Skip to content

Commit

Permalink
Remove individual enum classes from root namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed Dec 29, 2023
1 parent 468ffbb commit 611a3b3
Show file tree
Hide file tree
Showing 33 changed files with 89 additions and 106 deletions.
47 changes: 5 additions & 42 deletions pygit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,14 @@
from ._pygit2 import *

# High level API
from . import enums
from ._build import __version__
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 .config import Config
from .credentials import *
from .enums import (
AttrCheck,
ApplyLocation,
BlameFlag,
BlobFilter,
BranchType,
CheckoutNotify,
CheckoutStrategy,
ConfigLevel,
CredentialType,
DeltaStatus,
DescribeStrategy,
DiffFlag,
DiffOption,
DiffStatsFormat,
Feature,
FetchPrune,
FileMode,
FilterFlag,
FilterMode,
ObjectType,
Option,
MergeAnalysis,
MergePreference,
ReferenceFilter,
ReferenceType,
RepositoryInitFlag,
RepositoryInitMode,
RepositoryOpenFlag,
RepositoryState,
ResetMode,
RevSpecFlag,
StashApplyProgress,
FileStatus,
SubmoduleIgnore,
SubmoduleStatus,
SortMode,
)
from .errors import check_error, Passthrough
from .ffi import ffi, C
from .filter import Filter
Expand All @@ -91,7 +54,7 @@


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

