Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and test sdist builds; reduce sdist size #337

Merged
merged 22 commits into from
Dec 11, 2024
Merged

Conversation

ajjackson
Copy link
Collaborator

Currently the release-building action tests the binary wheels (as part of cibuildwheel workflow) but not the source distribution.

The source-build release test is failing on (only?) windows so perhaps something is not quite right. Here is a workflow to look into that.

@ajjackson ajjackson force-pushed the test_windows_sdist branch 2 times, most recently from b58cd5e to eca6808 Compare December 9, 2024 10:27
@ajjackson
Copy link
Collaborator Author

Ok, d3e40c5 reproduces the build error! Now we have a bit more freedom to try and fix it.

Copy link
Contributor

github-actions bot commented Dec 9, 2024

Test Results

    29 files  +    29      29 suites  +29   1h 47m 51s ⏱️ + 1h 47m 51s
 1 066 tests + 1 066   1 060 ✅ + 1 060   6 💤 + 6  0 ❌ ±0 
13 780 runs  +13 780  13 698 ✅ +13 698  82 💤 +82  0 ❌ ±0 

Results for commit b353ef8. ± Comparison against base commit 3feac5c.

♻️ This comment has been updated with latest results.

This happens when we try to use a non-existent git command. It happens
more often on Windows as we try to use more Git commands there.
@ajjackson
Copy link
Collaborator Author

@oerc0122 Looks like the problem is a bug in version.py; it will error out if any of the proposed git names is unavailable. (i.e. on Mac/Linux if git is unavailable, on Windows if any of git, git.cmd or git.exe is unavailable.)

Currently the sdist is not tested in the package-building workflow. Properly testing this sort of thing is tricky:

  • we can't really use a Github action that doesn't have git installed, and hiding it from the PATH would be quite fiddly. We get some coverage by testing on Windows where the multiple versions come into play, but the "no git" case seems impractical. Perhaps using a container?
  • the tests should not be in the sdist, so testing from a bare sdist install needs to also have a copy of the repo available and make sure it isn't exposed during testing. The best way to do that is probably with another tox setup 😭

The new action in this PR was mostly intended for troubleshooting and doesn't actually run tests. Maybe it should be migrated to a manual-dispatch workflow that targets a particular git commit and checks if the Ubuntu sdist -> Windows tests loop works, to be used when tweaking the build process.

Would it be very irresponsible to just roll out the version.py fix from this branch into a new release, without creating a bunch of new CI?

@oerc0122
Copy link
Collaborator

oerc0122 commented Dec 9, 2024

@oerc0122 Looks like the problem is a bug in version.py; it will error out if any of the proposed git names is unavailable. (i.e. on Mac/Linux if git is unavailable, on Windows if any of git, git.cmd or git.exe is unavailable.)

Currently the sdist is not tested in the package-building workflow. Properly testing this sort of thing is tricky:

  • we can't really use a Github action that doesn't have git installed, and hiding it from the PATH would be quite fiddly. We get some coverage by testing on Windows where the multiple versions come into play, but the "no git" case seems impractical. Perhaps using a container?
  • the tests should not be in the sdist, so testing from a bare sdist install needs to also have a copy of the repo available and make sure it isn't exposed during testing. The best way to do that is probably with another tox setup 😭

The new action in this PR was mostly intended for troubleshooting and doesn't actually run tests. Maybe it should be migrated to a manual-dispatch workflow that targets a particular git commit and checks if the Ubuntu sdist -> Windows tests loop works, to be used when tweaking the build process.

Would it be very irresponsible to just roll out the version.py fix from this branch into a new release, without creating a bunch of new CI?

Well, now I feel like an idiot. I think I originally had a FileNotFound except and presumed subprocess would never raise it and removed it.

I think that excluding the files from the sdist is easy enough and I think you're allowed to pass a directory to checkout, so we can probably do a bare checkout in the CI and call the run_tests.py to use the installed sdist version.

In terms of irresponsibility? It needs fixing. We just did a major build-system overhaul, we knew from the start things like this were liable to happen and would need attention. We did the best we could. I thought, though, that cibuildwheel would test the sdist for us, so I'm surprised we didn't catch this in that.

@ajjackson
Copy link
Collaborator Author

cibuildwheel isn't being used to build the sdist!


      - name: Build wheels
        uses: pypa/[email protected]
        env:
          CIBW_BUILD_FRONTEND: build
          CIBW_BUILD: ${{ matrix.version-tag }}-*
          CIBW_ARCHS: ${{ matrix.cibw_archs }}
          CIBW_SKIP: "*-musllinux*"

          CIBW_REPAIR_WHEEL_COMMAND_MACOS: ""

          CIBW_TEST_EXTRAS: "test,brille,phonopy_reader,matplotlib"
          CIBW_TEST_COMMAND: python {package}/tests_and_analysis/test/run_tests.py

        with:
          output-dir: wheelhouse

      - name: Create source distribution
        if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
        shell: bash -l {0}
        run: |
          python -m build --sdist .

