From a54d7a8b9ce6a48db5383e09711059b5025bcb18 Mon Sep 17 00:00:00 2001 From: fap <459631+fapdash@users.noreply.github.com> Date: Sat, 14 Feb 2026 13:46:56 +0100 Subject: [PATCH 1/2] Fix: pkg_resources is deprecated Moved code to use importlib.resources, which is available in Python >=3.9 Fixes #41 --- .github/workflows/pytest.yml | 2 +- gitprivacy/gitprivacy.py | 12 ++++++------ setup.py | 9 +++++---- tests/test_gitprivacy.py | 6 ++++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index c61dccf..063db77 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] + python-version: [3.9, "3.10", 3.11, 3.12, 3.13, 3.14] steps: - uses: actions/checkout@v2 diff --git a/gitprivacy/gitprivacy.py b/gitprivacy/gitprivacy.py index 95201fd..28d6e9a 100755 --- a/gitprivacy/gitprivacy.py +++ b/gitprivacy/gitprivacy.py @@ -5,12 +5,12 @@ import click import git # type: ignore import os +import importlib.resources import shutil import stat import sys from datetime import datetime, timezone -from pkg_resources import resource_stream, resource_string from typing import Optional, TextIO, Tuple @@ -178,15 +178,16 @@ def get_template_dir(repo: git.Repo) -> str: return templatedir -def copy_hook(git_path: str, hook: str, ) -> None: +def copy_hook(git_path: str, hook: str) -> None: hookdir = os.path.join(git_path, "hooks") if not os.path.exists(hookdir): os.mkdir(hookdir) hook_fn = os.path.join(hookdir, hook) + hook_res = importlib.resources.files('gitprivacy.resources.hooks') / hook try: dst = open(hook_fn, "xb") except FileExistsError: - hook_txt = resource_string('gitprivacy.resources.hooks', hook).decode() + hook_txt = hook_res.read_text(encoding='utf-8') with open(hook_fn, "r") as f: if f.read() == hook_txt: print(f"{hook} hook is already installed at {hook_fn}.") @@ -196,13 +197,12 @@ def copy_hook(git_path: str, hook: str, ) -> None: f"hook:\n\n{hook_txt}") return else: - with resource_stream('gitprivacy.resources.hooks', hook) as src, dst: - shutil.copyfileobj(src, dst) # type: ignore + with hook_res.open('rb') as src, dst: + shutil.copyfileobj(src, dst) os.chmod(hook_fn, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) # mode 755 print("Installed {} hook".format(hook)) - @cli.command('log') @click.option('-r', '--revision-range', required=False, default='HEAD', help="Show only commits in the specified revision range.") diff --git a/setup.py b/setup.py index f119ee9..ded907d 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ license="BSD", packages=find_packages(exclude=('tests', 'docs')), include_package_data=True, - python_requires='>=3.6', + python_requires='>=3.9', install_requires=[ 'click>=7', 'gitpython', @@ -33,11 +33,12 @@ "Topic :: Software Development :: Version Control :: Git", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", ], diff --git a/tests/test_gitprivacy.py b/tests/test_gitprivacy.py index 19cdcbc..bfc2d62 100644 --- a/tests/test_gitprivacy.py +++ b/tests/test_gitprivacy.py @@ -586,8 +586,10 @@ def test_commitdateupdate(self): def load_exported_commit(self, path): - from pkg_resources import resource_stream - with resource_stream('tests', path) as input_fd: + from importlib.resources import files + + resource_path = files('tests') / path + with resource_path.open('rb') as input_fd: res, stdout, stderr = self.git.fast_import( "--force", # discard existing commits istream=input_fd, From bede5f982dfa2da2e774ba712462f9f6a9f57738 Mon Sep 17 00:00:00 2001 From: fap <459631+fapdash@users.noreply.github.com> Date: Tue, 17 Feb 2026 13:35:10 +0100 Subject: [PATCH 2/2] Update README.md with new Python version requirement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5935756..27a805e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ might need them. $ pip3 install gitprivacy -_Note: `git-privacy` requires Python version 3.6 or later and Git version 2.22.0 or later._ +_Note: `git-privacy` requires Python version 3.9 or later and Git version 2.22.0 or later._ ## Getting Started