From dba42451187243ffe6d56a08e032dbcbb9ac615f Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 9 Sep 2023 16:55:44 -0400 Subject: [PATCH 01/17] Fix installation test for Python 3.12 and Windows Starting in Python 3.12, global and virtual Python environments no longer automatically ship setuptools (per the "ensurepip" item in https://docs.python.org/3.12/whatsnew/3.12.html#removed). Projects that use setuptools as a build backend are still supported, including with setup.py using techniques such as "pip install .". In Windows, the "bin" subdir of a virtual environment dir is called "Scripts" instead. Unlike in a global environment (where no names are universal, and "python3" and "pip3" are more common for the Python 3 commands on some popular Unix-like systems), in a virtual environment the "python" and "pip" commands are always present and "python3" and "pip3" are not guaranteed to be present. This commit changes test_installation accordingly. The CI workflows and documentation still need to be updated. --- test/test_installation.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/test_installation.py b/test/test_installation.py index c092aef5e..fea978ead 100644 --- a/test/test_installation.py +++ b/test/test_installation.py @@ -4,6 +4,7 @@ import ast import os import subprocess +from git.compat import is_win from test.lib import TestBase from test.lib.helper import with_rw_directory @@ -12,8 +13,9 @@ class TestInstallation(TestBase): def setUp_venv(self, rw_dir): self.venv = rw_dir subprocess.run(["virtualenv", self.venv], stdout=subprocess.PIPE) - self.python = os.path.join(self.venv, "bin/python3") - self.pip = os.path.join(self.venv, "bin/pip3") + bin_name = "Scripts" if is_win else "bin" + self.python = os.path.join(self.venv, bin_name, "python") + self.pip = os.path.join(self.venv, bin_name, "pip") self.sources = os.path.join(self.venv, "src") self.cwd = os.path.dirname(os.path.dirname(__file__)) os.symlink(self.cwd, self.sources, target_is_directory=True) @@ -32,14 +34,14 @@ def test_installation(self, rw_dir): msg=result.stderr or result.stdout or "Can't install requirements", ) result = subprocess.run( - [self.python, "setup.py", "install"], + [self.pip, "install", "."], stdout=subprocess.PIPE, cwd=self.sources, ) self.assertEqual( 0, result.returncode, - msg=result.stderr or result.stdout or "Can't build - setup.py failed", + msg=result.stderr or result.stdout or "Can't install project", ) result = subprocess.run([self.python, "-c", "import git"], stdout=subprocess.PIPE, cwd=self.sources) self.assertEqual( From 72e48aaea59738172ded5c964ddb4f06233ce9b7 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 9 Sep 2023 20:11:52 -0400 Subject: [PATCH 02/17] Update installation instructions in readme This changes the installation instructions in README.md to recommend "pip install ." instead of "python setup.py install". The former is compatible with Python 3.12 which doesn't have setuptools installed by default (so setup.py, which imports it, can be indirectly but not directly used). This also matches the corresponding change made in the installation unit test. While doing so, I've also clarified the instructions, and added the implied "cd" command as well as the "git fetch --tags" command in the position where a later section was recently updated to mention it should have been run. Using "pip install ." creates the opportunity to pass "-e" to make an editable install, which users who clone the repository to work on changes should do, because the effect of an editable install is only partially simulated by pytest, and so that manual testing of changes actually uses the changes intended for testing. This increases the length and detail of the instructions, so I've added h4 subsections to clarify the separations between them and make it easier for readers to find the part they're looking for. In doing so, I've reordered these subsections accordingly. Because greater detail can create the impression that all important steps are mentioned, I've made the general good advice to use a virtual environment explicit. For brevity, I have not added venv commands. --- README.md | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 94fcc76d9..c44985241 100644 --- a/README.md +++ b/README.md @@ -49,30 +49,49 @@ The installer takes care of installing them for you. ### INSTALL -If you have downloaded the source code: +GitPython and its required package dependencies can be installed in any of the following ways, all of which should typically be done in a [virtual environment](https://docs.python.org/3/tutorial/venv.html). -```bash -python setup.py install -``` +#### From PyPI -or if you want to obtain a copy from the Pypi repository: +To obtain and install a copy [from PyPI](https://pypi.org/project/GitPython/), run: ```bash pip install GitPython ``` -Both commands will install the required package dependencies. +(A distribution package can also be downloaded for manual installation at [the PyPI page](https://pypi.org/project/GitPython/).) + +#### From downloaded source code + +If you have downloaded the source code, run this from inside the unpacked `GitPython` directory: -A distribution package can be obtained for manual installation at: . +```bash +pip install . +``` -If you like to clone from source, you can do it like so: +#### By cloning the source code repository + +To clone the [the GitHub repository](https://github.com/gitpython-developers/GitPython) from source to work on the code, you can do it like so: ```bash git clone https://github.com/gitpython-developers/GitPython -git submodule update --init --recursive +cd GitPython +git fetch --tags ./init-tests-after-clone.sh ``` +If you are cloning [your own fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks), then replace the above `git clone` command with one that gives the URL of your fork. Or use this [`gh`](https://cli.github.com/) command (assuming you have `gh` and your fork is called `GitPython`): + +```bash +gh repo clone GitPython +``` + +Having cloned the repo, create and activate your [virtual environment](https://docs.python.org/3/tutorial/venv.html). Then make an [editable install](https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs): + +```bash +pip install -e . +``` + ### Limitations #### Leakage of System Resources From b095aa9f61691151e68efb972659ac018c8e939d Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 9 Sep 2023 20:27:04 -0400 Subject: [PATCH 03/17] Use more compatible hashbangs This adds a #! line to the top of setup.py, because it is a script with the executable bit set. Although neither recent nor current documentation in the project recommends to run "./setup.py", this should probably have the intuitive effect of attempting to run the script with a Python interpreter rather than a Unix-style shell. It also uses the "env trick" in init-tests-after-clone.sh so that script runs with whatever bash interpreter is found in a normal PATH search. While "sh" is expected to be found in /bin on all Unix-like systems, that is not always the case for "bash". This change slightly improves compatibility by supporting systems that don't ship with bash but on which it has been installed. --- init-tests-after-clone.sh | 8 +++++--- setup.py | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/init-tests-after-clone.sh b/init-tests-after-clone.sh index e852f3cd9..95ced98b7 100755 --- a/init-tests-after-clone.sh +++ b/init-tests-after-clone.sh @@ -1,7 +1,9 @@ -#!/bin/bash -e +#!/usr/bin/env bash + +set -e if [[ -z "$TRAVIS" ]]; then - read -p "This operation will destroy locally modified files. Continue ? [N/y]: " answer + read -rp "This operation will destroy locally modified files. Continue ? [N/y]: " answer if [[ ! $answer =~ [yY] ]]; then exit 2 fi @@ -13,4 +15,4 @@ git reset --hard HEAD~1 git reset --hard HEAD~1 git reset --hard HEAD~1 git reset --hard __testing_point__ -git submodule update --init --recursive \ No newline at end of file +git submodule update --init --recursive diff --git a/setup.py b/setup.py index ebece64eb..403482520 100755 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + from typing import Sequence from setuptools import setup, find_packages from setuptools.command.build_py import build_py as _build_py From 63c46240334d36129a78866a54694ea8fa5edd16 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 9 Sep 2023 21:51:13 -0400 Subject: [PATCH 04/17] Don't duplicate packages across requirements files - Remove "gitdb" from test-requirements.txt, because it already a dependency of the project (listed in requirements.txt, which is used to build the value passed for install_requires in setup.py). - Remove "black" from requirements-dev.txt, because it is listed in test-requirement.txt (which requirements-dev.txt sources). --- requirements-dev.txt | 1 - test-requirements.txt | 2 -- 2 files changed, 3 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 946b4c94f..f6705341c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,6 @@ # libraries for additional local testing/linting - to be added to test-requirements.txt when all pass flake8-type-checking;python_version>="3.8" # checks for TYPE_CHECKING only imports -black pytest-icdiff # pytest-profiling diff --git a/test-requirements.txt b/test-requirements.txt index 6c6d57060..e202d35c5 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -11,5 +11,3 @@ pytest pytest-cov coverage[toml] pytest-sugar - -gitdb From 3aacb3717ad78ec40e5b168a7ce8109aee6f156e Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 9 Sep 2023 23:13:20 -0400 Subject: [PATCH 05/17] Use a "test" extra instead of tests_require Because tests_require is deprecated since setuptools 41.5.0 with the intention that it will be removed in some future version (noted in https://setuptools.pypa.io/en/latest/references/keywords.html). It is somewhat unintuitive for GitPython to have a "test" extra, as it makes it so "GitPython[test]" can be specified for installation from PyPI to get test dependencies, even though the PyPI package doesn't include the unit test themselves. However, this makes the statement in README.md that the installer takes care of both requirements.txt and test-requirements.txt dependencies fully true, instead of moving further away from that. Because it is now possible to make an editable GitPython install with test as well as minimal dependencies installed, this commit also updates the readme to document and recommend this. --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++--------- setup.py | 2 +- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c44985241..4ff04c2e4 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,11 @@ gh repo clone GitPython Having cloned the repo, create and activate your [virtual environment](https://docs.python.org/3/tutorial/venv.html). Then make an [editable install](https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs): ```bash -pip install -e . +pip install -e ".[test]" ``` +In the less common case that you do not want to install test dependencies, `pip install -e .` can be used instead. + ### Limitations #### Leakage of System Resources @@ -120,20 +122,49 @@ On _Windows_, make sure you have `git-daemon` in your PATH. For MINGW-git, the ` exists in `Git\mingw64\libexec\git-core\`; CYGWIN has no daemon, but should get along fine with MINGW's. -Ensure testing libraries are installed. -In the root directory, run: `pip install -r test-requirements.txt` +#### Install test dependencies + +Ensure testing libraries are installed. This is taken care of already if you installed with: + +```bash +pip install -e ".[test]" +``` + +Otherwise, you can run: + +```bash +pip install -r test-requirements.txt +``` + +#### Test commands + +To test, run: -To lint, run: `pre-commit run --all-files` +```bash +pytest +``` + +To lint, run: -To typecheck, run: `mypy -p git` +```bash +pre-commit run --all-files +``` -To test, run: `pytest` +To typecheck, run: -For automatic code formatting run: `black git` +```bash +mypy -p git +``` + +For automatic code formatting, run: + +```bash +black git +``` -Configuration for flake8 is in the ./.flake8 file. +Configuration for flake8 is in the `./.flake8` file. -Configurations for mypy, pytest and coverage.py are in ./pyproject.toml. +Configurations for `mypy`, `pytest`, `coverage.py`, and `black` are in `./pyproject.toml`. The same linting and testing will also be performed against different supported python versions upon submitting a pull request (or on each push if you have a fork with a "main" branch and actions enabled). diff --git a/setup.py b/setup.py index 403482520..5516a67d1 100755 --- a/setup.py +++ b/setup.py @@ -95,7 +95,7 @@ def build_py_modules(basedir: str, excludes: Sequence = ()) -> Sequence: package_dir={"git": "git"}, python_requires=">=3.7", install_requires=requirements, - tests_require=requirements + test_requirements, + extras_require={"test": test_requirements}, zip_safe=False, long_description=long_description, long_description_content_type="text/markdown", From e1d8b40e91eedabc3a2c2c1ac653f86b662323a9 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 9 Sep 2023 23:33:06 -0400 Subject: [PATCH 06/17] Use "build" for building Instead of directly running setup.py. This allows Python 3.12 (as well as previous versions) to be used for building. Although setuptools could be added as a development dependency to run setup.py, using "build" instead is recommended in https://setuptools.pypa.io/en/latest/userguide/quickstart.html. Those docs likewise recommend only listing "wheel" in the build-system section of pyproject.toml if setup.py actually imports the wheel module. So this removes that. (Running "make release", which now uses "build", will continue to build wheels.) The "build" package is not conceptually a testing dependency, but test-requirements.txt is currently the de facto list of all stable development dependencies for regular use. --- Makefile | 2 +- pyproject.toml | 2 +- test-requirements.txt | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2af8de084..6bde85af1 100644 --- a/Makefile +++ b/Makefile @@ -16,5 +16,5 @@ release: clean force_release: clean git push --tags origin main - python3 setup.py sdist bdist_wheel + python -m build --sdist --wheel twine upload dist/* diff --git a/pyproject.toml b/pyproject.toml index 32c9d4a26..42bb31eda 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "wheel"] +requires = ["setuptools"] build-backend = "setuptools.build_meta" [tool.pytest.ini_options] diff --git a/test-requirements.txt b/test-requirements.txt index e202d35c5..67496031e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,6 +5,7 @@ black pre-commit +build virtualenv pytest From b9b6d8c07eb9afb88f092e507db9ae467e5e0986 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 9 Sep 2023 23:55:26 -0400 Subject: [PATCH 07/17] Ungroup and sort test_requirements.txt This is cleanup related to the previous commit. As that file grows, it is harder to tell immediately if a particular package is in it when not alphabetized. (The groups were also not intuitive, with ddt listed separately from other unit test related dependencies.) --- test-requirements.txt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 67496031e..214ad78ec 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,14 +1,10 @@ +black +build +coverage[toml] ddt>=1.1.1, !=1.4.3 mypy - -black - pre-commit - -build -virtualenv - pytest pytest-cov -coverage[toml] pytest-sugar +virtualenv From 21c5f8749590480de7cbcfe87352b60759328a75 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sun, 10 Sep 2023 00:08:58 -0400 Subject: [PATCH 08/17] Don't preinstall dependencies in test_installation This removes the step in test_installation that did the equivalent of "pip install -r requirements.txt", because installing GitPython is sufficient to install all its required dependencies, and it is more important to test that than to test requirements.txt directly. Removing this causes the test to fail if installing the project doesn't entail installation of the requirements necessary to import the git module or to cause gitdb to be found in a sys.path search. --- test/test_installation.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/test_installation.py b/test/test_installation.py index fea978ead..d856ebc94 100644 --- a/test/test_installation.py +++ b/test/test_installation.py @@ -23,16 +23,6 @@ def setUp_venv(self, rw_dir): @with_rw_directory def test_installation(self, rw_dir): self.setUp_venv(rw_dir) - result = subprocess.run( - [self.pip, "install", "-r", "requirements.txt"], - stdout=subprocess.PIPE, - cwd=self.sources, - ) - self.assertEqual( - 0, - result.returncode, - msg=result.stderr or result.stdout or "Can't install requirements", - ) result = subprocess.run( [self.pip, "install", "."], stdout=subprocess.PIPE, From 6b54890cfc14f1c574e8bf85d1ebf9be4c92be3e Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sun, 10 Sep 2023 01:18:44 -0400 Subject: [PATCH 09/17] Test changed setup, and Python 3.12, on CI Key changes: - Update the two CI workflows to install the project and its dependencies in accordance with the changed recommendations in README.md. (This is to test that those recommendations work, which the changed test_installation test case partially but not completely tests. The old approach to installation still works too, so this change on CI is not required to keep CI working.) - Add Python 3.12 to the CI test matrix in pythonpackage.yml, testing it on Ubuntu. (The Cygwin workflow still tests only 3.9.) Maintenance changes, made to avoid decreasing readability with the other changes (and hopefully even increase it somewhat): - Separate commands into more steps, grouping them by more specific purposes. - Decrease the ways the two workflows differ from each other that do not represent actual intended behavioral differences. This is to make the important differences easier to stop, and to make it easier to determine when the same change has or has not been made to both workflows. --- .github/workflows/cygwin-test.yml | 41 ++++++++++++++++++------ .github/workflows/pythonpackage.yml | 48 +++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 19 deletions(-) diff --git a/.github/workflows/cygwin-test.yml b/.github/workflows/cygwin-test.yml index 808dc5608..ceb988cec 100644 --- a/.github/workflows/cygwin-test.yml +++ b/.github/workflows/cygwin-test.yml @@ -12,38 +12,61 @@ jobs: SHELLOPTS: igncr TMP: "/tmp" TEMP: "/tmp" + defaults: + run: + shell: bash.exe -eo pipefail -o igncr "{0}" steps: - name: Force LF line endings run: git config --global core.autocrlf input + - uses: actions/checkout@v4 with: fetch-depth: 9999 + - uses: cygwin/cygwin-install-action@v4 with: packages: python39 python39-pip python39-virtualenv git + + - name: Show python and git versions + run: | + set -x + /usr/bin/python --version + /usr/bin/git version + - name: Tell git to trust this repo - shell: bash.exe -eo pipefail -o igncr "{0}" run: | /usr/bin/git config --global --add safe.directory "$(pwd)" - - name: Install dependencies and prepare tests - shell: bash.exe -eo pipefail -o igncr "{0}" + + - name: Prepare this repo for tests run: | set -x - /usr/bin/python -m pip install --upgrade pip setuptools wheel - /usr/bin/python --version; /usr/bin/git --version + /usr/bin/git submodule update --init --recursive /usr/bin/git fetch --tags - /usr/bin/python -m pip install -r requirements.txt - /usr/bin/python -m pip install -r test-requirements.txt TRAVIS=yes ./init-tests-after-clone.sh + + - name: Further prepare git configuration for tests + run: | + set -x + /usr/bin/git config --global user.email "travis@ci.com" /usr/bin/git config --global user.name "Travis Runner" # If we rewrite the user's config by accident, we will mess it up # and cause subsequent tests to fail cat test/fixtures/.gitconfig >> ~/.gitconfig + + - name: Update PyPA packages + run: | + set -x + /usr/bin/python -m pip install --upgrade pip setuptools wheel + + - name: Install project and test dependencies + run: | + set -x + /usr/bin/python -m pip install ".[test]" + - name: Test with pytest - shell: bash.exe -eo pipefail -o igncr "{0}" run: | + set -x /usr/bin/python -m pytest - continue-on-error: false diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index a6af507d1..9f15ceb2e 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -15,42 +15,70 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.7, 3.8, 3.9, "3.10", "3.11"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + include: + - experimental: false + - python-version: "3.12" + experimental: true steps: - uses: actions/checkout@v4 with: fetch-depth: 9999 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - name: Install dependencies and prepare tests + allow-prereleases: ${{ matrix.experimental }} + + - name: Show python and git versions + run: | + set -x + python --version + git version + + - name: Prepare this repo for tests run: | set -x - python -m pip install --upgrade pip setuptools wheel - python --version; git --version git submodule update --init --recursive git fetch --tags --force - - pip install -r requirements.txt - pip install -r test-requirements.txt TRAVIS=yes ./init-tests-after-clone.sh + - name: Prepare git configuration for tests + run: | + set -x + git config --global user.email "travis@ci.com" git config --global user.name "Travis Runner" # If we rewrite the user's config by accident, we will mess it up # and cause subsequent tests to fail cat test/fixtures/.gitconfig >> ~/.gitconfig + - name: Update PyPA packages + run: | + set -x + + python -m pip install --upgrade pip + if pip freeze --all | grep --quiet '^setuptools=='; then + # Python prior to 3.12 ships setuptools. Upgrade it if present. + python -m pip install --upgrade setuptools + fi + python -m pip install --upgrade wheel + + - name: Install project and test dependencies + run: | + set -x + pip install ".[test]" + - name: Check types with mypy - # With new versions of pypi new issues might arise. This is a problem if there is nobody able to fix them, - # so we have to ignore errors until that changes. - continue-on-error: true run: | set -x mypy -p git + # With new versions of mypy new issues might arise. This is a problem if there is nobody able to fix them, + # so we have to ignore errors until that changes. + continue-on-error: true - name: Test with pytest run: | From 055355d0028147c27b0423d713803748e60af6c3 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sun, 10 Sep 2023 04:23:25 -0400 Subject: [PATCH 10/17] Don't use "set -x" for "pytest" command on Cygwin The omission of "set -x" was intentional and is currently necessary on Cygwin (but not on Ubuntu), per aafb92a. --- .github/workflows/cygwin-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/cygwin-test.yml b/.github/workflows/cygwin-test.yml index ceb988cec..2e2e6d12d 100644 --- a/.github/workflows/cygwin-test.yml +++ b/.github/workflows/cygwin-test.yml @@ -68,5 +68,4 @@ jobs: - name: Test with pytest run: | - set -x /usr/bin/python -m pytest From a352404576552116bd16d9ca40cbcb903d3af020 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sun, 10 Sep 2023 13:24:40 -0400 Subject: [PATCH 11/17] List Python 3.12 as supported in setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 5516a67d1..44623d049 100755 --- a/setup.py +++ b/setup.py @@ -124,5 +124,6 @@ def build_py_modules(basedir: str, excludes: Sequence = ()) -> Sequence: "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ], ) From 415a8ebdf8d0648cd17218e817963721d8df54da Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sun, 10 Sep 2023 13:28:16 -0400 Subject: [PATCH 12/17] Small clarity improvements in setup.py --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 44623d049..bc53bf6c8 100755 --- a/setup.py +++ b/setup.py @@ -8,8 +8,8 @@ import os import sys -with open(os.path.join(os.path.dirname(__file__), "VERSION")) as v: - VERSION = v.readline().strip() +with open(os.path.join(os.path.dirname(__file__), "VERSION")) as ver_file: + VERSION = ver_file.readline().strip() with open("requirements.txt") as reqs_file: requirements = reqs_file.read().splitlines() @@ -49,7 +49,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: From 4eef3ecd5b2eb65f1e98457a35df8700166f67b0 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Mon, 11 Sep 2023 00:41:04 -0400 Subject: [PATCH 13/17] Have actions/checkout do the full fetch Setting the "fetch-depth" to 0 does a deep (i.e., ordinary) fetch, fetching all commits and tags. Setting "submodules" to "recursive" clones and checks out all submodules. These options allow commands that were doing those things to be removed from the later steps. --- .github/workflows/cygwin-test.yml | 6 ++---- .github/workflows/pythonpackage.yml | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cygwin-test.yml b/.github/workflows/cygwin-test.yml index 2e2e6d12d..533022b91 100644 --- a/.github/workflows/cygwin-test.yml +++ b/.github/workflows/cygwin-test.yml @@ -22,7 +22,8 @@ jobs: - uses: actions/checkout@v4 with: - fetch-depth: 9999 + fetch-depth: 0 + submodules: recursive - uses: cygwin/cygwin-install-action@v4 with: @@ -41,9 +42,6 @@ jobs: - name: Prepare this repo for tests run: | set -x - - /usr/bin/git submodule update --init --recursive - /usr/bin/git fetch --tags TRAVIS=yes ./init-tests-after-clone.sh - name: Further prepare git configuration for tests diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 9f15ceb2e..cce39d17a 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -24,7 +24,8 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 9999 + fetch-depth: 0 + submodules: recursive - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 @@ -41,9 +42,6 @@ jobs: - name: Prepare this repo for tests run: | set -x - - git submodule update --init --recursive - git fetch --tags --force TRAVIS=yes ./init-tests-after-clone.sh - name: Prepare git configuration for tests From 5f128e8c23e730748eb73bc2eb9f8ee552064e93 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Mon, 11 Sep 2023 01:42:40 -0400 Subject: [PATCH 14/17] Move effect of "set -x" into default shell command This also adds "--noprofile --norc" to the Cygwin shell command as a speed optimization (bash doesn't need to source its scripts). That only changes the Cygwin workflow; in the Ubuntu workflow, "--noprofile --norc" had already been included by default when no shell was specified, so having it there is to *keep* the optimized behavior that was already in use. --- .github/workflows/cygwin-test.yml | 11 +++-------- .github/workflows/pythonpackage.yml | 13 +++---------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cygwin-test.yml b/.github/workflows/cygwin-test.yml index 533022b91..962791ae7 100644 --- a/.github/workflows/cygwin-test.yml +++ b/.github/workflows/cygwin-test.yml @@ -14,7 +14,7 @@ jobs: TEMP: "/tmp" defaults: run: - shell: bash.exe -eo pipefail -o igncr "{0}" + shell: bash.exe --noprofile --norc -exo pipefail -o igncr "{0}" steps: - name: Force LF line endings @@ -31,23 +31,19 @@ jobs: - name: Show python and git versions run: | - set -x /usr/bin/python --version /usr/bin/git version - name: Tell git to trust this repo run: | - /usr/bin/git config --global --add safe.directory "$(pwd)" + /usr/bin/git config --global --add safe.directory "$(pwd)" - name: Prepare this repo for tests run: | - set -x TRAVIS=yes ./init-tests-after-clone.sh - name: Further prepare git configuration for tests run: | - set -x - /usr/bin/git config --global user.email "travis@ci.com" /usr/bin/git config --global user.name "Travis Runner" # If we rewrite the user's config by accident, we will mess it up @@ -56,14 +52,13 @@ jobs: - name: Update PyPA packages run: | - set -x /usr/bin/python -m pip install --upgrade pip setuptools wheel - name: Install project and test dependencies run: | - set -x /usr/bin/python -m pip install ".[test]" - name: Test with pytest run: | + set +x /usr/bin/python -m pytest diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index cce39d17a..a5467ef94 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -20,6 +20,9 @@ jobs: - experimental: false - python-version: "3.12" experimental: true + defaults: + run: + shell: /bin/bash --noprofile --norc -exo pipefail {0} steps: - uses: actions/checkout@v4 @@ -35,19 +38,15 @@ jobs: - name: Show python and git versions run: | - set -x python --version git version - name: Prepare this repo for tests run: | - set -x TRAVIS=yes ./init-tests-after-clone.sh - name: Prepare git configuration for tests run: | - set -x - git config --global user.email "travis@ci.com" git config --global user.name "Travis Runner" # If we rewrite the user's config by accident, we will mess it up @@ -56,8 +55,6 @@ jobs: - name: Update PyPA packages run: | - set -x - python -m pip install --upgrade pip if pip freeze --all | grep --quiet '^setuptools=='; then # Python prior to 3.12 ships setuptools. Upgrade it if present. @@ -67,12 +64,10 @@ jobs: - name: Install project and test dependencies run: | - set -x pip install ".[test]" - name: Check types with mypy run: | - set -x mypy -p git # With new versions of mypy new issues might arise. This is a problem if there is nobody able to fix them, # so we have to ignore errors until that changes. @@ -80,12 +75,10 @@ jobs: - name: Test with pytest run: | - set -x pytest continue-on-error: false - name: Documentation run: | - set -x pip install -r doc/requirements.txt make -C doc html From d99b2d4629f2257ac719f77b93e1a2d7affd08c6 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 11 Sep 2023 11:26:57 +0200 Subject: [PATCH 15/17] prepare next release --- VERSION | 2 +- doc/source/changes.rst | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index d87cdbb81..b402c1a8b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.35 +3.1.36 diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 6302176bd..06ec4b72c 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -2,6 +2,14 @@ Changelog ========= +3.1.36 +====== + +Note that this release should be a no-op, it's mainly for testing the changed release-process. + +See the following for all changes. +https://github.com/gitpython-developers/gitpython/milestone/66?closed=1 + 3.1.35 ====== From f86f09e12c5616680e19b45c940144520349c9e3 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 11 Sep 2023 12:53:21 +0200 Subject: [PATCH 16/17] Make publish process possible on MacOS There the system python interpreter is referred to as `python3`, at least when installed by homebrew. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6bde85af1..c3c00e948 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,6 @@ release: clean make force_release force_release: clean - git push --tags origin main - python -m build --sdist --wheel + python3 -m build --sdist --wheel twine upload dist/* + git push --tags origin main From 5343aa01e9d90481e4570797e99faf6a98ba8f6c Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Mon, 11 Sep 2023 13:39:34 -0400 Subject: [PATCH 17/17] Let "make" install build and twine if in a virtual environment If a virtual environment (created by venv or virtualenv) is active, running "make release" or "make force_release" now automatically installs/upgrades the "build" and "twine" packages in it. This is only done if "make" is run in a virtual environment. This can be a fresh environment: neither the project nor its dependencies need to be installed in it. Because the "build" module is not currently used in any tests and running "make" in a virtual environment takes care of installing "build" (and "twine"), "build" is now removed from test-requirements.txt. The publishing instructions in the readme are updated accordingly, to mention the optional step of creating and activating a virtual environment, and to briefly clarify why one might want to do that. Running "make" outside a virtual environment remains supported, except that, due to recent changes, whatever environment it is run in needs to have a usable "build" module. --- Makefile | 2 ++ README.md | 14 ++++++++------ test-requirements.txt | 1 - 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index c3c00e948..f2cbf826a 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ release: clean make force_release force_release: clean + # IF we're in a virtual environment, add build tools + test -z "$$VIRTUAL_ENV" || pip install -U build twine python3 -m build --sdist --wheel twine upload dist/* git push --tags origin main diff --git a/README.md b/README.md index 4ff04c2e4..ca470a851 100644 --- a/README.md +++ b/README.md @@ -188,13 +188,15 @@ Please have a look at the [contributions file][contributing]. ### How to make a new release -- Update/verify the **version** in the `VERSION` file -- Update/verify that the `doc/source/changes.rst` changelog file was updated -- Commit everything -- Run `git tag -s ` to tag the version in Git -- Run `make release` +- Update/verify the **version** in the `VERSION` file. +- Update/verify that the `doc/source/changes.rst` changelog file was updated. +- Commit everything. +- Run `git tag -s ` to tag the version in Git. +- _Optionally_ create and activate a [virtual environment](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment) using `venv` or `virtualenv`.\ +(When run in a virtual environment, the next step will automatically take care of installing `build` and `twine` in it.) +- Run `make release`. - Close the milestone mentioned in the _changelog_ and create a new one. _Do not reuse milestones by renaming them_. -- Got to [GitHub Releases](https://github.com/gitpython-developers/GitPython/releases) and publish a new one with the recently pushed tag. Generate the changelog. +- Go to [GitHub Releases](https://github.com/gitpython-developers/GitPython/releases) and publish a new one with the recently pushed tag. Generate the changelog. ### How to verify a release (DEPRECATED) diff --git a/test-requirements.txt b/test-requirements.txt index 214ad78ec..62f409824 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,4 @@ black -build coverage[toml] ddt>=1.1.1, !=1.4.3 mypy