Skip to content

Commit 9ba473a

Browse files
committed
Use pyproject and remove setup.py
This commit includes changes to remove the use of setup.py and setuptools in favor of using the existing pyrproject.toml and hatch. A source layout was chosen, which required several changes such as: - pushing bagit.py into src/bagit/ - pushing locale into src/bagit/locale The gettext related code in setup.py was relocated to utils/locales.py It's possible the way that the gettext functionality is setup needs to adjustment, as I'm new to using it. Also we now rely on running tests with uv and pytest, which happens in the test github action. We could chose to update the PyPI publishing step to use uv build/publish too?
1 parent da04180 commit 9ba473a

File tree

14 files changed

+106
-108
lines changed

14 files changed

+106
-108
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
23+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
2424
steps:
2525
- uses: actions/checkout@v4
2626
- name: Set up Python ${{ matrix.python-version }}
2727
uses: actions/setup-python@v5
2828
with:
2929
python-version: ${{ matrix.python-version }}
30-
- name: Install dependencies
31-
run: |
32-
python -m pip install --upgrade pip setuptools wheel
33-
pip install coverage
34-
pip install --editable .
35-
- name: Run test
36-
run: python -m unittest discover
30+
- name: Install uv
31+
uses: astral-sh/setup-uv@v5
32+
- name: Run tests
33+
run: uv run pytest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ dist
55
MANIFEST
66
bagit.egg-info
77
.idea
8+
uv.lock
9+
*.log

MANIFEST.in

