From 1b43166951caac29ed223c9d1522534626b3598e Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Mar 2024 17:09:03 -0400 Subject: [PATCH 1/3] Group setup.py imports While setuptools has official status, it is not actually part of the standard library (and since Python 3.12 cannot be treated as if it is, since it is not installed by default), so its imports belong in the second group rather than the first, per PEP-8. --- setup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 73d1ae952..e827d2483 100755 --- a/setup.py +++ b/setup.py @@ -1,11 +1,13 @@ #!/usr/bin/env python +import os +import sys from typing import Sequence + from setuptools import setup, find_packages from setuptools.command.build_py import build_py as _build_py from setuptools.command.sdist import sdist as _sdist -import os -import sys + with open(os.path.join(os.path.dirname(__file__), "VERSION"), encoding="utf-8") as ver_file: VERSION = ver_file.readline().strip() From 26dccd70713b2be6cb0af6892fd05703f17cda3e Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Mar 2024 17:49:56 -0400 Subject: [PATCH 2/3] Streamline setup.py file reading This is partly a refactoring, reducing logic duplication and slightly decreasing overall length of the code that reads values from files. However, it does make two small behavioral changes: - In addition to the VERSION file for which this was already the case, requirements files and the readme are also taken relative to the directory that contains the setup.py file, rather than relative to the current directory if different. Supporting reading the readme and dependencies realtive to a different directory doesn't seem intended, and could lead to confusion in some cases. - The VERSION file is now read entirely and whitespace stripped, rather than reading just the first line. The VERSION file should always contain exactly one line, and this logic is simpler. This changes code for the reading of metadata only. It does not make any changes to the version stamping code. --- setup.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index e827d2483..3f57e3327 100755 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ import os import sys +from pathlib import Path from typing import Sequence from setuptools import setup, find_packages @@ -9,17 +10,14 @@ from setuptools.command.sdist import sdist as _sdist -with open(os.path.join(os.path.dirname(__file__), "VERSION"), encoding="utf-8") as ver_file: - VERSION = ver_file.readline().strip() +def _read_content(path: str) -> str: + return (Path(__file__).parent / path).read_text(encoding="utf-8") -with open("requirements.txt", encoding="utf-8") as reqs_file: - requirements = reqs_file.read().splitlines() -with open("test-requirements.txt", encoding="utf-8") as reqs_file: - test_requirements = reqs_file.read().splitlines() - -with open("README.md", encoding="utf-8") as rm_file: - long_description = rm_file.read() +version = _read_content("VERSION").strip() +requirements = _read_content("requirements.txt").splitlines() +test_requirements = _read_content("test-requirements.txt").splitlines() +long_description = _read_content("README.md") class build_py(_build_py): @@ -50,7 +48,7 @@ def _stamp_version(filename: str) -> None: with open(filename) as f: for line in f: if "__version__ =" in line: - line = line.replace('"git"', "'%s'" % VERSION) + line = line.replace('"git"', "'%s'" % version) found = True out.append(line) except OSError: @@ -66,7 +64,7 @@ def _stamp_version(filename: str) -> None: setup( name="GitPython", cmdclass={"build_py": build_py, "sdist": sdist}, - version=VERSION, + version=version, description="GitPython is a Python library used to interact with Git repositories", author="Sebastian Thiel, Michael Trier", author_email="byronimo@gmail.com, mtrier@gmail.com", From 74df5a8995b6f4e9ed053e126dda1cb6cfc465f5 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Mar 2024 18:29:50 -0400 Subject: [PATCH 3/3] Add a "doc" extra for documentation build dependencies And use it in: - GitHub Actions CI checks - Read the Docs configuration - tox (for the "html" environment) (The tox "html" environment was not previously overriding "extras" to empty it out of dependencies needed only for linting or testing, so this happens to make `tox -e html` faster.) --- .github/workflows/pythonpackage.yml | 2 +- .readthedocs.yaml | 3 ++- setup.py | 6 +++++- tox.ini | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 6b89530c3..4ef741c36 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -100,5 +100,5 @@ jobs: - name: Documentation run: | - pip install -r doc/requirements.txt + pip install ".[doc]" make -C doc html diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 0b83e20ea..9bce80fd2 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -32,4 +32,5 @@ python: install: - method: pip path: . - - requirements: doc/requirements.txt + extra_requirements: + - doc diff --git a/setup.py b/setup.py index 3f57e3327..143206653 100755 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ def _read_content(path: str) -> str: version = _read_content("VERSION").strip() requirements = _read_content("requirements.txt").splitlines() test_requirements = _read_content("test-requirements.txt").splitlines() +doc_requirements = _read_content("doc/requirements.txt").splitlines() long_description = _read_content("README.md") @@ -75,7 +76,10 @@ def _stamp_version(filename: str) -> None: package_dir={"git": "git"}, python_requires=">=3.7", install_requires=requirements, - extras_require={"test": test_requirements}, + extras_require={ + "test": test_requirements, + "doc": doc_requirements, + }, zip_safe=False, long_description=long_description, long_description_content_type="text/markdown", diff --git a/tox.ini b/tox.ini index 6e02e5aee..dfcb5ed8f 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,7 @@ ignore_outcome = true [testenv:html] description = Build HTML documentation base_python = py{39,310,311,312,38,37} -deps = -r doc/requirements.txt +extras = doc allowlist_externals = make commands = make BUILDDIR={env_tmp_dir}/doc/build -C doc clean