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

Pyproject toml #324

Merged
merged 34 commits into from
Nov 22, 2024
Merged

Pyproject toml #324

merged 34 commits into from
Nov 22, 2024

Conversation

oerc0122
Copy link
Collaborator

@oerc0122 oerc0122 commented Oct 31, 2024

  • Migration to pyproject.toml with meson.
  • Migrated away from versioneer to custom version.py script.
  • Migrated CI workflows to use cibuildwheel
  • Move utilities related to build into <root>/build_utils.
  • Updated testing workflows to add appropriate compilers.

Addresses #323

@oerc0122 oerc0122 added the enhancement New feature or request label Oct 31, 2024
@oerc0122 oerc0122 requested a review from ajjackson October 31, 2024 12:06
@ajjackson
Copy link
Collaborator

This is looking really promising! It's nice having the compilation stuff in the meson config file and then a fairly clean toml for main project.

We may have to ditch versioneer; will be worth seeing what other meson projects are using?

@ajjackson
Copy link
Collaborator

ajjackson commented Oct 31, 2024

Have a look at this branch: https://github.com/pace-neutrons/Euphonic/tree/pyproject-toml-rebase

  • I rebased on master (only tweak needed really was to add toolz to pyproject.toml as it was in the desynced setup.py)
  • Hacked out versioneer for now. (Haven't even removed the files yet, just the references.)
  • Added a lot of boilerplate to meson.build so that it includes all they Python source files

The last part seems to be essential but looks pretty ugly. I think the preferred pattern is to cascade it into more meson.build files and load them with the subdir directive?

Anyway it seems to build and euphonic-dos runs so that's a good start.

I can force-push to your branch if that's helpful/allowed

@oerc0122 oerc0122 force-pushed the pyproject-toml branch 22 times, most recently from c7f69a1 to 934a38a Compare November 7, 2024 16:54
@oerc0122 oerc0122 force-pushed the pyproject-toml branch 3 times, most recently from 55d9d81 to 97efcbc Compare November 8, 2024 11:31
@oerc0122 oerc0122 force-pushed the pyproject-toml branch 12 times, most recently from 44d1712 to 12dc04d Compare November 22, 2024 16:01
@oerc0122 oerc0122 changed the title [WIP] Pyproject toml Pyproject toml Nov 22, 2024
build_utils/version.py Outdated Show resolved Hide resolved
@ajjackson
Copy link
Collaborator

ajjackson commented Nov 22, 2024

Some reflections on the overall process that got us here:

  • This was quite painful and took more time than expected

    • None of the problems can be blamed on pyproject.toml / PEP517 / PEP518; they do actually simplify things. The trouble is finding the correct configuration for the "simple" way of doing things...
  • We had hoped that by using (python-)meson the platform-dependent code would be pushed upstream and we wouldn't need to worry about it any more. In practice what happened is that platform-dependent fiddling was moved from the setup.py to the Github runners. That should be good news as it means we are less tied to particular build environments and e.g. a Mac user should now be able to build against non-Homebrew OpenMP if they can obtain it.

  • But this necessitated another round of work on the Github Actions. Troubleshooting Github Actions is a bit soul-destroying because it can take a lot of cursing and iteration to get to the correct "simple, obvious-looking" result.

  • There were some gotchas with the Github-provided Windows runners:

    • after activating the msvc environment, we got an inconsistent cl.exe and link.exe on the PATH, because a "Git" directory is given priority and ships with GNU link.exe
    • the solution is to use absolute paths, but then we discovered that different runners can have slightly different MSVC versions leading to flaky builds/tests. We have ended up with some compromise code that makes a few assumptions and tries to locate a reasonable MSVC installation before setting CC and CC_LD to absolute paths. It will need updating when the runners are significantly changed.
    • For a while we tried this third-party action which activates MSVC and sets some useful environment variables: https://dvdhrm.github.io/2021/04/21/meson-msvc-github-actions/ https://github.com/bus1/cabuild
      • But it's totally unofficial and has 1 star on Github. How is there not a "standard" tool for this? What are other C-compiling Windows projects doing instead?
  • I'm puzzled that we had to dig so much and invent so much process/machinery to handle the task of versioning sdist and wheel built with python-meson. It seems like something "everyone" needs to do, yet the information is scattered around a bit. As far as I can see, "everyone" has either a) something simpler/less-capable than this (i.e. no "dirty" versioning) or b) something even more complicated (that suits their complicated project.) Perhaps it's worth a blog post or something to help people (i.e. our future selves) navigate our solution and the surrounding issues; but I suspect neither of us wants to look at this again for a while.

  • It's a pity that Versioneer is currently coupled to setuptools, because it looks like their new "put these lines in your pyproject.toml" deployment is a nice improvement on the "vendoring" approach Euphonic was previously using.

  • Making PRs from forks is usually a pretty painless development workflow, but when applied to Github Actions it is awful. PRs would not trigger test runs; we had to post links to action runs on the other repository; discrepancies in the git tags gave misleading results.

In future if contributing CI tweaks from a fork I would make a PR to another branch on the fork for purposes of discussion and automatic CI.

@mducle
Copy link
Member

mducle commented Nov 22, 2024

Troubleshooting Github Actions is a bit soul-destroying

Yes, totally agree... I found that using tmate-actions was helpful but it's still quite a painful process...

@ajjackson
Copy link
Collaborator

Yeah, that wouldn't have helped with everything but might have been handy in a couple of places 🤔

Copy link
Collaborator

@ajjackson ajjackson left a comment

Choose a reason for hiding this comment

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

At this stage:

  • test CI (here) and package-building CI (on the fork) look as expected
  • test_release.yml hasn't been updated but that can be a separate PR. It will probably need further revision when the release is actually made...

I think it's a good time to merge to master and see what happens.

@ajjackson
Copy link
Collaborator

ajjackson commented Nov 22, 2024

Ah, one thing to look at: we currently document an option to

pip install --install-option="--python-only" euphonic

https://euphonic.readthedocs.io/en/stable/installation.html#installing-euphonic-without-the-c-extension

I don't think that syntax works any more? But that's arguably an unrelated Pip/deprecation issue: https://pip.pypa.io/en/stable/news/#v23-1

@oerc0122
Copy link
Collaborator Author

The command is now:

pip install -Csetup-args="-Dpython_only=true" euphonic

Not sure if that'll work from PyPI though

@ajjackson
Copy link
Collaborator

That doc update looks great! And the command behaves as expected on my laptop.

@ajjackson ajjackson merged commit c829321 into pace-neutrons:master Nov 22, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants