Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 5 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install coverage
pip install --editable .
- name: Run test
run: python -m unittest discover
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Run tests
run: uv run pytest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ dist
MANIFEST
bagit.egg-info
.idea
uv.lock
*.log
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ exclude: ".*test-data.*"

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.15.2
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-added-large-files
args: ["--maxkb=128"]
- id: check-ast
- id: check-byte-order-marker
- id: fix-byte-order-marker
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
Expand Down
7 changes: 0 additions & 7 deletions MANIFEST.in

This file was deleted.

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ COMPILED_MESSAGES=$(patsubst %.po,%.mo, $(wildcard locale/*/LC_MESSAGES/bagit-py
all: messages compile

clean:
rm -f locale/*/LC_MESSAGES/*.mo
rm -f src/bagit/locale/*/LC_MESSAGES/*.mo

messages:
xgettext --language=python -d bagit-python --no-location -o locale/bagit-python.pot bagit.py
xgettext --language=python -d bagit-python --no-location -o src/bagit/locale/bagit-python.pot src/bagit/__init__.py
# Until http://savannah.gnu.org/bugs/?20923 is fixed:
sed -i '' -e 's/CHARSET/UTF-8/g' locale/bagit-python.pot
msgmerge --no-fuzzy-matching --lang=en --output-file=locale/en/LC_MESSAGES/bagit-python.po locale/en/LC_MESSAGES/bagit-python.po locale/bagit-python.pot
sed -i '' -e 's/CHARSET/UTF-8/g' src/bagit/locale/bagit-python.pot
msgmerge --no-fuzzy-matching --lang=en --output-file=src/bagit/locale/en/LC_MESSAGES/bagit-python.po src/bagit/locale/en/LC_MESSAGES/bagit-python.po src/bagit/locale/bagit-python.pot

%.mo: %.po
msgfmt -o $@ $<
Expand Down
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,23 @@ Contributing to bagit-python development
% git clone git://github.com/LibraryOfCongress/bagit-python.git
% cd bagit-python
# MAKE CHANGES
% python test.py
% uv run pytest

Running the tests
~~~~~~~~~~~~~~~~~

You can quickly run the tests using the built-in unittest framework:
You can quickly run the tests using `uv <https://docs.astral.sh/uv/>`_.

::

python -m unittest discover
uv run pytest

If you have Docker installed, you can run the tests under Linux inside a
container:

::

% docker build -t bagit:latest . && docker run -it bagit:latest
docker build -t bagit:latest . && docker run -it bagit:latest

Benchmarks
----------
Expand All @@ -246,7 +246,7 @@ bench utility:

::

% ./bench.py
./utils/bench.py

License
-------
Expand Down
39 changes: 32 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[build-system]
requires = ["setuptools>=64", "setuptools-scm>=8"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "bagit"
dynamic = ["version"]
description = "Create and validate BagIt packages"
readme = {file = "README.rst", content-type = "text/x-rst"}
authors = [
{ name = "Ed Summers", email = "ehs@pobox.com" },
{ name = "Chris Adams", email = "chris@improbable.org" },
{ name = "Ed Summers", email = "ehs@pobox.com" }
]
classifiers = [
"Intended Audience :: Developers",
Expand All @@ -18,6 +19,10 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Filesystems",
]
requires-python = ">= 3.9"

[project.scripts]
"bagit" = "bagit:main"

[project.urls]
Homepage = "https://libraryofcongress.github.io/bagit-python/"
Expand All @@ -27,14 +32,34 @@ Homepage = "https://libraryofcongress.github.io/bagit-python/"
[tool.ruff]
target-version = "py38"


[tool.setuptools_scm]

[tool.isort]
line_length = 110
default_section = "THIRDPARTY"
known_first_party = "bagit"

[tool.pytest.ini_options]
testpaths = ["test.py"]
addopts = "-v"

[tool.coverage.run]
branch = true
include = "bagit.py"
include = "src"

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.targets.sdist]
packages = ["src/bagit"]
include = [
"src/bagit/*.py",
"src/bagit/locale/*.po",
"src/bagit/locale/*.mo",
]


[dependency-groups]
dev = [
"coverage>=7.8.2",
"pytest>=8.4.0",
"ruff>=0.11.12",
]
61 changes: 0 additions & 61 deletions setup.py

This file was deleted.

19 changes: 10 additions & 9 deletions bagit.py → src/bagit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ def make_bag(
break
except PermissionError as e:
if hasattr(e, "winerror") and e.winerror == 5:
LOGGER.warning(_("PermissionError [WinError 5] when renaming temp folder. Retrying in 10 seconds..."))
LOGGER.warning(
_(
"PermissionError [WinError 5] when renaming temp folder. Retrying in 10 seconds..."
)
)
time.sleep(10)
else:
raise
Expand All @@ -250,7 +254,7 @@ def make_bag(
)

LOGGER.info(_("Creating bagit.txt"))
txt = """BagIt-Version: 0.97\nTag-File-Character-Encoding: UTF-8\n"""
txt = """BagIt-Version: 1.0\nTag-File-Character-Encoding: UTF-8\n"""
with open_text_file("bagit.txt", "w") as bagit_file:
bagit_file.write(txt)

Expand Down Expand Up @@ -946,7 +950,7 @@ def _path_is_dangerous(self, path):
real_path = os.path.normpath(real_path)
bag_path = os.path.realpath(self.path)
bag_path = os.path.normpath(bag_path)
common = os.path.commonprefix((bag_path, real_path))
common = os.path.commonpath((bag_path, real_path))
return not (common == bag_path)


Expand Down Expand Up @@ -1124,12 +1128,12 @@ def _calc_hashes(args):
full_path = os.path.join(base_path, rel_path)

# Create a clone of the default empty hash objects:
f_hashers = dict((alg, hashlib.new(alg)) for alg in hashes if alg in algorithms)
f_hashers = {alg: hashlib.new(alg) for alg in hashes if alg in algorithms}

try:
f_hashes = _calculate_file_hashes(full_path, f_hashers)
except BagValidationError as e:
f_hashes = dict((alg, str(e)) for alg in f_hashers.keys())
f_hashes = {alg: str(e) for alg in f_hashers}

return rel_path, f_hashes, hashes

Expand Down Expand Up @@ -1489,10 +1493,7 @@ def _make_parser():

checksum_args = parser.add_argument_group(
_("Checksum Algorithms"),
_(
"Select the manifest algorithms to be used when creating bags"
" (default=%s)"
)
_("Select the manifest algorithms to be used when creating bags (default=%s)")
% ", ".join(DEFAULT_CHECKSUMS),
)

Expand Down
20 changes: 15 additions & 5 deletions locale/bagit-python.pot → src/bagit/locale/bagit-python.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-06-26 10:28-0400\n"
"POT-Creation-Date: 2025-06-05 12:14-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -226,20 +226,23 @@ msgid ""
"%(found_byte_count)d bytes"
msgstr ""

msgid "Bag validation failed"
msgid "Bag is incomplete"
msgstr ""

#, python-format
msgid "Unable to calculate file hashes for %s"
msgstr ""

msgid "Bag validation failed"
msgstr ""

msgid "bagit.txt must not contain a byte-order mark"
msgstr ""

#, python-format
msgid ""
"%(path)s %(algorithm)s validation failed: expected=\"%(expected)s\" found="
"\"%(found)s\""
"%(path)s %(algorithm)s validation failed: expected=\"%(expected)s\" "
"found=\"%(found)s\""
msgstr ""

#, python-format
Expand Down Expand Up @@ -345,16 +348,23 @@ msgstr ""
msgid "bagit-python version %s"
msgstr ""

msgid "The number of processes must be 0 or greater"
msgid "The number of processes must be greater than 0"
msgstr ""

msgid "--fast is only allowed as an option for --validate!"
msgstr ""

msgid "--completeness-only is only allowed as an option for --validate!"
msgstr ""

#, python-format
msgid "%s valid according to Payload-Oxum"
msgstr ""

#, python-format
msgid "%s is complete and valid according to Payload-Oxum"
msgstr ""

#, python-format
msgid "%s is valid"
msgstr ""
Expand Down
File renamed without changes.
Loading
Loading