# libgit version tuple
LIBGIT2_VER = (LIBGIT2_VER_MAJOR, LIBGIT2_VER_MINOR, LIBGIT2_VER_REVISION)
Expand All @@ -100,8 +63,8 @@
def init_repository(
path: typing.Union[str, bytes, PathLike, None],
bare: bool = False,
flags: RepositoryInitFlag = RepositoryInitFlag.MKPATH,
mode: typing.Union[int, RepositoryInitMode] = RepositoryInitMode.SHARED_UMASK,
flags: enums.RepositoryInitFlag = enums.RepositoryInitFlag.MKPATH,
mode: typing.Union[int, enums.RepositoryInitMode] = enums.RepositoryInitMode.SHARED_UMASK,
workdir_path: typing.Optional[str] = None,
description: typing.Optional[str] = None,
template_path: typing.Optional[str] = None,
Expand Down Expand Up @@ -136,7 +99,7 @@ def init_repository(
raise TypeError('Expected string type for path, found None.')

if bare:
flags |= RepositoryInitFlag.BARE
flags |= enums.RepositoryInitFlag.BARE

# Options
options = ffi.new('git_repository_init_options *')
Expand Down
8 changes: 4 additions & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
def global_git_config():
# Do not use global config for better test reproducibility.
# https://github.com/libgit2/pygit2/issues/989
levels = [pygit2.ConfigLevel.GLOBAL,
pygit2.ConfigLevel.XDG,
pygit2.ConfigLevel.SYSTEM]
levels = [pygit2.enums.ConfigLevel.GLOBAL,
pygit2.enums.ConfigLevel.XDG,
pygit2.enums.ConfigLevel.SYSTEM]
for level in levels:
pygit2.settings.search_path[level] = ""

# Fix tests running in AppVeyor
if platform.system() == 'Windows':
pygit2.option(pygit2.Option.SET_OWNER_VALIDATION, 0)
pygit2.option(pygit2.enums.Option.SET_OWNER_VALIDATION, 0)


@pytest.fixture
Expand Down
6 changes: 2 additions & 4 deletions test/test_apply_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
# Boston, MA 02110-1301, USA.

import pygit2
from pygit2.enums import ApplyLocation, CheckoutStrategy, FileStatus
import pytest

import os
from pathlib import Path

from pygit2 import ApplyLocation
from pygit2 import FileStatus


def read_content(testrepo):
with (Path(testrepo.workdir) / 'hello.txt').open('rb') as f:
Expand All @@ -57,7 +55,7 @@ def patch_diff(testrepo, new_content):
patch = testrepo.diff().patch

# Rollback all changes
testrepo.checkout('HEAD', strategy=pygit2.CheckoutStrategy.FORCE)
testrepo.checkout('HEAD', strategy=CheckoutStrategy.FORCE)

# Return the diff
return pygit2.Diff.parse_diff(patch)
Expand Down
3 changes: 2 additions & 1 deletion test/test_blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

import pytest

from pygit2 import Signature, Oid, BlameFlag
from pygit2 import Signature, Oid
from pygit2.enums import BlameFlag


PATH = 'hello.txt'
Expand Down
2 changes: 1 addition & 1 deletion test/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import pytest

import pygit2
from pygit2 import ObjectType
from pygit2.enums import ObjectType
from . import utils


Expand Down
2 changes: 1 addition & 1 deletion test/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import pygit2
import pytest
import os
from pygit2 import BranchType
from pygit2.enums import BranchType


LAST_COMMIT = '2be5719152d4f82c7302b1c0932d8e5f0a4a0e98'
Expand Down
2 changes: 1 addition & 1 deletion test/test_branch_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import pygit2
import pytest
from pygit2 import BranchType
from pygit2.enums import BranchType


ORIGIN_MASTER_COMMIT = '784855caf26449a1914d2cf62d12b9374d76ae78'
Expand Down
9 changes: 5 additions & 4 deletions test/test_cherrypick.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
"""Tests for merging and information about it."""

from pathlib import Path
import pytest

import pygit2
import pytest
from pygit2.enums import RepositoryState


def test_cherrypick_none(mergerepo):
Expand All @@ -48,10 +49,10 @@ def test_cherrypick_already_something_in_index(mergerepo):


def test_cherrypick_remove_conflicts(mergerepo):
assert mergerepo.state() == pygit2.RepositoryState.NONE
assert mergerepo.state() == RepositoryState.NONE
other_branch_tip = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
mergerepo.cherrypick(other_branch_tip)
assert mergerepo.state() == pygit2.RepositoryState.CHERRYPICK
assert mergerepo.state() == RepositoryState.CHERRYPICK
idx = mergerepo.index
conflicts = idx.conflicts
assert conflicts is not None
Expand All @@ -60,4 +61,4 @@ def test_cherrypick_remove_conflicts(mergerepo):
with pytest.raises(KeyError): conflicts.__getitem__('.gitignore')
assert idx.conflicts is None
mergerepo.state_cleanup()
assert mergerepo.state() == pygit2.RepositoryState.NONE
assert mergerepo.state() == RepositoryState.NONE
3 changes: 2 additions & 1 deletion test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

import pytest

from pygit2 import Signature, Oid, GitError, ObjectType
from pygit2 import Signature, Oid, GitError
from pygit2.enums import ObjectType
from . import utils


Expand Down
3 changes: 2 additions & 1 deletion test/test_commit_gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

from pygit2 import ObjectType, Oid, Signature
from pygit2 import Oid, Signature
from pygit2.enums import ObjectType

content = """\
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
Expand Down
3 changes: 2 additions & 1 deletion test/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import pytest

import pygit2
from pygit2 import CredentialType, Username, UserPass, Keypair, KeypairFromAgent, KeypairFromMemory
from pygit2 import Username, UserPass, Keypair, KeypairFromAgent, KeypairFromMemory
from pygit2.enums import CredentialType
from . import utils


Expand Down
4 changes: 2 additions & 2 deletions test/test_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

import pytest

from pygit2 import DescribeStrategy
from pygit2.enums import DescribeStrategy, ObjectType
import pygit2


def add_tag(repo, name, target):
message = 'Example tag.\n'
tagger = pygit2.Signature('John Doe', '[email protected]', 12347, 0)

sha = repo.create_tag(name, target, pygit2.ObjectType.COMMIT, tagger, message)
sha = repo.create_tag(name, target, ObjectType.COMMIT, tagger, message)
return sha


Expand Down
2 changes: 1 addition & 1 deletion test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import pytest

import pygit2
from pygit2 import DeltaStatus, DiffOption, DiffStatsFormat
from pygit2.enums import DeltaStatus, DiffOption, DiffStatsFormat


COMMIT_SHA1_1 = '5fe808e8953c12735680c257f56600cb0de44b10'
Expand Down
8 changes: 5 additions & 3 deletions test/test_diff_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

import pygit2
import pytest

import pygit2
from pygit2.enums import DiffOption

from . import utils


Expand Down Expand Up @@ -54,9 +56,9 @@ def repo(tmp_path):
def test_binary_diff(repo):
diff = repo.diff('HEAD', 'HEAD^')
assert PATCH_BINARY == diff.patch
diff = repo.diff('HEAD', 'HEAD^', flags=pygit2.DiffOption.SHOW_BINARY)
diff = repo.diff('HEAD', 'HEAD^', flags=DiffOption.SHOW_BINARY)
assert PATCH_BINARY_SHOW == diff.patch
diff = repo.diff(b'HEAD', b'HEAD^')
assert PATCH_BINARY == diff.patch
diff = repo.diff(b'HEAD', b'HEAD^', flags=pygit2.DiffOption.SHOW_BINARY)
diff = repo.diff(b'HEAD', b'HEAD^', flags=DiffOption.SHOW_BINARY)
assert PATCH_BINARY_SHOW == diff.patch
2 changes: 1 addition & 1 deletion test/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

import pygit2
from pygit2 import BlobFilter
from pygit2.enums import BlobFilter
from pygit2.errors import Passthrough


Expand Down
4 changes: 2 additions & 2 deletions test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import pygit2
from pygit2 import Repository, Index, Oid
from pygit2 import FileMode
from pygit2.enums import FileMode
from . import utils


Expand Down Expand Up @@ -214,7 +214,7 @@ def test_change_attributes(testrepo):
assert FileMode.BLOB_EXECUTABLE == entry.mode

def test_write_tree_to(testrepo, tmp_path):
pygit2.option(pygit2.Option.ENABLE_STRICT_OBJECT_CREATION, False)
pygit2.option(pygit2.enums.Option.ENABLE_STRICT_OBJECT_CREATION, False)
with utils.TemporaryRepository('emptyrepo.zip', tmp_path) as path:
nrepo = Repository(path)
id = testrepo.index.write_tree(nrepo)
Expand Down
3 changes: 1 addition & 2 deletions test/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

import pytest

from pygit2 import MergeAnalysis
from pygit2 import FileStatus
import pygit2
from pygit2.enums import FileStatus, MergeAnalysis


@pytest.mark.parametrize("id", [None, 42])
Expand Down
3 changes: 2 additions & 1 deletion test/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

import pytest

from pygit2 import ObjectType, Tree, Tag
from pygit2 import Tree, Tag
from pygit2.enums import ObjectType


BLOB_SHA = 'a520c24d85fbfc815d385957eed41406ca5a860b'
Expand Down
2 changes: 1 addition & 1 deletion test/test_odb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# pygit2
from pygit2 import Odb, Oid
from pygit2 import ObjectType
from pygit2.enums import ObjectType
from . import utils


Expand Down
5 changes: 3 additions & 2 deletions test/test_odb_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

# pygit2
import pygit2
from pygit2.enums import ObjectType
from . import utils


Expand Down Expand Up @@ -113,12 +114,12 @@ def test_read(proxy):
ab = proxy.read(BLOB_OID)
a = proxy.read(BLOB_HEX)
assert ab == a
assert (pygit2.ObjectType.BLOB, b'a contents\n') == a
assert (ObjectType.BLOB, b'a contents\n') == a

def test_read_prefix(proxy):
a_hex_prefix = BLOB_HEX[:4]
a3 = proxy.read_prefix(a_hex_prefix)
assert (pygit2.ObjectType.BLOB, b'a contents\n', BLOB_OID) == a3
assert (ObjectType.BLOB, b'a contents\n', BLOB_OID) == a3

def test_exists(proxy):
with pytest.raises(TypeError):
Expand Down
5 changes: 3 additions & 2 deletions test/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
# Boston, MA 02110-1301, USA.

import pygit2
from pygit2 import option, ConfigLevel, ObjectType, Option
from pygit2 import option
from pygit2.enums import ConfigLevel, ObjectType, Option


def __option(getter, setter, value):
Expand Down Expand Up @@ -61,7 +62,7 @@ def test_mwindow_mapped_limit_300():

def test_cache_object_limit():
new_limit = 2 * 1024
option(Option.SET_CACHE_OBJECT_LIMIT, GIT_OBJ_BLOB, new_limit)
option(Option.SET_CACHE_OBJECT_LIMIT, ObjectType.BLOB, new_limit)

def test_cache_object_limit_proxy():
new_limit = 4 * 1024
Expand Down
5 changes: 2 additions & 3 deletions test/test_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@

import pytest

from pygit2 import ReferenceType
from pygit2 import Signature
from pygit2 import Commit, Tree, reference_is_valid_name
from pygit2 import Commit, Signature, Tree, reference_is_valid_name
from pygit2 import AlreadyExistsError, GitError, InvalidSpecError
from pygit2.enums import ReferenceType


LAST_COMMIT = '2be5719152d4f82c7302b1c0932d8e5f0a4a0e98'
Expand Down
Loading

0 comments on commit 611a3b3

Please sign in to comment.