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

Improve Python version and OS compatibility, fixing deprecations #1654

Merged
merged 17 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions .github/workflows/cygwin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,60 @@ 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 "[email protected]"
/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: |
/usr/bin/python -m pytest
continue-on-error: false
48 changes: 38 additions & 10 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
EliahKagan marked this conversation as resolved.
Show resolved Hide resolved
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 "[email protected]"
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: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Byron marked this conversation as resolved.
Show resolved Hide resolved
twine upload dist/*
84 changes: 67 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,51 @@ 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:

```bash
pip install .
```

A distribution package can be obtained for manual installation at: <http://pypi.python.org/pypi/GitPython>.
#### By cloning the source code repository

If you like to clone from source, you can do it like so:
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 ".[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
Expand Down Expand Up @@ -101,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

To lint, run: `pre-commit run --all-files`
Ensure testing libraries are installed. This is taken care of already if you installed with:

To typecheck, run: `mypy -p git`
```bash
pip install -e ".[test]"
```

To test, run: `pytest`
Otherwise, you can run:

For automatic code formatting run: `black git`
```bash
pip install -r test-requirements.txt
```

#### Test commands

To test, run:

```bash
pytest
```

To lint, run:

```bash
pre-commit run --all-files
```

To typecheck, run:

```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).
Expand Down
8 changes: 5 additions & 3 deletions init-tests-after-clone.sh
Original file line number Diff line number Diff line change
@@ -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
Byron marked this conversation as resolved.
Show resolved Hide resolved
exit 2
fi
Expand All @@ -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
git submodule update --init --recursive
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -6,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()
Expand Down Expand Up @@ -47,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:
Expand Down Expand Up @@ -93,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",
Expand Down Expand Up @@ -122,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",
EliahKagan marked this conversation as resolved.
Show resolved Hide resolved
],
)
13 changes: 4 additions & 9 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
black
build
coverage[toml]
ddt>=1.1.1, !=1.4.3
mypy

black

pre-commit

virtualenv

pytest
pytest-cov
coverage[toml]
pytest-sugar

gitdb
virtualenv
Loading
Loading