Skip to content

Commit

Permalink
Finish removing Python 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
acdha committed Oct 15, 2024
1 parent c5c7b7d commit 255320b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
22 changes: 3 additions & 19 deletions bagit.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

import argparse
import codecs
import gettext
Expand Down Expand Up @@ -42,10 +40,8 @@ def find_locale_dir():
TRANSLATION_CATALOG = gettext.translation(
"bagit-python", localedir=find_locale_dir(), fallback=True
)
if sys.version_info < (3,):
_ = TRANSLATION_CATALOG.ugettext
else:
_ = TRANSLATION_CATALOG.gettext

_ = TRANSLATION_CATALOG.gettext

MODULE_NAME = "bagit" if __name__ == "__main__" else __name__

Expand Down Expand Up @@ -1039,22 +1035,10 @@ def posix_multiprocessing_worker_initializer():
# is consistency since the input value will be preserved:


def normalize_unicode_py3(s):
def normalize_unicode(s):
return unicodedata.normalize("NFC", s)


def normalize_unicode_py2(s):
if isinstance(s, str):
s = s.decode("utf-8")
return unicodedata.normalize("NFC", s)


if sys.version_info > (3, 0):
normalize_unicode = normalize_unicode_py3
else:
normalize_unicode = normalize_unicode_py2


def build_unicode_normalized_lookup_dict(filenames):
"""
Return a dictionary mapping unicode-normalized filenames to as-encoded
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Homepage = "https://libraryofcongress.github.io/bagit-python/"

[tool]

[tool.ruff]
target-version = "py38"


[tool.setuptools_scm]

[tool.isort]
Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

from setuptools import setup

if sys.version_info < (2, 7):
print("Python 2.7 or higher is required")
sys.exit(1)

description = "Create and validate BagIt packages"


Expand Down
4 changes: 1 addition & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ def test_validation_completeness_error_details(self):

def test_bom_in_bagit_txt(self):
bag = bagit.make_bag(self.tmpdir)
BOM = codecs.BOM_UTF8
if sys.version_info[0] >= 3:
BOM = BOM.decode("utf-8")
BOM = codecs.BOM_UTF8.decode("utf-8")
with open(j(self.tmpdir, "bagit.txt"), "r") as bf:
bagfile = BOM + bf.read()
with open(j(self.tmpdir, "bagit.txt"), "w") as bf:
Expand Down

0 comments on commit 255320b

Please sign in to comment.