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

Addopt setuptools-scm without vendoring setuptools-scm #4537

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions (meta)/stable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v72.2.0
19 changes: 14 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ jobs:
timeout-minutes: 75
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
id: python-install
uses: actions/setup-python@v5
Expand All @@ -91,20 +93,21 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
working-directory: setuptools/tests/config
run: python -m downloads.preload setupcfg_examples.txt
- name: Workaround for unreleased PyNaCl (pyca/pynacl#805)
if: contains(matrix.python, 'pypy')
run: echo "SETUPTOOLS_ENFORCE_DEPRECATION=0" >> $GITHUB_ENV
- name: Install tox
run: python -m pip install tox
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved this part around such that tox would be installed before pre-building distributions1.

Footnotes

  1. The pre-built distributions were previously introduced to be used with virtualenv fixtures, it is also used by downstream packagers.

- name: Pre-build distributions for test
shell: bash
run: |
tox -e version
rm -rf dist
# workaround for pypa/setuptools#4333
pipx run --pip-args 'pyproject-hooks!=1.1' build
echo "PRE_BUILT_SETUPTOOLS_SDIST=$(ls dist/*.tar.gz)" >> $GITHUB_ENV
echo "PRE_BUILT_SETUPTOOLS_WHEEL=$(ls dist/*.whl)" >> $GITHUB_ENV
rm -rf setuptools.egg-info # Avoid interfering with the other tests
- name: Workaround for unreleased PyNaCl (pyca/pynacl#805)
if: contains(matrix.python, 'pypy')
run: echo "SETUPTOOLS_ENFORCE_DEPRECATION=0" >> $GITHUB_ENV
- name: Install tox
run: python -m pip install tox
- name: Run
run: tox
- name: Create coverage report
Expand Down Expand Up @@ -172,6 +175,8 @@ jobs:
timeout-minutes: 75
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setuptools-scm fails without the history/tags in the repository.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder why this isn't a problem for other projects I use that employ setuptools_scm. It's a little frustrating that this concern needs to be addressed in multiple different places. Probably it should instead reference a common setting that documents its purpose. No need to deal with that yet, until we decide to go forward with this approach.

Copy link
Contributor Author

@abravalheri abravalheri Aug 13, 2024

Choose a reason for hiding this comment

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

Probably because setuptools history is long? I am not sure... But I did find this issue in other projects using setuptools-scm before and also in other CIs (like CirrusCI and the old Travis) that similarly perform a shallow clone by default.

- name: Install Cygwin with Python
uses: cygwin/cygwin-install-action@v4
with:
Expand Down Expand Up @@ -227,6 +232,8 @@ jobs:
timeout-minutes: 75
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install OS-level dependencies
run: |
sudo apt-get update
Expand All @@ -252,6 +259,8 @@ jobs:
timeout-minutes: 75
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file lists exclude patterns unique to the repository.
# Do not add common patterns here, see https://blog.jaraco.com/skeleton/#ignoring-artifacts
# for a global approach or use .git/info/exclude.
(meta)/latest.txt
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ include pytest.ini
include tox.ini
include setuptools/tests/config/setupcfg_examples.txt
include setuptools/config/*.schema.json
graft (meta)
global-exclude *.py[cod] __pycache__
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ backend-path = ["."]

[project]
name = "setuptools"
version = "72.2.0"
authors = [
{ name = "Python Packaging Authority", email = "distutils-sig@python.org" },
]
Expand All @@ -26,6 +25,7 @@ keywords = ["CPAN PyPI distutils eggs package management"]
requires-python = ">=3.8"
dependencies = [
]
dynamic = ["version"]

[project.urls]
Source = "https://github.com/pypa/setuptools"
Expand Down Expand Up @@ -194,3 +194,4 @@ namespaces = true
formats = "zip"

[tool.setuptools_scm]
version_file = "(meta)/latest.txt"
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
package_data.setdefault('setuptools.command', []).extend(['*.xml'])


def get_version() -> str:
candidates = ["(meta)/latest.txt", "(meta)/stable.txt"]
version_file = next(f for f in candidates if os.path.exists(f))
with open(version_file, encoding="utf-8") as fp:
return fp.read()


def pypi_link(pkg_filename):
"""
Given the filename, including md5 fragment, construct the
Expand Down Expand Up @@ -83,6 +90,7 @@ def _restore_install_lib(self):


setup_params = dict(
version=get_version(),
cmdclass={'install': install_with_pth},
package_data=package_data,
)
Expand Down
63 changes: 12 additions & 51 deletions tools/finalize.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,23 @@
"""
Finalize the repo for a release. Invokes towncrier and bumpversion.
Finalize the repo for a release. Invokes towncrier.
Copy link
Member

Choose a reason for hiding this comment

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

I was really hoping to see this file gone, as it mostly duplicates jaraco.develop.finalize().

Copy link
Contributor Author

@abravalheri abravalheri Aug 13, 2024

Choose a reason for hiding this comment

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

I have removed most of the duplication based on the approach discussed in #4537 (comment).

We could add support for a hook in jaraco.develop.finalize, as suggested in #4537 (comment), for example:

# Potential change in jaraco.develop.finalize

Hook: TypeAlias = Callable[[str], Iterable[str]]

def finalize(modify_files: Hook = lambda _: []):
    ...
    if modified := modify_files(version):
        subprocess.run(["git", "add", *modified], ...)
    ...

Or something like a --save-version=FILE CLI option...

"""

__requires__ = ['bump2version', 'towncrier', 'jaraco.develop>=7.21']
__requires__ = ['towncrier', 'jaraco.develop>=7.23']


import pathlib
import re
import subprocess
import sys
from pathlib import Path

from jaraco.develop import towncrier

bump_version_command = [
sys.executable,
'-m',
'bumpversion',
towncrier.release_kind(),
]


def get_version():
cmd = bump_version_command + ['--dry-run', '--verbose']
out = subprocess.check_output(cmd, text=True, encoding='utf-8')
return re.search('^new_version=(.*)', out, re.MULTILINE).group(1)


def update_changelog():
towncrier.run('build', '--yes')
_repair_changelog()


def _repair_changelog():
"""
Workaround for #2666
"""
changelog_fn = pathlib.Path('NEWS.rst')
changelog = changelog_fn.read_text(encoding='utf-8')
fixed = re.sub(r'^(v[0-9.]+)v[0-9.]+$', r'\1', changelog, flags=re.M)
changelog_fn.write_text(fixed, encoding='utf-8')
subprocess.check_output(['git', 'add', changelog_fn])


def bump_version():
cmd = bump_version_command + ['--allow-dirty']
subprocess.check_call(cmd)
from jaraco.develop.finalize import finalize


def ensure_config():
"""
Double-check that Git has an e-mail configured.
"""
subprocess.check_output(['git', 'config', 'user.email'])
def main():
version = towncrier.semver(towncrier.get_version())
version = version.lstrip("v") # Compatibility with setuptools-scm
Path("(meta)/latest.txt").unlink() # Remove "unstable"/development version
Path("(meta)/stable.txt").write_text(version, encoding="utf-8")
subprocess.check_output(['git', 'add', "(meta)/stable.txt"])
finalize()


if __name__ == '__main__':
print("Cutting release at", get_version())
ensure_config()
towncrier.check_changes()
update_changelog()
bump_version()
__name__ == '__main__' and main()
15 changes: 12 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ setenv =
PYTHONWARNDEFAULTENCODING = 1
SETUPTOOLS_ENFORCE_DEPRECATION = {env:SETUPTOOLS_ENFORCE_DEPRECATION:1}
commands =
tox -qe version # Use a separated testenv to avoid entrypoints tampering with tests
pytest {posargs}
usedevelop = True
extras =
Expand Down Expand Up @@ -53,6 +54,7 @@ changedir = docs
deps =
importlib_resources < 6 # twisted/towncrier#528 (waiting for release)
commands =
tox -qe version
python -m sphinx -W --keep-going . {toxinidir}/build/html
python -m sphinxlint \
# workaround for sphinx-contrib/sphinx-lint#83
Expand All @@ -63,12 +65,10 @@ description = assemble changelog and tag a release
skip_install = True
deps =
towncrier
bump2version
jaraco.develop >= 7.23
importlib_resources < 6 # twisted/towncrier#528 (waiting for release)
pass_env = *
commands =
python tools/finalize.py
python -m tools.finalize

[testenv:vendor]
skip_install = True
Expand All @@ -81,6 +81,15 @@ deps =
commands =
vendor: python -m tools.vendored

[testenv:version]
skip_install = True
deps =
setuptools_scm>=8.1
pass_env =
SETUPTOOLS_SCM*
commands =
python -m setuptools_scm --force-write-version-files

[testenv:generate-validation-code]
skip_install = True
deps =
Expand Down
Loading