Skip to content

Commit

Permalink
Drop unsupported Python versions
Browse files Browse the repository at this point in the history
* Upgrade pre-commit dependencies
* Rename codecov config file
* Update manifest file
* Update tests configuration
* Migrate to pyproject.toml
* Update requirements files
* Add make rules for pip-compile commands
* Unpin mysqlclient and requests versions
* Add GitHub workflow for uploading to PyPI
* Bump version
  • Loading branch information
replaceafill authored Nov 8, 2023
1 parent 62b64a0 commit 907c599
Show file tree
Hide file tree
Showing 21 changed files with 353 additions and 131 deletions.
File renamed without changes.
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

16 changes: 16 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[flake8]
exclude = .tox, .git, __pycache__, .cache, build, dist, *.pyc, *.egg-info, .eggs
# Error codes:
# - https://flake8.pycqa.org/en/latest/user/error-codes.html
# - https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
# - https://github.com/PyCQA/flake8-bugbear#list-of-warnings
#
# E203: whitespace before `,`, `;` or `:`
# E402: module level import not at top of file
# E501: line too long
# W503: line break before binary operator
ignore =
E203,
E402,
E501,
W503
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: "Release"
on: "workflow_dispatch"
jobs:
build:
name: "Build"
runs-on: "ubuntu-22.04"
steps:
- name: "Check out repository"
uses: "actions/checkout@v4"
- name: "Set up Python"
uses: "actions/setup-python@v4"
with:
python-version: "3.9"
- name: "Build distribution packages"
run: make package-check
- name: "Save distribution directory"
uses: "actions/upload-artifact@v3"
with:
name: "distribution"
path: |
dist
upload:
name: "Upload"
needs: "build"
runs-on: "ubuntu-22.04"
environment: "release"
permissions:
id-token: "write"
steps:
- name: "Restore distribution directory"
uses: "actions/download-artifact@v3"
with:
name: "distribution"
path: |
dist
- name: "Upload distribution packages to PyPI"
uses: "pypa/gh-action-pypi-publish@release/v1"
34 changes: 15 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,37 @@ on:
branches:
- "master"
jobs:
tox:
test:
name: "Test Python ${{ matrix.python-version }}"
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
strategy:
fail-fast: false
matrix:
python-version: [
"3.6",
"3.7",
"3.8",
"3.9",
"3.10",
"3.11",
"3.12",
]
steps:
- name: "Check out repository"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Set up Python ${{ matrix.python-version }}"
uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
- name: "Get pip cache dir"
id: "pip-cache"
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: "Cache pip packages"
uses: "actions/cache@v3"
with:
path: "${{ steps.pip-cache.outputs.dir }}"
key: "${{ runner.os }}-pip-${{ hashFiles('**/base.txt', '**/local.txt', '**/production.txt') }}"
restore-keys: |
${{ runner.os }}-pip-
cache: "pip"
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- name: "Install tox"
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: "Run tox"
run: |
tox -- --cov-config .coveragerc --cov-report xml:coverage.xml
tox -- --cov agentarchives --cov-report xml:coverage.xml
- name: "Upload coverage report"
if: github.repository == 'artefactual-labs/agentarchives'
uses: "codecov/codecov-action@v3"
Expand All @@ -57,11 +49,15 @@ jobs:
runs-on: "ubuntu-22.04"
steps:
- name: "Check out repository"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Set up Python"
uses: "actions/setup-python@v4"
with:
python-version: "3.8"
python-version: "3.12"
cache: "pip"
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- name: "Install tox"
run: |
python -m pip install --upgrade pip
Expand Down
15 changes: 8 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py3-plus, --py36-plus]
args: [--py38-plus]
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.10.0
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: [--py3-plus, --py36-plus]
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: "23.7.0"
rev: "23.10.1"
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: "6.1.0"
hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-bugbear==23.9.16
- flake8-comprehensions==3.14.0
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include LICENSE
include LICENSE
include README.md
33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
.PHONY: clean package package-deps package-source package-upload package-wheel
.DEFAULT_GOAL := help

package-deps:
pip install --upgrade twine wheel
.PHONY: clean package package-deps package-distribution package-upload pip-compile pip-upgrade

package-source:
python setup.py sdist
package-deps: ## Upgrade dependencies for packaging
python3 -m pip install --upgrade build twine

package-wheel: package-deps
python setup.py bdist_wheel
package-distribution: package-deps ## Create distribution packages
python3 -m build

