Skip to content

Commit 62b64a0

Browse files
authored
Fix ArchivesSpace URL parsing in Python 3.9+
* Fix ArchivesSpace URL parsing in Python 3.9+ * Update package setup * Update CI configuration * Add long description to package setup * Do not fail CI on coverage upload error
1 parent 580e189 commit 62b64a0

File tree

9 files changed

+61
-29
lines changed

9 files changed

+61
-29
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ on:
77
- "master"
88
jobs:
99
tox:
10-
name: "Test ${{ matrix.toxenv }}"
10+
name: "Test Python ${{ matrix.python-version }}"
1111
runs-on: "ubuntu-20.04"
1212
strategy:
13+
fail-fast: false
1314
matrix:
14-
include:
15-
- python-version: "3.6"
16-
toxenv: "py36"
17-
- python-version: "3.7"
18-
toxenv: "py37"
19-
- python-version: "3.8"
20-
toxenv: "py38"
15+
python-version: [
16+
"3.6",
17+
"3.7",
18+
"3.8",
19+
"3.9",
20+
"3.10",
21+
"3.11",
22+
]
2123
steps:
2224
- name: "Check out repository"
2325
uses: "actions/checkout@v3"
@@ -39,21 +41,17 @@ jobs:
3941
- name: "Install tox"
4042
run: |
4143
python -m pip install --upgrade pip
42-
pip install tox
44+
pip install tox tox-gh-actions
4345
- name: "Run tox"
44-
env:
45-
TOXENV: ${{ matrix.toxenv }}
4646
run: |
4747
tox -- --cov-config .coveragerc --cov-report xml:coverage.xml
4848
- name: "Upload coverage report"
4949
if: github.repository == 'artefactual-labs/agentarchives'
5050
uses: "codecov/codecov-action@v3"
5151
with:
5252
files: ./coverage.xml
53-
fail_ci_if_error: true
53+
fail_ci_if_error: false
5454
verbose: true
55-
name: ${{ matrix.toxenv }}
56-
flags: ${{ matrix.toxenv }}
5755
lint:
5856
name: "Lint"
5957
runs-on: "ubuntu-22.04"

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
repos:
22
- repo: https://github.com/asottile/pyupgrade
3-
rev: v2.31.0
3+
rev: v3.10.1
44
hooks:
55
- id: pyupgrade
66
args: [--py3-plus, --py36-plus]
77
- repo: https://github.com/asottile/reorder_python_imports
8-
rev: v2.6.0
8+
rev: v3.10.0
99
hooks:
1010
- id: reorder-python-imports
1111
args: [--py3-plus, --py36-plus]
12-
- repo: https://github.com/ambv/black
13-
rev: 22.8.0
12+
- repo: https://github.com/psf/black
13+
rev: "23.7.0"
1414
hooks:
1515
- id: black
1616
args: [--safe, --quiet]
1717
language_version: python3
1818
- repo: https://github.com/pycqa/flake8
19-
rev: 5.0.4
19+
rev: "6.1.0"
2020
hooks:
2121
- id: flake8
2222
language_version: python3

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package-source:
77
python setup.py sdist
88

99
package-wheel: package-deps
10-
python setup.py bdist_wheel --universal
10+
python setup.py bdist_wheel
1111