There's an interesting discussion here where people suggest building an sdist and then using that as the source for cibuildwheel:

pypa/cibuildwheel#173

@ajjackson
Copy link
Collaborator Author

The cibuildwheel docs suggest making the sdist in a separate step to the wheels, and having upload depend on both. That doesn't seem a bad idea, and would let some sdist tests run at the same time as other builds are being put together.

https://cibuildwheel.pypa.io/en/stable/deliver-to-pypi/#github-actions

This reworks the overall flow a bit: sdist is created first, then all
wheels are produced from the same sdist. sdist is tested
separately (hopefully while the wheels are being built and tested).
Then finally if release everything is gathered and uploaded.
Tweaking the run conditions temporarily while troubleshooting this;
these should be reverted.
- Don't get tags when building from sdist, everything should be there
  already

- Try glob-matching the sdist location now we have the right path

- ls fewer files
@ajjackson
Copy link
Collaborator Author

Here is the CI run that nearly pushes to PyPI (so lets us see what files it would have used...) https://github.com/pace-neutrons/Euphonic/actions/runs/12253702919/job/34183074026?pr=337

I've now restored the usual triggers.

@ajjackson ajjackson changed the title Build sdist on ubuntu and test on windows Fix Windows sdist builds; test this in PyPI release action Dec 10, 2024
@ajjackson ajjackson marked this pull request as ready for review December 10, 2024 11:59
@ajjackson ajjackson requested a review from oerc0122 December 10, 2024 11:59
@ajjackson
Copy link
Collaborator Author

Not sure how this was created. I don't think I did...

Screenshot 2024-12-10 at 12 04 41

@oerc0122
Copy link
Collaborator

oerc0122 commented Dec 10, 2024

Mine now says:

ajjackson temporarily deployed to pypi 2 hours ago — with GitHub Actions

@ajjackson
Copy link
Collaborator Author

I don't see a weird release or files on PyPI, anyway 🤷‍♂️

Copy link
Collaborator

@oerc0122 oerc0122 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to update the sdist excludes here?

@ajjackson ajjackson added this to the v1.4.1 milestone Dec 10, 2024
@ajjackson
Copy link
Collaborator Author

It looks like #338 will make some further changes to the workflow, as cibuildwheel doesn't do well at testing its builds from sdist (as opposed to git checkout).

We could merge that into this branch first, or merge this branch first and retarget #338 . Any preference?

@oerc0122
Copy link
Collaborator

It looks like #338 will make some further changes to the workflow, as cibuildwheel doesn't do well at testing its builds from sdist (as opposed to git checkout).

We could merge that into this branch first, or merge this branch first and retarget #338 . Any preference?

It'll automagically retarget so it doesn't make too much difference, but I would probably say merge #338 as this is really one job to master.

## Update .gitattributes: exclude tests and workflows from archive

meson-python uses git-archive to create the sdist. Some of euphonic's
test files are on the large side and we don't need to include them
with every copy of the source.

This does have the downside that git-archive can no longer be used
to produce a copy of the source with tests, but we weren't using that
anyway.


## Build wheels from git checkout

While the purity of building from sdist was appealing, it is difficult
for cibuildwheel to cleanly run an external test suite as it
containerizes the Linux build (to deal with ManyLinux requirements).

We are still testing the sdist (on Windows) so just have to trust in
cibuildwheel's own efforts to separate the testing and source from the
installation. (Which it does seem to work quite hard at.)
@ajjackson ajjackson changed the title Fix Windows sdist builds; test this in PyPI release action Fix and test sdist builds; reduce sdist size Dec 10, 2024
@ajjackson
Copy link
Collaborator Author

ajjackson commented Dec 10, 2024

Ok, I think remaining tasks here are:

  • strip out the docs as well
  • update changelog again
  • One last run of the workflow 🤞
  • Final sanity check from @oerc0122

@ajjackson ajjackson requested a review from oerc0122 December 11, 2024 11:24
@ajjackson
Copy link
Collaborator Author

Pipeline looks good, if you're happy we can merge this and I'll have a crack at a release-number-updating manual action. (They need bumping anyway, may as well have a go at setting it up.)

Copy link
Collaborator

@oerc0122 oerc0122 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks sane to me, let's hope it works.

@ajjackson ajjackson merged commit 862c560 into master Dec 11, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants