Skip to content

Commit 0251f80

Browse files
author
Matthijs van Otterdijk
authored
Remove old build files and make python 3.11 work (#415)
* remove all old build logic in favor of poetry * fix pytest configuration * update lockfile * fix enum class generation in python 3.11 * add python 3.11 to the ci test matrix * fix linting * modify bumpversion config to not look for setup.py, correct version * bump requests library
1 parent bd04fff commit 0251f80

File tree

14 files changed

+579
-1084
lines changed

14 files changed

+579
-1084
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
[bumpversion]
2-
current_version = 11.0.0
2+
current_version = 10.2.4
33
commit = True
44
tag = True
55

66
[bumpversion:file:terminusdb_client/__version__.py]
77

8-
[bumpversion:file:setup.py]
9-
108
[bumpversion:file:pyproject.toml]

.github/workflows/python.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
run: |
2121
python -m pip install --upgrade pip
2222
python -m pip install tox
23-
tox -e deps
2423
- name: Linting
2524
run: |
2625
tox -e check
@@ -29,7 +28,7 @@ jobs:
2928
runs-on: ubuntu-latest
3029
strategy:
3130
matrix:
32-
python-version: ["3.8", "3.9", "3.10"]
31+
python-version: ["3.8", "3.9", "3.10", "3.11"]
3332

3433
steps:
3534
- uses: actions/checkout@v3
@@ -41,7 +40,6 @@ jobs:
4140
run: |
4241
python -m pip install --upgrade pip
4342
python -m pip install tox
44-
tox -e deps
4543
- name: Test with pytest
4644
run: |
4745
[[ "$GITHUB_REPOSITORY" == "terminusdb/terminusdb-client-python" && "$GITHUB_EVENT_NAME" == "push" ]] && export TERMINUSX_TOKEN='${{ secrets.TERMINUSX_TOKEN_DEV }}'
@@ -64,8 +62,8 @@ jobs:
6462
python-version: "3.10"
6563
- name: Run setup.py sdist
6664
run: |
67-
pip install wheel
68-
python setup.py sdist bdist_wheel
65+
pip install poetry
66+
poetry build
6967
tar -xf dist/*.tar.gz
7068
cat terminusdb-client-*/terminusdb_client.egg-info/requires.txt
7169
unzip -n dist/*.whl

install.txt

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

makefile

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

poetry.lock

Lines changed: 485 additions & 853 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,25 @@ authors = ["TerminusDB group"]
66
license = "Apache Software License"
77

88
[tool.poetry.dependencies]
9-
python = ">=3.8.0,<4.0"
10-
requests = "<2.29.2"
11-
shed = "*"
9+
python = ">=3.8.0,<3.12"
10+
requests = "^2.31.0"
11+
numpy = ">= 1.13.0"
1212
numpydoc = "*"
13+
pandas = ">= 0.23.0"
1314
typeguard = "~2.13.3"
1415
tqdm = "*"
1516
click = ">=8.0"
17+
shed = "*"
1618

1719
[tool.poetry.dev-dependencies]
18-
pytest = "*"
20+
pytest = ">= 3"
21+
pytest-cov = "*"
1922
pytest-mock = "*"
23+
pytest-xdist = "*"
2024
flake8 = "*"
21-
pytest-cov = "*"
22-
bumpversion = "*"
23-
sphinx = "*"
24-
sphinx_rtd_theme = "*"
25-
sphinxcontrib-napoleon = "*"
26-
sphinx_autodoc_typehints = "*"
27-
sphinx_click = "*"
28-
pandas = "~1.4.0"
29-
tox = "*"
30-
interrogate = "*"
31-
pre-commit = "*"
32-
shed = "*"
33-
PyYAML = "<6.0"
25+
26+
[tool.poetry.scripts]
27+
tdbpy = "terminusdb_client.scripts.scripts:tdbpy"
3428

3529
[build-system]
3630
requires = ["poetry-core>=1.0.0"]
@@ -42,3 +36,26 @@ search_path = [ "./terminusdb_client" ]
4236

4337
[tool.pydoc-markdown.renderer]
4438
type = "gitbook"
39+
40+
[tool.pytest.ini_options]
41+
addopts = [
42+
"-p no:warnings",
43+
"--doctest-modules",
44+
"--import-mode=importlib",
45+
]
46+
doctest_optionflags = [
47+
"NORMALIZE_WHITESPACE",
48+
"ELLIPSIS"
49+
]
50+
junit_family="legacy"
51+
testpaths = [
52+
"terminusdb_client/tests/",
53+
]
54+
55+
[tool.isort]
56+
profile = "black"
57+
multi_line_output = 3
58+
include_trailing_comma = true
59+
force_grid_wrap = 0
60+
combine_as_imports = true
61+
line_length = 88

pytest.ini

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

requirements-dev.in

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

requirements.in

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

setup.cfg

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

setup.py

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

terminusdb_client/schema/schema.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,27 @@ def _obj_to_dict(self, skip_checking=False):
369369
return (result, references)
370370

371371

372+
# starting in python 3.11, enums can't really be defined with
373+
# non-unique values anymore. Since that is an established pattern for
374+
# us, we have to put some effort into making those enum values unique.
375+
def transform_enum_dict(d):
376+
"Ensure that all enums in a definition have a unique value by transforming those that have no value set to have their stringified name as a value"
377+
new_dict = {}
378+
for key, value in d.items():
379+
if not key.startswith("__") and not value:
380+
value = str(key)
381+
# remove this value from the undocumented member names list
382+
if type(d._member_names) == list:
383+
d._member_names.remove(key)
384+
else:
385+
d._member_names.pop(key)
386+
new_dict[key] = value
387+
388+
for key, value in new_dict.items():
389+
d.pop(key)
390+
d[key] = value
391+
392+
372393
class EnumMetaTemplate(EnumMeta):
373394
def __new__(
374395
metacls,
@@ -382,13 +403,26 @@ def __new__(
382403
):
383404
if "_schema" in classdict:
384405
schema = classdict.pop("_schema")
385-
classdict._member_names.remove("_schema")
406+
407+
# _member_names is a field maintained in the enum dict
408+
# that keeps track of fields to prevent
409+
# duplicates. Unfortunately, since we're messing with
410+
# definitions here, we'll have to reach into internals
411+
# like this to keep things working well.
412+
# There is probably a better way to do this.
413+
if type(classdict._member_names) == list:
414+
classdict._member_names.remove("_schema")
415+
else:
416+
classdict._member_names.pop("_schema")
417+
418+
transform_enum_dict(classdict)
386419
new_cls = super().__new__(metacls, cls, bases, classdict)
387420
new_cls._schema = schema
388421
if not hasattr(schema, "object"):
389422
schema.object = {}
390423
schema.object[cls] = new_cls
391424
else:
425+
transform_enum_dict(classdict)
392426
new_cls = super().__new__(metacls, cls, bases, classdict)
393427
globals()[cls] = new_cls
394428
return new_cls

terminusdb_client/tests/test_Schema.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from terminusdb_client.client import Client
1010
from terminusdb_client.schema.schema import (
1111
DocumentTemplate,
12+
EnumTemplate,
1213
Schema,
1314
_check_cycling,
1415
)
@@ -450,3 +451,16 @@ def test_from_json_schema():
450451
# other_schema.delete_property(Title)
451452
# assert other_schema.all_obj() == {Employee, Address, Team}
452453
# assert other_schema.all_prop() == {AddressOf, PostCode, Country}
454+
455+
456+
class AnEnum(EnumTemplate):
457+
"An enum"
458+
_schema = Schema()
459+
Foo = ()
460+
Bar = ()
461+
Baz = ()
462+
463+
464+
def test_simple_enum():
465+
assert AnEnum.Foo.name == "Foo"
466+
assert AnEnum.Foo.value == "Foo"

0 commit comments

Comments
 (0)