1212
package-upload: package-deps package-source package-wheel
1313
twine upload dist/* --repository-url https://upload.pypi.org/legacy/

agentarchives/archivesspace/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import re
5+
import sys
56
from urllib.parse import urlparse
67

78
import requests
@@ -87,11 +88,17 @@ def _build_base_url(self, host, port):
8788
removed so it always need to be added by the consumer.
8889
"""
8990
parsed = urlparse(host)
90-
if not parsed.scheme:
91+
# In some cases Python3.9+ may parse the host as the scheme.
92+
# See https://bugs.python.org/issue27657
93+
if not parsed.scheme or (
94+
sys.version_info >= (3, 9)
95+
and host.partition(":")[0] == parsed.scheme
96+
and not parsed.netloc
97+
):
9198
parsed = parsed._replace(scheme="http")
9299
parsed = parsed._replace(path="")
93100
netloc, parts = host, host.partition(":")
94-
if parts[1] == "" and port is not None:
101+
if parts[1] == "" and port not in (None, ""):
95102
netloc = f"{parts[0]}:{port}"
96103
parsed = parsed._replace(netloc=netloc)
97104
parsed = parsed._replace(path=parsed.path.rstrip("/"))

requirements/base.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
requests>=2,<3
2-
mysqlclient>=1.4,<2
3-
urllib3<2
1+
requests
2+
mysqlclient

setup.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
import codecs
2+
from os import path
3+
14
from setuptools import setup
25

6+
7+
here = path.abspath(path.dirname(__file__))
8+
9+
with codecs.open(path.join(here, "README.md"), encoding="utf-8") as f:
10+
long_description = f.read()
11+
312
setup(
413
name="agentarchives",
514
description="Clients to retrieve, add, and modify records from archival management systems",
15+
long_description=long_description,
16+
long_description_content_type="text/markdown",
617
url="https://github.com/artefactual-labs/agentarchives",
718
author="Artefactual Systems",
819
author_email="[email protected]",
@@ -14,7 +25,7 @@
1425
"agentarchives.archivists_toolkit",
1526
"agentarchives.atom",
1627
],
17-
install_requires=["requests>=2,<3", "mysqlclient>=1.4,<2"],
28+
install_requires=["requests", "mysqlclient"],
1829
python_requires=">=3.6",
1930
classifiers=[
2031
"Development Status :: 4 - Beta",
@@ -23,5 +34,8 @@
2334
"Programming Language :: Python :: 3.6",
2435
"Programming Language :: Python :: 3.7",
2536
"Programming Language :: Python :: 3.8",
37+
"Programming Language :: Python :: 3.9",
38+
"Programming Language :: Python :: 3.10",
39+
"Programming Language :: Python :: 3.11",
2640
],
2741
)

tests/test_archivesspace_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
[
1919
# These are pairs that we don't like and we raise.
2020
({"host": "", "port": ""}, True, None),
21+
({"host": None, "port": None}, True, None),
2122
({"host": "", "port": "string"}, True, None),
2223
({"host": "string", "port": "string"}, True, None),
2324
# When `host` is not a URL.
@@ -26,6 +27,10 @@
2627
({"host": "localhost", "port": 12345}, False, "http://localhost:12345"),
2728
({"host": "localhost", "port": "12345"}, False, "http://localhost:12345"),
2829
({"host": "localhost", "port": None}, False, "http://localhost"),
30+
({"host": "localhost", "port": ""}, False, "http://localhost"),
31+
({"host": "foobar.tld", "port": ""}, False, "http://foobar.tld"),
32+
({"host": "foobar.tld", "port": None}, False, "http://foobar.tld"),
33+
({"host": "foobar.tld", "port": "12345"}, False, "http://foobar.tld:12345"),
2934
# When `host` is a URL!
3035
({"host": "http://apiserver"}, False, "http://apiserver"),
3136
(
@@ -149,7 +154,7 @@ def test_find_resource_children():
149154
client = ArchivesSpaceClient(**AUTH)
150155
data = client.get_resource_component_and_children("/repositories/2/resources/1")
151156

152-
assert type(data) == dict
157+
assert isinstance(data, dict)
153158
assert len(data["children"]) == 2
154159
assert data["has_children"] is True
155160
assert data["title"] == "Test fonds"

tests/test_atom_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_find_resource_children():
141141
client = AtomClient(**AUTH)
142142
data = client.get_resource_component_and_children("test-fonds")
143143

144-
assert type(data) == dict
144+
assert isinstance(data, dict)
145145
assert len(data["children"]) == 1
146146
assert data["has_children"] is True
147147
assert data["title"] == "Test fonds"

tox.ini

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
[tox]
2-
envlist = py{36,37,38}, flake8, linting
2+
envlist = py{36,37,38,39,310,311}, linting
3+
4+
[gh-actions]
5+
python =
6+
3.6: py36
7+
3.7: py37
8+
3.8: py38
9+
3.9: py39
10+
3.10: py310
11+
3.11: py311
312

413
[testenv]
514
deps = -rrequirements/local.txt

0 commit comments

Comments
 (0)