Skip to content

Commit c9366e5

Browse files
committed
Fix ruff formatting and update AGENTS.md
Reformat pygit2/__init__.py, pygit2/callbacks.py, pygit2/remotes.py and pygit2/repository.py to fix the 'ruff format --diff' CI failure. Also refresh AGENTS.md (build commands, CI details, mypy strictness for tests) and document that AI-authored commits must carry the Assisted-by trailer. Assisted-by: Kimi Code
1 parent 3f33544 commit c9366e5

5 files changed

Lines changed: 51 additions & 24 deletions

File tree

AGENTS.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,25 @@ modules:
5656
`repository.py`, `callbacks.py`, `config.py`, `index.py`, `remotes.py`,
5757
`settings.py`, `submodules.py`, `transaction.py`, `filter.py`, `blob.py`,
5858
`blame.py`, `branches.py`, `credentials.py`, `errors.py`, `options.py`,
59-
`packbuilder.py`, `references.py`, `refspec.py`, `utils.py`, `enums.py`.
59+
`packbuilder.py`, `rebase.py`, `references.py`, `refspec.py`, `utils.py`,
60+
`enums.py`.
6061

6162
- **`test/`** — pytest suite with fixture-based repository handling.
6263
- **`docs/`** — Sphinx documentation (RTD theme).
6364

6465
## Key Configuration Files
6566

6667
- **`setup.py`** — setuptools entry point. Builds both the C extension
67-
(`src/*.c`) and the CFFI extension (`pygit2/_run.py:ffi`).
68+
(`src/*.c`) and the CFFI extension (`pygit2/_run.py:ffi`). On Windows it
69+
also copies `git2.dll` into the package (see `BuildWithDLLs`).
6870
- **`pyproject.toml`** — Build-system requirements, `cibuildwheel`
6971
configuration, `ruff` settings, and `codespell` settings.
7072
- **`setup.cfg`** — Legacy pycodestyle configuration.
7173
- **`pytest.ini`** — pytest configuration (`--capture=no -ra --verbose`,
7274
`testpaths = test/`).
7375
- **`mypy.ini`** — mypy configuration with strict settings.
7476
- **`mypy-stubtest.ini`** — mypy configuration for `stubtest` against
75-
`_pygit2.pyi`.
77+
`_pygit2.pyi` (at the repo root).
7678
- **`requirements.txt`** — Runtime/build requirements (`cffi>=2.0`,
7779
`setuptools` for Python >= 3.12).
7880
- **`requirements-test.txt`** — Test requirements (`pytest`, `pytest-cov`).
@@ -107,14 +109,12 @@ make
107109
# Or manually:
108110
LIBSSH2_VERSION=1.11.1 LIBGIT2_VERSION=1.9.6 sh build.sh
109111

110-
# Build inplace and run the tests
111-
sh build.sh test
112-
113-
# Build a wheel, install it, and run the tests
112+
# Build a wheel and bundle the shared libraries into it
114113
sh build.sh wheel
114+
sh build.sh bundle
115115

116-
# Run tests with coverage
117-
sh build.sh test # build.sh adds --cov=pygit2
116+
# Build inplace and run the tests with coverage (build.sh adds --cov=pygit2)
117+
sh build.sh test
118118

119119
# Run mypy type checking
120120
sh build.sh mypy
@@ -169,7 +169,9 @@ make -C docs html # requires sphinx-rtd-theme
169169
- Run `ruff format` and `ruff check` on changed files before committing.
170170
CI runs `ruff format --diff` and `ruff check`; formatting failures will
171171
fail the build.
172-
- **Type checker**: mypy (strict settings enabled; see `mypy.ini`)
172+
- **Type checker**: mypy (strict settings enabled; see `mypy.ini`). Test
173+
modules additionally require typed defs and calls (`disallow_untyped_defs`,
174+
`disallow_untyped_calls` under `[mypy-test.*]`).
173175
- All Python source files must include the standard GPLv2 copyright header.
174176
- `pygit2/__init__.py` is large because it re-exports a large surface of
175177
constants and classes; follow existing patterns when adding new public
@@ -235,13 +237,15 @@ def f(a, b):
235237
GitHub Actions workflows live in `.github/workflows/`:
236238

237239
- **`tests.yml`** — Runs on s390x via QEMU (`uraimo/run-on-arch-action`).
238-
Allowed to fail; see issue #812.
240+
Allowed to fail (`continue-on-error`); see issue #812.
239241
- **`lint.yml`** — Runs `ruff format --diff`, `ruff check`, and
240242
`sh build.sh mypy`.
241-
- **`wheels.yml`** — Uses `cibuildwheel` to build wheels for Linux (amd64,
242-
arm64, ppc64le, musl), macOS (intel, arm64, PyPy), and Windows (x64, x86,
243-
arm64). It also builds an sdist, runs a `twine check`, publishes to PyPI,
244-
and creates a GitHub Release on version tags (`v*`).
243+
- **`wheels.yml`** — Uses `cibuildwheel` (`~=3.3`) to build wheels for Linux
244+
(amd64, arm64, ppc64le and riscv64 via QEMU, musl), macOS (intel, arm64,
245+
PyPy), and Windows (x64, x86, arm64). It also builds an sdist, runs a
246+
`twine check` (skipped on version tags), publishes to PyPI, and creates a
247+
GitHub Release on version tags (`v*`), with release notes parsed from
248+
`CHANGELOG.md` by `.github/workflows/parse_release_notes.py`.
245249
- **`codespell.yml`** — Spell checking with the codespell action.
246250

