Skip to content

Commit

Permalink
Drop Python 2.7 support
Browse files Browse the repository at this point in the history
* Remove py27 toxenv
* Remove 2.7 classifier and bump version
* Upgrade dependencies
* Update debian dependencies
* Add upgrade tools to pre-commit configuration
* Run pre-commit
  • Loading branch information
replaceafill authored Jun 20, 2023
1 parent db39224 commit 4786aa1
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 58 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
strategy:
matrix:
include:
- python-version: "2.7"
toxenv: "py27"
- python-version: "3.6"
toxenv: "py36"
- python-version: "3.7"
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args: [--py3-plus, --py36-plus]
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.6.0
hooks:
- id: reorder-python-imports
args: [--py3-plus, --py36-plus]
- repo: https://github.com/ambv/black
rev: 22.8.0
hooks:
Expand Down
7 changes: 3 additions & 4 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ Section: utils
Priority: extra
Maintainer: Artefactual Systems Inc. <[email protected]>
Build-Depends:
python (>= 2.7.3),
debhelper (>= 9),
python-dev,
python3.6-dev,
ruby-ronn,
dh-virtualenv
Standards-Version: 3.9.3
X-Python-Version: 2.7
X-Python-Version: 3.6

Package: fixity
Architecture: i386 amd64
Depends: python (>= 2.7.3), ${python:Depends}, ${misc:Depends}, sqlite3
Depends: python3, ${python3:Depends}, ${misc:Depends}, sqlite3
Description: Commandline tool to check fixity of AIPs stored in
an Archivematica Storage Service installation.
Homepage: http://archivematica.org
26 changes: 12 additions & 14 deletions fixity/fixity.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import print_function
from argparse import ArgumentParser
from datetime import datetime
import json
import os
import sys
from uuid import uuid4
from time import sleep
import traceback
from argparse import ArgumentParser
from datetime import datetime
from time import sleep
from uuid import uuid4

from .models import Report, Session
from . import reporting
from . import storage_service
from .models import Report
from .models import Session


class ArgumentError(Exception):
Expand Down Expand Up @@ -50,7 +50,7 @@ def _get_environment_variable(var):
try:
return os.environ[var]
except KeyError as e:
raise ArgumentError("Missing environment variable: {}".format(e.args[0]))
raise ArgumentError(f"Missing environment variable: {e.args[0]}")


def fetch_environment_variables(namespace):
Expand Down Expand Up @@ -83,9 +83,9 @@ def scan_message(aip_uuid, status, message):
succeeded = "didn't run"
else:
succeeded = "returned an unknown status"
output = "Fixity scan {} for AIP: {}".format(succeeded, aip_uuid)
output = f"Fixity scan {succeeded} for AIP: {aip_uuid}"
if message:
output += " ({})".format(message)
output += f" ({message})"
return output


Expand Down Expand Up @@ -135,9 +135,7 @@ def scan(
session_id=session_id,
)
except reporting.ReportServiceException:
print(
"Unable to POST pre-scan report to {}".format(report_url), file=sys.stderr
)
print(f"Unable to POST pre-scan report to {report_url}", file=sys.stderr)

try:
status, report = storage_service.scan_aip(
Expand Down Expand Up @@ -184,7 +182,7 @@ def scan(
)
except reporting.ReportServiceException:
print(
"Unable to POST report for AIP {} to remote service".format(aip),
f"Unable to POST report for AIP {aip} to remote service",
file=sys.stderr,
)

Expand Down Expand Up @@ -307,7 +305,7 @@ def main():
force_local=args.force_local,
)
else:
return Exception('Error: "{}" is not a valid command.'.format(args.command))
return Exception(f'Error: "{args.command}" is not a valid command.')

session.commit()
except Exception as e:
Expand Down
13 changes: 10 additions & 3 deletions fixity/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import os

from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import Column, ForeignKey, Boolean, DateTime, Integer, String
from sqlalchemy.orm import relationship, backref, sessionmaker
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref
from sqlalchemy.orm import relationship
from sqlalchemy.orm import sessionmaker

db_path = os.path.join(os.path.dirname(__file__), "fixity.db")
engine = create_engine("sqlite:///{}".format(db_path), echo=False)
engine = create_engine(f"sqlite:///{db_path}", echo=False)

Session = sessionmaker(bind=engine)
Base = declarative_base()
Expand Down
16 changes: 7 additions & 9 deletions fixity/reporting.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import calendar
import json

from .utils import check_valid_uuid

