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

build: remove versioningit build-req from sdist #5632

Merged

Conversation

bastimeyer
Copy link
Member

  • Replace tool.versioningit.onbuild hook with a custom implementation which replaces the entire streamlink._version module (similar to before) and which additionally removes versioningit from the build-system.requires field in pyproject.toml and which sets a static version string in setup.py
  • Rewrite streamlink._version module
  • Add and update comments
  • Update docs
  • Add tests

Follow-up of #5625

sdist and bdist build just fine...

$ python -m build --sdist --wheel
...

pyproject.toml and setup.py changes in sdist:

$ head -n8 pyproject.toml 
[build-system]
requires = [
  "setuptools >=64",
  "wheel",
  # 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, <3",  # disabled in sdist
]

$ bsdtar -xzOf dist/streamlink-6.2.1+41.g3494ec48.tar.gz streamlink-6.2.1+41.g3494ec48/pyproject.toml | head -n8
[build-system]
requires = [
  "setuptools >=64",
  "wheel",
  # 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, <3",
]

$ tail -n6 setup.py 
    setup(
        cmdclass=get_cmdclasses(),
        entry_points=entry_points,
        data_files=data_files,
        # version="",  # static version string template, uncommented and substituted by versioningit's onbuild hook
    )

$ bsdtar -xzOf dist/streamlink-6.2.1+41.g3494ec48.tar.gz streamlink-6.2.1+41.g3494ec48/setup.py | tail -n6
    setup(
        cmdclass=get_cmdclasses(),
        entry_points=entry_points,
        data_files=data_files,
        version="6.2.1+41.g3494ec48",
    )

streamlink._version module

$ tail -n1 src/streamlink/_version.py 
__version__ = _get_version()

$ bsdtar -xzOf dist/streamlink-6.2.1+41.g3494ec48tar.gz streamlink-6.2.1+41.g3494ec48/src/streamlink/_version.py
__version__ = "6.2.1+41.g3494ec48"

$ bsdtar -xzOf dist/streamlink-6.2.1+41.g3494ec48-py3-none-any.whl streamlink/_version.py
__version__ = "6.2.1+41.g3494ec48"

wheel metadata

$ bsdtar -xzOf dist/streamlink-6.2.1+41.g3494ec48-py3-none-any.whl streamlink-6.2.1+41.g3494ec48.dist-info/METADATA | grep -E '^Version: '
Version: 6.2.1+41.g3494ec48

Installing from the sdist ✔️

$ rm -rf /tmp/venv
$ python -m venv /tmp/venv
$ source /tmp/venv/bin/activate
$ pip install dist/streamlink-6.2.1+41.g3494ec48.tar.gz
...
$ streamlink -V
streamlink 6.2.1+41.g3494ec48
$ pip list | grep streamlink
streamlink         6.2.1+41.g3494ec48
$ python -c 'import importlib.metadata;print(importlib.metadata.version("streamlink"))'
6.2.1+41.g3494ec48

Installing from the wheel ✔️

$ rm -rf /tmp/venv
$ python -m venv /tmp/venv
$ source /tmp/venv/bin/activate
$ pip install dist/streamlink-6.2.1+41.g3494ec48-py3-none-any.whl
...
$ streamlink -V
streamlink 6.2.1+41.g3494ec48
$ pip list | grep streamlink
streamlink         6.2.1+41.g3494ec48
$ python -c 'import importlib.metadata;print(importlib.metadata.version("streamlink"))'
6.2.1+41.g3494ec48

Installing from git ✔️

$ rm -rf /tmp/venv
$ python -m venv /tmp/venv
$ source /tmp/venv/bin/activate
$ pip install git+file:///home/basti/repos/streamlink@build/remove-versioningit-from-sdist
...
$ streamlink -V
streamlink 6.2.1+41.g3494ec48
$ pip list | grep streamlink
streamlink         6.2.1+41.g3494ec48
$ python -c 'import importlib.metadata;print(importlib.metadata.version("streamlink"))'
6.2.1+41.g3494ec48

Installing in editable mode ✔️

$ rm -rf /tmp/venv
$ python -m venv /tmp/venv
$ source /tmp/venv/bin/activate
$ pip install -e . versioningit
...
$ streamlink -V
streamlink 6.2.1+41.g3494ec48
$ pip list | grep streamlink
streamlink         6.2.1+41.g3494ec48 /home/basti/repos/streamlink
$ python -c 'import importlib.metadata;print(importlib.metadata.version("streamlink"))'
6.2.1+41.g3494ec48

Building wheel from sdist ✔️

$ rm -rf /tmp/venv
$ python -m venv /tmp/venv
$ source /tmp/venv/bin/activate
$ bsdtar -xz -C /tmp/venv -f dist/streamlink-6.2.1+41.g3494ec48.tar.gz
...
$ cd /tmp/venv/streamlink-6.2.1+41.g3494ec48
$ python install build
...
$ python -m build --wheel
...
$ bsdtar -xzOf dist/streamlink-6.2.1+41.g3494ec48-py3-none-any.whl streamlink-6.2.1+41.g3494ec48.dist-info/METADATA | grep -E '^Version: '
Version: 6.2.1+41.g3494ec48
$ pip install dist/streamlink-6.2.1+41.g3494ec48-py3-none-any.whl 
...
$ streamlink -V
streamlink 6.2.1+41.g3494ec48
$ pip list | grep streamlink
streamlink         6.2.1+41.g3494ec48
$ python -c 'import importlib.metadata;print(importlib.metadata.version("streamlink"))'
6.2.1+41.g3494ec48

- Replace `tool.versioningit.onbuild` hook with a custom implementation
  which replaces the entire `streamlink._version` module (similar to
  before) and which additionally removes `versioningit` from the
  `build-system.requires` field in `pyproject.toml` and which sets
  a static version string in `setup.py`
- Rewrite `streamlink._version` module
- Add and update comments
- Update docs
- Add tests
@bastimeyer
Copy link
Member Author

And for good measure, I also tested building using the PKGBUILD from the Arch Linux repos...


My initial plan was to override the sdist and build_py setuptools cmdclasses, just like versioningit does, but this led to problems when building the wheel, as the version metadata gets read using the setuptools.finalize_distribution_options entry point, so this was a dead end.

The current solution should be good enough. I don't care that it modifies setup.py instead of only modifying pyproject.toml (added a comment about that), and I also don't care that it's a simple regex substitution instead of parsing and replacing the toml file, because otherwise, another build requirement (only when building from git though) would need to be added.

@bastimeyer bastimeyer merged commit 1376283 into streamlink:master Oct 22, 2023
23 checks passed
@bastimeyer bastimeyer deleted the build/remove-versioningit-from-sdist branch October 22, 2023 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant