Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
55bc286
add some rules to ruff
DinhHuy2010 Dec 21, 2024
2c06530
ignore unused imports
DinhHuy2010 Dec 21, 2024
484886a
Initial formatting and liniting fix of all files
DinhHuy2010 Dec 21, 2024
6330d4b
add type checking configuration (use pyright)
DinhHuy2010 Dec 21, 2024
325891b
add _libgit2.pyi
DinhHuy2010 Dec 21, 2024
aa37e2d
mega fix _pygit2.pyi
DinhHuy2010 Dec 21, 2024
b53b9a7
fix stubs
DinhHuy2010 Dec 21, 2024
c70241d
change lib to Any
DinhHuy2010 Dec 21, 2024
42b5129
fix pyright config
DinhHuy2010 Dec 21, 2024
5f6657e
fix _pygit2.pyi again
DinhHuy2010 Dec 21, 2024
4b3878b
fix enums.py
DinhHuy2010 Dec 21, 2024
49bc71b
add FilterSource
DinhHuy2010 Dec 21, 2024
7433683
yet another fix the _pygit2.pyi
DinhHuy2010 Dec 21, 2024
3aabbc7
add typing to credentials.py
DinhHuy2010 Dec 21, 2024
9a1affc
add typing to errors.py
DinhHuy2010 Dec 21, 2024
735ba5a
fix pyproject again
DinhHuy2010 Dec 21, 2024
5fc3b70
add filter_* functions to _pygit2.pyi
DinhHuy2010 Dec 21, 2024
95b003f
add typing to utils.py
DinhHuy2010 Dec 21, 2024
e71d03b
fix ffi.py
DinhHuy2010 Dec 21, 2024
9b68da8
initial commit of pygit2 __init__
DinhHuy2010 Dec 21, 2024
7afd694
remove pygit2 star imports
DinhHuy2010 Dec 22, 2024
b2680c3
fix pyproject again
DinhHuy2010 Dec 22, 2024
4970a94
fix pyproject
DinhHuy2010 Dec 22, 2024
40f44c1
fix pyproject again
DinhHuy2010 Dec 22, 2024
e3ed43f
initial commit of pygit2 callbacks.py
DinhHuy2010 Dec 22, 2024
35fb5e1
typing fix for __init__.py
DinhHuy2010 Dec 22, 2024
c3b01f8
fix typing for _build.py and _run.py
DinhHuy2010 Dec 24, 2024
0fe1aac
fix pyproject.toml
DinhHuy2010 Dec 25, 2024
58b88c2
add typing for packbuilder.py
DinhHuy2010 Dec 25, 2024
d8755fb
fix typing for utils
DinhHuy2010 Dec 25, 2024
8114f2b
hotfix for packbuilder.py
DinhHuy2010 Dec 25, 2024
071df9d
fix _pygit2.pyi
DinhHuy2010 Dec 25, 2024
9a10a41
initial stub for repository.py
DinhHuy2010 Dec 25, 2024
5f2d9ae
add typing for branches.py
DinhHuy2010 Dec 29, 2024
720881e
add typing to blob.py and fix _pygit2.pyi
DinhHuy2010 Dec 30, 2024
0e55fb3
add typing for blame.py and add _ctyping
DinhHuy2010 Dec 30, 2024
6ab13f7
Resolve confilcts from 'upstream/master'
DinhHuy2010 Dec 30, 2024
5dca60a
change pathtype name to StrOrBytesPath
DinhHuy2010 Dec 30, 2024
599f2b7
fix _ctyping
DinhHuy2010 Dec 30, 2024
d3be17a
fix _ctyping again
DinhHuy2010 Dec 30, 2024
dddd720
add maybe_bytes
DinhHuy2010 Dec 30, 2024
f019420
add typing to config.py
DinhHuy2010 Jan 13, 2025
86c62cd
Merge branch 'master' of https://github.com/libgit2/pygit2 into typec…
DinhHuy2010 Jan 13, 2025
b0da06b
fix typing
DinhHuy2010 Jan 13, 2025
0fab374
Solve confilcts
DinhHuy2010 Feb 17, 2025
8b46dec
Merge branch 'master' into typecheck
DinhHuy2010 Feb 17, 2025
48e0dce
fix config
DinhHuy2010 Feb 17, 2025
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
Prev Previous commit
Next Next commit
Initial formatting and liniting fix of all files
  • Loading branch information
DinhHuy2010 committed Dec 21, 2024
commit 484886a335628d691bb971343e0699666f2b71b6
3 changes: 2 additions & 1 deletion build_tag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import platform, sys
import platform
import sys

py = {'CPython': 'cp', 'PyPy': 'pp'}[platform.python_implementation()]
print(f'{py}{sys.version_info.major}{sys.version_info.minor}')
26 changes: 16 additions & 10 deletions pygit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,31 @@

# Standard Library
import functools
from os import PathLike
import typing

# Low level API
from ._pygit2 import *
from ._pygit2 import _cache_enums
from os import PathLike

# High level API
from . import enums
from ._build import __version__

# Low level API
from ._pygit2 import *
from ._pygit2 import _cache_enums
from .blame import Blame, BlameHunk
from .blob import BlobIO
from .callbacks import Payload, RemoteCallbacks, CheckoutCallbacks, StashApplyCallbacks
from .callbacks import git_clone_options, git_fetch_options, get_credentials
from .callbacks import (
CheckoutCallbacks,
Payload,
RemoteCallbacks,
StashApplyCallbacks,
get_credentials,
git_clone_options,
git_fetch_options,
)
from .config import Config
from .credentials import *
from .errors import check_error, Passthrough
from .ffi import ffi, C
from .errors import Passthrough, check_error
from .ffi import C, ffi
from .filter import Filter
from .index import Index, IndexEntry
from .legacyenums import *
Expand All @@ -53,7 +60,6 @@
from .submodules import Submodule
from .utils import to_bytes, to_str


# Features
features = enums.Feature(C.git_libgit2_features())

Expand Down
3 changes: 2 additions & 1 deletion pygit2/_pygit2.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Iterator, Literal, Optional, overload
from io import IOBase
from typing import Iterator, Literal, Optional, overload

from . import Index
from .enums import (
ApplyLocation,
Expand Down
2 changes: 1 addition & 1 deletion pygit2/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

# Import from the Standard Library
import codecs
from pathlib import Path
import sys
from pathlib import Path

# Import from cffi
from cffi import FFI
Expand Down
4 changes: 2 additions & 2 deletions pygit2/blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
# Boston, MA 02110-1301, USA.

# Import from pygit2
from .ffi import ffi, C
from ._pygit2 import Oid, Signature
from .ffi import C, ffi
from .utils import GenericIterator
from ._pygit2 import Signature, Oid


def wrap_signature(csig):
Expand Down
2 changes: 1 addition & 1 deletion pygit2/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import threading
import time
from contextlib import AbstractContextManager
from typing import Optional
from queue import Queue
from typing import Optional

from ._pygit2 import Blob, Oid
from .enums import BlobFilter
Expand Down
3 changes: 2 additions & 1 deletion pygit2/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
# Boston, MA 02110-1301, USA.

from __future__ import annotations

from typing import TYPE_CHECKING

from .enums import BranchType, ReferenceType
from ._pygit2 import Commit, Oid
from .enums import BranchType, ReferenceType

# Need BaseRepository for type hints, but don't let it cause a circular dependency
if TYPE_CHECKING:
Expand Down
18 changes: 6 additions & 12 deletions pygit2/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@
from typing import Optional, Union

# pygit2
from ._pygit2 import Oid, DiffFile
from ._pygit2 import DiffFile, Oid
from .enums import CheckoutNotify, CheckoutStrategy, CredentialType, StashApplyProgress
from .errors import check_error, Passthrough
from .ffi import ffi, C
from .utils import maybe_string, to_bytes, ptr_to_bytes, StrArray

from .errors import Passthrough, check_error
from .ffi import C, ffi
from .utils import StrArray, maybe_string, ptr_to_bytes, to_bytes

#
# The payload is the way to pass information from the pygit2 API, through
Expand Down Expand Up @@ -471,9 +470,7 @@ def _certificate_check_cb(cert_i, valid, host, data):
if not val:
return C.GIT_ECERTIFICATE
except Passthrough:
if is_ssh:
return 0
elif valid:
if is_ssh or valid:
return 0
else:
return C.GIT_ECERTIFICATE
Expand Down Expand Up @@ -669,10 +666,7 @@ def _git_checkout_options(
paths=None,
c_checkout_options_ptr=None,
):
if callbacks is None:
payload = CheckoutCallbacks()
else:
payload = callbacks
payload = CheckoutCallbacks() if callbacks is None else callbacks

# Get handle to payload
handle = ffi.new_handle(payload)
Expand Down
8 changes: 4 additions & 4 deletions pygit2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
from cached_property import cached_property

# Import from pygit2
import contextlib

from .errors import check_error
from .ffi import ffi, C
from .ffi import C, ffi
from .utils import to_bytes


Expand Down Expand Up @@ -96,10 +98,8 @@ def from_c(cls, repo, ptr):
return config

def __del__(self):
try:
with contextlib.suppress(AttributeError):
C.git_config_free(self._config)
except AttributeError:
pass

def _get(self, key):
key = str_to_bytes(key, 'key')
Expand Down
3 changes: 1 addition & 2 deletions pygit2/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

from .ffi import C

from .enums import CredentialType
from .ffi import C


class Username:
Expand Down
7 changes: 3 additions & 4 deletions pygit2/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@
# Boston, MA 02110-1301, USA.

# Import from pygit2
from .ffi import ffi, C
from ._pygit2 import GitError
from .ffi import C, ffi


value_errors = set([C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS])
value_errors = {C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS}


def check_error(err, io=False):
if err >= 0:
return

# These are special error codes, they should never reach here
test = err != C.GIT_EUSER and err != C.GIT_PASSTHROUGH
test = err not in (C.GIT_EUSER, C.GIT_PASSTHROUGH)
assert test, f'Unexpected error code {err}'

# Error message
Expand Down
3 changes: 2 additions & 1 deletion pygit2/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
# Boston, MA 02110-1301, USA.

# Import from pygit2
from ._libgit2 import ffi, lib as C
from ._libgit2 import ffi
from ._libgit2 import lib as C
9 changes: 4 additions & 5 deletions pygit2/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
import weakref

# Import from pygit2
from ._pygit2 import Oid, Tree, Diff
from ._pygit2 import Diff, Oid, Tree
from .enums import DiffOption, FileMode
from .errors import check_error
from .ffi import ffi, C
from .utils import to_bytes, to_str
from .utils import GenericIterator, StrArray
from .ffi import C, ffi
from .utils import GenericIterator, StrArray, to_bytes, to_str


class Index:
Expand Down Expand Up @@ -367,7 +366,7 @@ def oid(self):
@property
def hex(self):
"""The id of the referenced object as a hex string"""
warnings.warn('Use str(entry.id)', DeprecationWarning)
warnings.warn('Use str(entry.id)', DeprecationWarning, stacklevel=2)
return str(self.id)

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion pygit2/packbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# Import from pygit2
from .errors import check_error
from .ffi import ffi, C
from .ffi import C, ffi
from .utils import to_bytes


Expand Down
1 change: 1 addition & 0 deletions pygit2/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# Boston, MA 02110-1301, USA.

from __future__ import annotations

from typing import TYPE_CHECKING

from .enums import ReferenceFilter
Expand Down
2 changes: 1 addition & 1 deletion pygit2/refspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Import from pygit2
from .errors import check_error
from .ffi import ffi, C
from .ffi import C, ffi
from .utils import to_bytes


Expand Down
13 changes: 6 additions & 7 deletions pygit2/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@
# Boston, MA 02110-1301, USA.

from __future__ import annotations

from typing import TYPE_CHECKING

from . import utils

# Import from pygit2
from ._pygit2 import Oid
from .callbacks import git_fetch_options, git_push_options, git_remote_callbacks
from .enums import FetchPrune
from .errors import check_error
from .ffi import ffi, C
from .ffi import C, ffi
from .refspec import Refspec
from . import utils
from .utils import maybe_string, to_bytes, strarray_to_strings, StrArray
from .utils import StrArray, maybe_string, strarray_to_strings, to_bytes

# Need BaseRepository for type hints, but don't let it cause a circular dependency
if TYPE_CHECKING:
Expand Down Expand Up @@ -185,10 +187,7 @@ def ls_remotes(self, callbacks=None, proxy=None):
for i in range(int(refs_len[0])):
ref = refs[0][i]
local = bool(ref.local)
if local:
loid = Oid(raw=bytes(ffi.buffer(ref.loid.id)[:]))
else:
loid = None
loid = Oid(raw=bytes(ffi.buffer(ref.loid.id)[:])) if local else None

remote = {
'local': local,
Expand Down
Loading