Lines changed: 0 additions & 7 deletions
This file was deleted.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ COMPILED_MESSAGES=$(patsubst %.po,%.mo, $(wildcard locale/*/LC_MESSAGES/bagit-py
33
all: messages compile
44

55
clean:
6-
rm -f locale/*/LC_MESSAGES/*.mo
6+
rm -f src/bagit/locale/*/LC_MESSAGES/*.mo
77

88
messages:
9-
xgettext --language=python -d bagit-python --no-location -o locale/bagit-python.pot bagit.py
9+
xgettext --language=python -d bagit-python --no-location -o src/bagit/locale/bagit-python.pot src/bagit/__init__.py
1010
# Until http://savannah.gnu.org/bugs/?20923 is fixed:
11-
sed -i '' -e 's/CHARSET/UTF-8/g' locale/bagit-python.pot
12-
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
11+
sed -i '' -e 's/CHARSET/UTF-8/g' src/bagit/locale/bagit-python.pot
12+
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
1313

1414
%.mo: %.po
1515
msgfmt -o $@ $<

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,23 @@ Contributing to bagit-python development
219219
% git clone git://github.com/LibraryOfCongress/bagit-python.git
220220
% cd bagit-python
221221
# MAKE CHANGES
222-
% python test.py
222+
% uv run pytest
223223

224224
Running the tests
225225
~~~~~~~~~~~~~~~~~
226226

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

229229
::
230230

231-
python -m unittest discover
231+
uv run pytest
232232

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

236236
::
237237

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

240240
Benchmarks
241241
----------
@@ -246,7 +246,7 @@ bench utility:
246246

247247
::
248248

249-
% ./bench.py
249+
./utils/bench.py
250250

251251
License
252252
-------

pyproject.toml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[build-system]
2-
requires = ["setuptools>=64", "setuptools-scm>=8"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["hatchling", "hatch-vcs"]
3+
build-backend = "hatchling.build"
44

55
[project]
66
name = "bagit"
77
dynamic = ["version"]
88
description = "Create and validate BagIt packages"
99
readme = {file = "README.rst", content-type = "text/x-rst"}
1010
authors = [
11-
{ name = "Ed Summers", email = "[email protected]" },
11+
{ name = "Chris Adams", email = "[email protected]" },
12+
{ name = "Ed Summers", email = "[email protected]" }
1213
]
1314
classifiers = [
1415
"Intended Audience :: Developers",
@@ -18,6 +19,10 @@ classifiers = [
1819
"Topic :: Software Development :: Libraries :: Python Modules",
1920
"Topic :: System :: Filesystems",
2021
]
22+
requires-python = ">= 3.9"
23+
24+
[project.scripts]
25+
"bagit" = "bagit:main"
2126

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

30-
31-
[tool.setuptools_scm]
32-
3335
[tool.isort]
3436
line_length = 110
3537
default_section = "THIRDPARTY"
3638
known_first_party = "bagit"
3739

40+
[tool.pytest.ini_options]
41+
testpaths = ["test.py"]
42+
addopts = "-v"
43+
3844
[tool.coverage.run]
3945
branch = true
40-
include = "bagit.py"
46+
include = "src"
47+
48+
[tool.hatch.version]
49+
source = "vcs"
50+
51+
[tool.hatch.build.targets.sdist]
52+
packages = ["src/bagit"]
53+
include = [
54+
"src/bagit/*.py",
55+
"src/bagit/locale/*.po",
56+
"src/bagit/locale/*.mo",
57+
]
58+
59+
60+
[dependency-groups]
61+
dev = [
62+
"coverage>=7.8.2",
63+
"pytest>=8.4.0",
64+
"ruff>=0.11.12",
65+
]

setup.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

bagit.py renamed to src/bagit/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def make_bag(
240240
)
241241

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

@@ -1481,10 +1481,7 @@ def _make_parser():
14811481

14821482
checksum_args = parser.add_argument_group(
14831483
_("Checksum Algorithms"),
1484-
_(
1485-
"Select the manifest algorithms to be used when creating bags"
1486-
" (default=%s)"
1487-
)
1484+
_("Select the manifest algorithms to be used when creating bags (default=%s)")
14881485
% ", ".join(DEFAULT_CHECKSUMS),
14891486
)
14901487

locale/bagit-python.pot renamed to src/bagit/locale/bagit-python.pot

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2018-06-26 10:28-0400\n"
11+
"POT-Creation-Date: 2025-06-05 12:14-0400\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -226,20 +226,23 @@ msgid ""
226226
"%(found_byte_count)d bytes"
227227
msgstr ""
228228

229-
msgid "Bag validation failed"
229+
msgid "Bag is incomplete"
230230
msgstr ""
231231

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

236+
msgid "Bag validation failed"
237+
msgstr ""
238+
236239
msgid "bagit.txt must not contain a byte-order mark"
237240
msgstr ""
238241

239242
#, python-format
240243
msgid ""
241-
"%(path)s %(algorithm)s validation failed: expected=\"%(expected)s\" found="
242-
"\"%(found)s\""
244+
"%(path)s %(algorithm)s validation failed: expected=\"%(expected)s\" "
245+
"found=\"%(found)s\""
243246
msgstr ""
244247

245248
#, python-format
@@ -345,16 +348,23 @@ msgstr ""
345348
msgid "bagit-python version %s"
346349
msgstr ""
347350

348-
msgid "The number of processes must be 0 or greater"
351+
msgid "The number of processes must be greater than 0"
349352
msgstr ""
350353

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

357+
msgid "--completeness-only is only allowed as an option for --validate!"
358+
msgstr ""
359+
354360
#, python-format
355361
msgid "%s valid according to Payload-Oxum"
356362
msgstr ""
357363

364+
#, python-format
365+
msgid "%s is complete and valid according to Payload-Oxum"
366+
msgstr ""
367+
358368
#, python-format
359369
msgid "%s is valid"
360370
msgstr ""
File renamed without changes.

locale/en/LC_MESSAGES/bagit-python.po renamed to src/bagit/locale/en/LC_MESSAGES/bagit-python.po

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PACKAGE VERSION\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2018-06-26 10:28-0400\n"
10+
"POT-Creation-Date: 2025-06-05 12:14-0400\n"
1111
"PO-Revision-Date: 2017-04-27 15:02-0400\n"
1212
"Last-Translator: Automatically generated\n"
1313
"Language-Team: none\n"
@@ -233,20 +233,23 @@ msgid ""
233233
"%(found_byte_count)d bytes"
234234
msgstr ""
235235

236-
msgid "Bag validation failed"
236+
msgid "Bag is incomplete"
237237
msgstr ""
238238

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

243+
msgid "Bag validation failed"
244+
msgstr ""
245+
243246
msgid "bagit.txt must not contain a byte-order mark"
244247
msgstr ""
245248

246249
#, python-format
247250
msgid ""
248-
"%(path)s %(algorithm)s validation failed: expected=\"%(expected)s\" found="
249-
"\"%(found)s\""
251+
"%(path)s %(algorithm)s validation failed: expected=\"%(expected)s\" "
252+
"found=\"%(found)s\""
250253
msgstr ""
251254

252255
#, python-format
@@ -352,16 +355,23 @@ msgstr ""
352355
msgid "bagit-python version %s"
353356
msgstr ""
354357

355-
msgid "The number of processes must be 0 or greater"
358+
msgid "The number of processes must be greater than 0"
356359
msgstr ""
357360

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

364+
msgid "--completeness-only is only allowed as an option for --validate!"
365+
msgstr ""
366+
361367
#, python-format
362368
msgid "%s valid according to Payload-Oxum"
363369
msgstr "%s valid according to Payload-Oxum"
364370

371+
#, python-format
372+
msgid "%s is complete and valid according to Payload-Oxum"
373+
msgstr ""
374+
365375
#, python-format
366376
msgid "%s is valid"
367377
msgstr "%s is valid"

test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def test_make_bag(self):
523523
tagmanifest_txt = slurp_text_file(
524524
j(self.tmpdir, "tagmanifest-md5.txt")
525525
).splitlines()
526-
self.assertIn("9e5ad981e0d29adc278f6a294b8c2aca bagit.txt", tagmanifest_txt)
526+
self.assertIn("eaa2c609ff6371712f623f5531945b44 bagit.txt", tagmanifest_txt)
527527
self.assertIn(
528528
"a0ce6631a2a6d1a88e6d38453ccc72a5 manifest-md5.txt", tagmanifest_txt
529529
)

bench.py renamed to utils/bench.py

File renamed without changes.

0 commit comments

Comments
 (0)