package-upload: package-deps package-source package-wheel
twine upload dist/* --repository-url https://upload.pypi.org/legacy/
package-check: package-distribution ## Check the distribution is valid
python3 -m twine check --strict dist/*

package-upload: package-deps package-check ## Upload distribution packages
python3 -m twine upload dist/* --repository-url https://upload.pypi.org/legacy/

package: package-upload

clean:
clean: ## Clean the package directory
rm -rf agentarchives.egg-info/
rm -rf build/
rm -rf dist/

pip-compile: ## Compile pip requirements
pip-compile --allow-unsafe --output-file=requirements.txt pyproject.toml
pip-compile --allow-unsafe --extra=dev --output-file=requirements-dev.txt pyproject.toml

pip-upgrade: ## Upgrade pip requirements
pip-compile --allow-unsafe --upgrade --output-file=requirements.txt pyproject.toml
pip-compile --allow-unsafe --upgrade --extra=dev --output-file=requirements-dev.txt pyproject.toml

help: ## Print this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2 changes: 2 additions & 0 deletions agentarchives/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
DEFAULT_TIMEOUT = 10

__version__ = "0.9.0"
24 changes: 18 additions & 6 deletions agentarchives/archivesspace/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,16 @@ def _request(self, method, url, params, expected_response, data=None):

return response

def _get(self, url, params={}, expected_response=200):
def _get(self, url, params=None, expected_response=200):
if params is None:
params = {}
return self._request(
self.session.get, url, params=params, expected_response=expected_response
)

def _put(self, url, params={}, data=None, expected_response=200):
def _put(self, url, params=None, data=None, expected_response=200):
if params is None:
params = {}
return self._request(
self.session.put,
url,
Expand All @@ -198,7 +202,9 @@ def _put(self, url, params={}, data=None, expected_response=200):
expected_response=expected_response,
)

def _post(self, url, params={}, data=None, expected_response=200):
def _post(self, url, params=None, data=None, expected_response=200):
if params is None:
params = {}
return self._request(
self.session.post,
url,
Expand All @@ -207,7 +213,9 @@ def _post(self, url, params={}, data=None, expected_response=200):
expected_response=expected_response,
)

def _delete(self, url, params={}, expected_response=200):
def _delete(self, url, params=None, expected_response=200):
if params is None:
params = {}
return self._request(
self.session.delete, url, params=params, expected_response=expected_response
)
Expand Down Expand Up @@ -558,7 +566,7 @@ def get_resource_component_and_children(
resource_id,
resource_type="collection",
level=1,
sort_data={},
sort_data=None,
recurse_max_level=False,
sort_by=None,
**kwargs,
Expand All @@ -578,6 +586,8 @@ def get_resource_component_and_children(
Consult ArchivistsToolkitClient.get_resource_component_and_children for the output format.
:rtype dict:
"""
if sort_data is None:
sort_data = {}
resource_type = self.resource_type(resource_id)
if resource_type == "resource":
return self._get_resources(
Expand Down Expand Up @@ -1027,7 +1037,7 @@ def add_child(
start_date="",
end_date="",
date_expression="",
notes=[],
notes=None,
):
"""
Adds a new resource component parented within `parent`.
Expand All @@ -1038,6 +1048,8 @@ def add_child(
:return: The ID of the newly-created record.
"""
if notes is None:
notes = []
parent_record = self.get_record(parent)
record_type = self.resource_type(parent)
repository = parent_record["repository"]["ref"]
Expand Down
5 changes: 3 additions & 2 deletions agentarchives/archivists_toolkit/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_resource_component_children(self, resource_component_id):
)

def get_resource_component_and_children(
self, resource_id, resource_type="collection", level=1, sort_data={}, **kwargs
self, resource_id, resource_type="collection", level=1, sort_data=None, **kwargs
):
"""
Fetch detailed metadata for the specified resource_id and all of its children.
Expand Down Expand Up @@ -234,9 +234,10 @@ def get_resource_component_and_children(
}
:rtype list:
"""
if sort_data is None:
sort_data = {}
# we pass the sort position as a dict so it passes by reference and we
# can use it to share state during recursion

recurse_max_level = kwargs.get("recurse_max_level", False)
query = kwargs.get("search_pattern", "")

Expand Down
24 changes: 18 additions & 6 deletions agentarchives/atom/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ def _request(self, method, url, params, expected_response, data=None):

return response

def _get(self, url, params={}, expected_response=200):
def _get(self, url, params=None, expected_response=200):
if params is None:
params = {}
return self._request(
self.session.get, url, params=params, expected_response=expected_response
)

def _put(self, url, params={}, data=None, expected_response=200):
def _put(self, url, params=None, data=None, expected_response=200):
if params is None:
params = {}
return self._request(
self.session.put,
url,
Expand All @@ -94,7 +98,9 @@ def _put(self, url, params={}, data=None, expected_response=200):
expected_response=expected_response,
)

def _post(self, url, params={}, data=None, expected_response=200):
def _post(self, url, params=None, data=None, expected_response=200):
if params is None:
params = {}
return self._request(
self.session.post,
url,
Expand All @@ -103,7 +109,9 @@ def _post(self, url, params={}, data=None, expected_response=200):
expected_response=expected_response,
)

def _delete(self, url, params={}, expected_response=200):
def _delete(self, url, params=None, expected_response=200):
if params is None:
params = {}
return self._request(
self.session.delete, url, params=params, expected_response=expected_response
)
Expand Down Expand Up @@ -369,7 +377,7 @@ def get_resource_component_and_children(
resource_id,
resource_type="collection",
level=1,
sort_data={},
sort_data=None,
recurse_max_level=False,
sort_by=None,
**kwargs,
Expand All @@ -387,6 +395,8 @@ def get_resource_component_and_children(
Consult ArchivistsToolkitClient.get_resource_component_and_children for the output format.
:rtype dict:
"""
if sort_data is None:
sort_data = {}
return self._get_resources(
resource_id, recurse_max_level=recurse_max_level, sort_by=sort_by
)
Expand Down Expand Up @@ -700,7 +710,7 @@ def add_child(
start_date=None,
end_date=None,
date_expression=None,
notes=[],
notes=None,
):
"""
Adds a new resource component parented within `parent`.
Expand All @@ -711,6 +721,8 @@ def add_child(
:return: The ID of the newly-created record.
"""
if notes is None:
notes = []

new_object = {"title": title, "level_of_description": level}

Expand Down
Loading

0 comments on commit 907c599

Please sign in to comment.