-
Notifications
You must be signed in to change notification settings - Fork 69
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
Support dynamic version generation, including from git tags and with git commit hashes #159
Comments
Thanks @lithomas1. xref pandas-dev/pandas#47081 (comment) for more context. There are multiple things folks want to do with version names in wheel files, see e.g. One issue with I am +1 on adding the feature, because this is something a lot of folks want - and want it enough to go through a lot of effort to get it. |
I don't think that it's a problem for cross compiling. setuptools has long supported (via setup.cfg but not setup.py, IIRC) reading versions from an attribute of a source file, commonly The tl;dr is that it takes Setuptools actually does fall back to directly importing the file if literal_eval fails. That's not precisely required, and obviously also has cross-compile concerns. |
Thanks @eli-schwartz, interesting, I didn't know >>> spec = _find_spec('scipy', None)
>>> spec
ModuleSpec(name='scipy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x10622d5b0>, origin='/Users/rgommers/code/scipy/build-install/lib/python3.9/site-packages/scipy/__init__.py', submodule_search_locations=['/Users/rgommers/code/scipy/build-install/lib/python3.9/site-packages/scipy'])
>>> StaticModule('scipy', spec)
<__main__.StaticModule object at 0x1077a1fa0>
>>> StaticModule('scipy', spec).__version__
Traceback (most recent call last):
Cell In [3], line 25 in __getattr__
return next(
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
Cell In [20], line 1
StaticModule('scipy', spec).__version__
Cell In [3], line 31 in __getattr__
raise AttributeError(f"{self.name} has no attribute {attr}") from e
AttributeError: scipy has no attribute __version__
>>> import scipy
>>> scipy.__version__
'1.10.0.dev0+1964.ac815d4'
>>> type(scipy.__version__)
<class 'str'>
>>> spec = _find_spec('scipy.version', None)
>>> StaticModule('scipy-version', spec)
<__main__.StaticModule object at 0x105a0c4f0>
>>> StaticModule('scipy-version', spec).full_version
'1.10.0.dev0+1964.ac815d4' Given that The [tool.meson-python]
version = 'scipy.version.version' |
Yup, that's how the logic is specified -- it sees if it can literal_eval the attribute "without code execution", and literal_eval means it has to be a simple assignment of a primitive type, no functions or imports or operators or any form of logic building. Which is all that's needed here.
Yup, that's what setuptools does too. Since this is private logic to the internal source code / builder routines (pyproject.toml's tool sections) it's perfectly reasonable to poke at undocumented private attributes, and name them whatever you like into the bargain. Is it necessary to look at the generated file, or is the plan to just look for the updated version after constructing the primary wheel contents, but before generating the dist-info, and reading it from the staged wheel layout? |
Annoying complication: we do want the sdist and wheel filenames to match, and we cannot ship generated sources in the sdist nor can we run I don't see a good solution to that to make the |
You can, Meson allows you to do this via a Usually this is not also an installable file created by a build rule -- it's just a flag file that allows a version generator script to deduce the version as a fallback if it's not running in a git repo. That being said, it's not precisely forbidden to use if fs.exists('version.py')
py.install_sources('version.py', subdir: 'scipy')
else
version_py_gen = find_program('version-py-gen.py')
custom_target(..., output: 'version.py',
command: [version_py_gen, ...],
install: true, install_dir: py.get_install_dir() / 'scipy')
meson.add_dist_script(version_py_gen, ...)
endif It's also a use case I'd like to find a better solution for in the long run, because there are valid cases to ship generated sources in a release tarball. This is one of them. manpages and other forms of documentation are another. |
Going this route is possible, but seems a little bit hard. AFAICT the goal here is to only change the package version in one place, @lithomas1 have you considered rewriting |
How does that help in getting the version into the sdist/wheel name? That is the one missing piece here; Pandas, SciPy et al. already have ways of generating |
That's not the only possible goal, and not the most important one. With |
Afaict the real goal when you get right down to it is that The sticking point is that It is simply the most familiar thing, to people, to have That's how several different tools already work, including versioneer. |
Thanks all for the replies. To be honest, I don't really feel strongly about meson-python having to get the version from Ideally, version info would come from meson itself. One way to do this would probably be through the introspection files(intro-install_plan.json). We can probably mark the version file with a specific install tag, and then configure meson-python to look for a given variable in the marked file. Also, slightly unrelated, but some general pain points in general:
|
You can have it in
We currently support using the version declared in the Meson project. See https://meson-python.readthedocs.io/en/latest/usage/start.html#specifying-the-project-metadata Example:
I think I am missing something here, because I fail to see what that has to do with loading the version from I do agree that generating the version from VCS is a relevant use-case though.
Is there any escape hatch for that? Like specifying the version in an env var or Meson option for example. If not, it could be added, and we can make sure meson-python sets that when invoking Meson. |
My suggestion up above was that meson.add_dist_script() can be used to run
And how does meson-python know what the version is? If it did know, then Meson doesn't support env vars, but However, this environment variable is typically set by a build script such as a |
You can see what version strings are used in nightlies here: https://anaconda.org/scipy-wheels-nightly. For example:
The reasoning here is:
|
Here is a more complete list of packages that support dynamic version generation:
There are even more random ones floating around, plus some projects (like SciPy) have their homegrown code for it. That shows that building this into @FFY00 also pointed me to this way of exporting metadata with Perhaps one of the above packages can be an optional dependency to make it simpler for end users. However, the main priorities here are:
|
Is there a cookbook or recommended best practice for this now? I'm porting a project to meson + meson-python, and currently I have |
You don't need to define the version in [project]
name = 'foo'
dynamic = ['version'] |
🤦 Ah, of course. That's what I get for "copy-paste-edit" development! |
meson-python should provide a way to use the
__version__
attribute of a package as its version instead of using the version from meson.EDIT: for an extended description of this feature request, see https://github.com/FFY00/meson-python/issues/159#issuecomment-1266576327
The text was updated successfully, but these errors were encountered: