0

I recently messed up the built PyPI package of PyPDF2 (the packages missed one package). The result was that CI looked fine, but every user who used PyPI to install PyPDF2==2.3.0 got an error when importing PyPDF2 (this one).

The package was in the Github repository, but not in the built distribution.

I want to check my distribution files in CI.

I already build the package, but I don't know how to install it from that artifact. Also, how do I make sure that pytest uses the installed artifact and not the local PyPDF2 folder when I execute the tests?

How I build the package in Github Actions

  package:
    name: Build & verify package
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v3
        with:
          python-version: ${{env.PYTHON_LATEST}}

      - run: python -m pip install build twine check-wheel-contents
      - run: python -m build --sdist --wheel .
      - run: ls -l dist
      - run: check-wheel-contents dist/*.whl
      - name: Check long_description
        run: python -m twine check dist/*

The current steps

In case you want to see the full picture: https://github.com/py-pdf/PyPDF2/blob/main/.github/workflows/github-ci.yaml

enter image description here

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958

1 Answers1

0

The easiest way to handle this would be to add a step to your CI that installs the package, and then runs some minimal code example outside your package directory to verify that it works.

Something like below for your particular repo:

      - name: Test installing package
        run: python -m pip install .

      - name: Test running installed package
        working-directory: /tmp
        run: python -c "import PyPDF2;print(PyPDF2.__version__)"

This would just test the root module import chain works, which may be sufficient in your case, but alternatively, it may be worth making an integration test file that you run from /tmp directory that would further test the code, but this depends on what you'd consider the import coverage of the above line.

MasterOdin
  • 7,117
  • 1
  • 20
  • 35