import requests

from .utils import check_valid_uuid


class ReportServiceException(Exception):
pass
Expand Down Expand Up @@ -36,19 +36,17 @@ def post_pre_scan_report(aip, start_time, report_url, report_auth=(), session_id
if report_auth:
kwargs["auth"] = report_auth

url = report_url + "api/fixity/{}".format(aip)
url = report_url + f"api/fixity/{aip}"

try:
response = requests.post(url, **kwargs)
except requests.ConnectionError:
raise ReportServiceException(
"Unable to connect to report service at URL {}".format(report_url)
f"Unable to connect to report service at URL {report_url}"
)

if not response.status_code == 201:
raise ReportServiceException(
"Report service returned {}".format(response.status_code)
)
raise ReportServiceException(f"Report service returned {response.status_code}")

return True

Expand Down Expand Up @@ -85,14 +83,14 @@ def post_success_report(aip, report, report_url, report_auth=(), session_id=None
if report_auth:
kwargs["auth"] = report_auth

url = report_url + "api/fixity/{}".format(aip)
url = report_url + f"api/fixity/{aip}"

try:
response = requests.post(url, **kwargs)
except requests.ConnectionError:
report.posted = False
raise ReportServiceException(
"Unable to connect to report service at URL {}".format(report_url)
f"Unable to connect to report service at URL {report_url}"
)

if not response.status_code == 201:
Expand Down
9 changes: 5 additions & 4 deletions fixity/storage_service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import calendar
from datetime import datetime
import json
from datetime import datetime

import requests
from sqlalchemy.orm.exc import NoResultFound

from .models import AIP, Report
from .models import AIP
from .models import Report
from .utils import check_valid_uuid


Expand All @@ -25,7 +26,7 @@ class StorageServiceError(Exception):

def __init__(self, message, report=None):
self.report = report
super(StorageServiceError, self).__init__(message)
super().__init__(message)


def _get_aips(ss_url, ss_user, ss_key, uri=None):
Expand Down Expand Up @@ -254,7 +255,7 @@ def scan_aip(
if response.status_code != 200:
json_report = {
"success": None,
"message": "Storage service returned {}".format(response.status_code),
"message": f"Storage service returned {response.status_code}",
"started": begun_int,
"finished": ended_int,
}
Expand Down
2 changes: 1 addition & 1 deletion fixity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class InvalidUUID(Exception):
def __init__(self, uuid):
self.message = "Invalid UUID: {}".format(uuid)
self.message = f"Invalid UUID: {uuid}"

def __str__(self):
return self.message
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests==2.2.1
SQLAlchemy==0.9.4
requests==2.27.1
SQLAlchemy==1.4.48
7 changes: 3 additions & 4 deletions requirements/local.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-r base.txt
ipython==2.0.0
pytest==4.6.5
pytest-cov==2.11.1
vcrpy==1.0.0
pytest==7.0.1
pytest-cov==4.0.0
vcrpy==4.1.1
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

setup(
name="fixity",
version="0.4.0",
version="0.5.0",
packages=["fixity"],
url="https://github.com/artefactual/fixity",
author="Artefactual Systems",
author_email="[email protected]",
entry_points={"console_scripts": ["fixity = fixity.fixity:main"]},
classifiers=[
"License :: OSI Approved :: GNU Affero General Public License v3",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*",
python_requires=">=3.6",
)
11 changes: 6 additions & 5 deletions tests/test_reporting.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from fixity.models import AIP, Report
from fixity import reporting
from fixity.utils import InvalidUUID
import os
from datetime import datetime

import pytest
import vcr

import os
from datetime import datetime
from fixity import reporting
from fixity.models import AIP
from fixity.models import Report
from fixity.utils import InvalidUUID


REPORT_URL = "http://localhost:8003/"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_storage_service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json

import pytest
import vcr

from fixity import storage_service
from fixity.models import Session
from fixity.utils import InvalidUUID

import pytest
import vcr


SESSION = Session()
STORAGE_SERVICE_URL = "http://localhost:8000/"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fixity import utils

import pytest

from fixity import utils


def test_uuid_recognizes_valid_uuid():
assert utils.check_valid_uuid("2791aed2-0fc9-4ddd-9eb1-49420ef99ef2") is True
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
skipsdist = True
envlist = py{27,36,37,38,39},linting
envlist = py{36,37,38,39},linting

[testenv]
skip_install = True
Expand Down

0 comments on commit 4786aa1

Please sign in to comment.