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

Replace versioneer with setuptools-scm, migrate to pyproject.toml. #186

Merged
merged 3 commits into from
May 26, 2023

Conversation

HexDecimal
Copy link
Collaborator

#139 mentioned issues with Versioneer, so this PR completely removes it. pyproject.toml allows including versioning tools into the build system so having a bundled addon is no longer necessary.

Now _version.py is generated during setup, but I've tweaked the script so that the package can still run without it.

A lot of setup.py metadata has been moved into pyproject.toml as well. With a little more effort I think the entire thing can be moved to pyproject.toml but I stuck with the more important bits for now.

With this change you no longer use setup.py to build or develop. You use pip install -e . to install in development mode and python -m build to make distributions. I've automated this stuff some time ago and have now edited the release guide to reflect that.

If this PR does too much then I can split it up.

@codecov
Copy link

codecov bot commented May 22, 2023

Codecov Report

Merging #186 (8d6325a) into master (d17fc69) will decrease coverage by 0.26%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##           master     #186      +/-   ##
==========================================
- Coverage   95.00%   94.74%   -0.26%     
==========================================
  Files          14       14              
  Lines        1100     1103       +3     
==========================================
  Hits         1045     1045              
- Misses         55       58       +3     
Impacted Files Coverage Δ
delocate/__init__.py 66.66% <50.00%> (-33.34%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Versioneer has been completely removed.
Now `_version.py` is generated during setup, but I've tweaked the script
so that the package can run even without it.

Setup metadata has been moved into pyproject.toml as well.
Copy link
Owner

@matthew-brett matthew-brett left a comment

Choose a reason for hiding this comment

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

Thanks for doing this - it looks like a good cleanup.

@@ -9,17 +9,17 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
# checkout@v1 is required since versioneer uses git describe.
# checkout@v1 is used to that tags are more relaible.
Copy link
Owner

@matthew-brett matthew-brett May 23, 2023

Choose a reason for hiding this comment

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

Suggested change
# checkout@v1 is used to that tags are more relaible.
# checkout@v1 is used so that tags are more reliable. See:
# https:/actions/checkout/issues/290

Reference for this statement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The checkout action has a history of messing up references to annotated tags which could affect scripts deriving versions from those tags but if the build system is just using any tag then it will probably work fine. actions/checkout#290

I think I can update the version here without issues, but you don't really know until you push a commit and it breaks.

Copy link
Owner

Choose a reason for hiding this comment

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

OK - I added the URL to the suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know. Seeing as the issue only affects annotated tags made me think this was a non-issue after all. If something happens then I'm familiar with some workarounds that might be better than keeping an older version of the action.

from .delocating import delocate_path, delocate_wheel, patch_wheel
from .libsana import tree_libs, wheel_libs

__version__ = _version.get_versions()["version"]
del _version
try:
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry for my ignorance here, but under what circumstances would this be triggered?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not under normal circumstances, but if the module was imported directly from the repo without being installed in development mode then _version.py would be missing. Versioneer seemed to have a fallback for the case when a version was asked for with the package being setup and this was me accounting for that with the new setup.

It should also be possible to cover this with a test which installs the dependencies but not the package itself. I'd also be okay with removing this try/except clause and just telling everyone to be sure to use pip install -e .

Copy link
Owner

Choose a reason for hiding this comment

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

How about raising a warning in the block, possibly a deprecation warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A RuntimeWarning might be appropriate, but also simply crashing when _version.py is missing is also an option. I'll go with whatever you want.

I think running the module without doing a development install is unrealistic and is going to crash on one of the imports of dependencies before it reaches this part.

I've had one of my own projects which required a trick like this but it was exceptional: It needed to import the package for doc generation but the package was too heavy to install on the doc generating servers.

Copy link
Owner

Choose a reason for hiding this comment

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

My preference would be to allow it for now, with a deprecation warning that we will break in the future - just because somebody may be using that mis-feature at the moment.

Copy link
Owner

@matthew-brett matthew-brett left a comment

Choose a reason for hiding this comment

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

Consider deprecation and planned error after deprecation? Your call. PEP complaint, otherwise all good.

from .delocating import delocate_path, delocate_wheel, patch_wheel
from .libsana import tree_libs, wheel_libs

try:
from ._version import __version__
except ImportError:
__version__ = "0.0.0"
warnings.warn(
Copy link
Owner

Choose a reason for hiding this comment

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

But - what do you think about planning to raise an error after a period of deprecation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a really niche usage of the package and the warning should make it clear what the correct usage is. This is just an elaborate alternative to crashing on ImportError because the package wasn't installed properly.

DeprecationWarning is too easy to miss, so it has to be one of the alternatives such as RuntimeWarning or FutureWarning.

Or the warning can be skipped and it just crashes when it isn't installed. This only affects developers of the package itself who should be installing it in development mode and will likely know what a missing _version module means.

Or silently fallback to __version__ = "0.0.0" since the version doesn't matter as much for development.

Copy link
Owner

Choose a reason for hiding this comment

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

Your party, your rules! Just go for whatever you prefer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently with as it is now this is the most explicit and most forgiving option: A clear warning saying "don't do this" while still allowing it.

I guess what's actually missing here is a CONTRIBUTING.md file saying to use pip install -e . to set this up for development.

delocate/__init__.py Outdated Show resolved Hide resolved
Copy link
Owner

@matthew-brett matthew-brett left a comment

Choose a reason for hiding this comment

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

Feel free to merge when you're happy ...

@HexDecimal HexDecimal merged commit 1c038e8 into matthew-brett:master May 26, 2023
@HexDecimal HexDecimal deleted the setuptools-meta branch May 26, 2023 09:55
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