247251
The `cibuildwheel` configuration in `pyproject.toml` pins:
@@ -250,8 +254,10 @@ The `cibuildwheel` configuration in `pyproject.toml` pins:
250254
- `LIBSSH2_VERSION="1.11.1"`
251255
- `OPENSSL_VERSION="3.5.4"`
252256

253-
and skips `*musllinux_ppc64le` plus testing on `*-*linux_ppc64le` and
254-
`pp*-macosx_arm64`.
257+
and skips `*musllinux_ppc64le` plus testing on `*-*linux_ppc64le`,
258+
`*-*linux_riscv64` and `pp*-macosx_arm64`. On Windows it uses the
259+
`Visual Studio 18 2026` CMake generator for x64/x86 and
260+
`Visual Studio 17 2022` for ARM64.
255261

256262
## Security Considerations
257263

@@ -264,6 +270,11 @@ and skips `*musllinux_ppc64le` plus testing on `*-*linux_ppc64le` and
264270
- Valgrind support: see `docs/development.rst` and
265271
`misc/valgrind-python.supp` for memory-leak debugging instructions.
266272

273+
## Git Commits
274+
275+
- Commits created by an AI agent must end with the `Assisted-by:` trailer.
276+
Human-authored commits do not need it.
277+
267278
## Useful Notes for Agents
268279

269280
- **Do not assume libgit2 is installed globally.** Check for `LIBGIT2` or use

pygit2/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,17 @@ def clone_repository(
531531
opts.fetch_opts.depth = depth
532532

533533
if checkout_branch:
534-
checkout_branch_ref = ffi.new('char []', utils.encode_string(checkout_branch))
534+
checkout_branch_ref = ffi.new(
535+
'char []', utils.encode_string(checkout_branch)
536+
)
535537
opts.checkout_branch = checkout_branch_ref
536538

537539
with git_fetch_options(payload, opts=opts.fetch_opts):
538540
with git_proxy_options(payload, opts.fetch_opts.proxy_opts, proxy):
539541
crepo = ffi.new('git_repository **')
540-
err = C.git_clone(crepo, utils.encode_string(url), utils.encode_fs_path(path), opts)
542+
err = C.git_clone(
543+
crepo, utils.encode_string(url), utils.encode_fs_path(path), opts
544+
)
541545
payload.check_error(err)
542546

543547
# Ok

pygit2/callbacks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,11 @@ def get_credentials(fn, url, username, allowed):
756756
err = C.git_credential_ssh_key_from_agent(ccred, name)
757757
else:
758758
err = C.git_credential_ssh_key_new(
759-
ccred, name, encode_string(pubkey), encode_string(privkey), encode_string(passphrase)
759+
ccred,
760+
name,
761+
encode_string(pubkey),
762+
encode_string(privkey),
763+
encode_string(passphrase),
760764
)
761765

762766
elif cred_type == CredentialType.USERNAME:

pygit2/remotes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,16 @@ def delete(self, name: str) -> None:
485485

486486
def set_url(self, name: str, url: str) -> None:
487487
"""Set the URL for a remote"""
488-
err = C.git_remote_set_url(self._repo._repo, encode_string(name), encode_string(url))
488+
err = C.git_remote_set_url(
489+
self._repo._repo, encode_string(name), encode_string(url)
490+
)
489491
check_error(err)
490492

491493
def set_push_url(self, name: str, url: str) -> None:
492494
"""Set the push-URL for a remote"""
493-
err = C.git_remote_set_pushurl(self._repo._repo, encode_string(name), encode_string(url))
495+
err = C.git_remote_set_pushurl(
496+
self._repo._repo, encode_string(name), encode_string(url)
497+
)
494498
check_error(err)
495499

496500
def add_fetch(self, name: str, refspec: str) -> None:
@@ -504,5 +508,7 @@ def add_fetch(self, name: str, refspec: str) -> None:
504508
def add_push(self, name: str, refspec: str) -> None:
505509
"""Add a push refspec (str) to the remote"""
506510

507-
err = C.git_remote_add_push(self._repo._repo, encode_string(name), encode_string(refspec))
511+
err = C.git_remote_add_push(
512+
self._repo._repo, encode_string(name), encode_string(refspec)
513+
)
508514
check_error(err)

pygit2/repository.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,9 @@ def set_ident(self, name: Optional[str], email: Optional[str]) -> None:
18201820
used. If none is set, it will be read from the configuration.
18211821
"""
18221822

1823-
err = C.git_repository_set_ident(self._repo, encode_string(name), encode_string(email))
1823+
err = C.git_repository_set_ident(
1824+
self._repo, encode_string(name), encode_string(email)
1825+
)
18241826
check_error(err)
18251827

18261828
def revert(self, commit: Commit) -> None:

0 commit comments

Comments
 (0)