Skip to content

Commit

Permalink
Drop compatibility with pygit < 1.4
Browse files Browse the repository at this point in the history
Currently, rpmautospec is available on current Fedora versions as well
as RHEL/CS >= 9, these all have a newer version. The plan for the future
is to make it available on RHEL/CS 8, too, on top of the Python 3.11
stack, which will need a backport of a current pygit2 version as the one
available (0.26) is much too old.

Signed-off-by: Nils Philippsen <nils@redhat.com>
  • Loading branch information
nphilipp committed Jan 26, 2024
1 parent c4086b9 commit 4cc8285
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -44,7 +44,7 @@ exclude = [
python = "^3.9"
rpmautospec_core = "^0.1.4"
babel = "^2.9"
pygit2 = "^1.2.1"
pygit2 = "^1.4.0"
rpm = "*"

[tool.poetry.group.dev.dependencies]
Expand Down
33 changes: 15 additions & 18 deletions rpmautospec/pkg_history.py
Expand Up @@ -52,12 +52,7 @@ def __init__(self, spec_or_path: Union[str, Path]):
raise FileNotFoundError(f"Spec file '{self.specfile}' doesn't exist in '{self.path}'.")

try:
if hasattr(pygit2, "GIT_REPOSITORY_OPEN_NO_SEARCH"):
kwargs = {"flags": pygit2.GIT_REPOSITORY_OPEN_NO_SEARCH}
else:
# pygit2 < 1.4.0
kwargs = {}
self.repo = pygit2.Repository(self.path, **kwargs)
self.repo = pygit2.Repository(self.path, flags=pygit2.GIT_REPOSITORY_OPEN_NO_SEARCH)
except pygit2.GitError:
self.repo = None

Expand Down Expand Up @@ -258,16 +253,18 @@ def release_number_visitor(self, commit: pygit2.Commit, child_info: dict[str, An
# Find the maximum applicable parent release number and increment by one if the
# epoch-version can be parsed from the spec file.
parent_release_numbers = tuple(
res["release-number"]
if res
and (
# Paper over gaps in epoch-versions, these could be simple syntax errors in
# the spec file, or a retired, then unretired package.
epoch_version is None
or res["epoch-version"] is None
or epoch_version == res["epoch-version"]
(
res["release-number"]
if res
and (
# Paper over gaps in epoch-versions, these could be simple syntax errors in
# the spec file, or a retired, then unretired package.
epoch_version is None
or res["epoch-version"] is None
or epoch_version == res["epoch-version"]
)
else 0
)
else 0
for res in parent_results
)
release_number = max(parent_release_numbers, default=0)
Expand Down Expand Up @@ -724,9 +721,9 @@ def run(
if base is None:
base = 1
release_number_with_base = release_number + base - 1
worktree_result[
"release-complete"
] = release_complete = f"{prerel_str}{release_number_with_base}{tag_string}"
worktree_result["release-complete"] = release_complete = (
f"{prerel_str}{release_number_with_base}{tag_string}"
)

# Mimic the bottom half of the changelog visitor for a generic entry
if not self.specfile.exists():
Expand Down
7 changes: 1 addition & 6 deletions rpmautospec/subcommands/convert.py
Expand Up @@ -45,12 +45,7 @@ def __init__(self, spec_or_path: Path):
log.debug("Working on spec file %s", self.specfile)

try:
if hasattr(pygit2, "GIT_REPOSITORY_OPEN_NO_SEARCH"):
kwargs = {"flags": pygit2.GIT_REPOSITORY_OPEN_NO_SEARCH}
else:
# pygit2 < 1.4.0
kwargs = {}
self.repo = pygit2.Repository(self.path, **kwargs)
self.repo = pygit2.Repository(self.path, flags=pygit2.GIT_REPOSITORY_OPEN_NO_SEARCH)
log.debug("Found repository at %s", self.path)
except pygit2.GitError:
self.repo = None
Expand Down
6 changes: 1 addition & 5 deletions tests/conftest.py
Expand Up @@ -59,11 +59,7 @@ def specfile(repopath, release, changelog):
@pytest.fixture
def repo(repopath, specfile):
pygit2.init_repository(repopath, initial_head="rawhide")
if hasattr(pygit2, "GIT_REPOSITORY_OPEN_NO_SEARCH"):
repo = pygit2.Repository(repopath, pygit2.GIT_REPOSITORY_OPEN_NO_SEARCH)
else:
# pygit2 < 1.4.0
repo = pygit2.Repository(repopath)
repo = pygit2.Repository(repopath, pygit2.GIT_REPOSITORY_OPEN_NO_SEARCH)

repo.config["user.name"] = "Jane Doe"
repo.config["user.email"] = "jane.doe@example.com"
Expand Down

0 comments on commit 4cc8285

Please sign in to comment.