-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
When building Streamlink's sdist, it removes versioningit from its build-system.requires, so that versioningit is only required when building from git, as intended:
Lines 4 to 6 in befff8e
| # The versioningit build-requirement gets removed from the source distribution, | |
| # as the version string is already built into it (see the onbuild versioningit hook): | |
| "versioningit >=2.0.0,<4", # disabled in sdist |
This is currently done by using a regex in a custom versioningit build step that's run when building the sdist from git:
Lines 185 to 187 in befff8e
| [tool.versioningit.onbuild] | |
| # When building the sdist or wheel, remove versioningit build-requirement and set the static version string | |
| method = { module = "build_backend.onbuild", value = "onbuild" } |
streamlink/build_backend/onbuild.py
Lines 58 to 84 in befff8e
| # Remove versioningit from ``build-system.requires`` in ``pyproject.toml`` | |
| if is_source: | |
| with update_file(base_dir / "pyproject.toml") as cmproxy: | |
| cmproxy.set( | |
| re.sub( | |
| r"^(\s*)(\"versioningit\b.+?\",).*$", | |
| "\\1# \\2", | |
| cmproxy.get(), | |
| flags=re.MULTILINE, | |
| count=1, | |
| ), | |
| ) | |
| # Set the static version string that gets passed directly to setuptools via ``setup.py``. | |
| # This is much easier compared to adding the ``project.version`` field and removing "version" from ``project.dynamic`` | |
| # in ``pyproject.toml``. | |
| if is_source: | |
| with update_file(base_dir / "setup.py") as cmproxy: | |
| cmproxy.set( | |
| re.sub( | |
| r"^(\s*)# (version=\"\",).*$", | |
| f'\\1version="{version}",', | |
| cmproxy.get(), | |
| flags=re.MULTILINE, | |
| count=1, | |
| ), | |
| ) |
It was done this way, because it's the simplest way without having to parse the pyproject.toml file. On older Python versions, this would've required the additional tomli dependency. With the drop of Python 3.10 next year though, tomllib will be available in the stdlib, so let's replace this "hacky" regex-based substitution then.
Then the version attribute also doesn't have to be set in setup.py and it can simply be set in pyproject.toml as a static value after removing the version item from project.dynamic. This is much cleaner.
Line 93 in befff8e
| # version="", # static version string template, uncommented and substituted by versioningit's onbuild hook |
Line 49 in befff8e
| "version", |