From 78b198935c8251ac704ad5770a1764c205717437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20B=2E=20D=C3=B8rm=C3=A6nen?= Date: Thu, 26 Nov 2020 20:33:34 +0100 Subject: [PATCH 1/3] chore: upgrade build tools --- .github/workflows/coverage.yml | 7 ++-- .github/workflows/release.yml | 7 ++-- .github/workflows/tests.yml | 7 ++-- README.md | 6 ++++ mypy.ini | 3 ++ noxfile.py | 49 ++++++++++----------------- pyproject.toml | 2 +- src/concepttordf/concept.py | 62 +++++++++++++++++++++++++++------- tests/test_collection.py | 6 ++-- tests/test_concept.py | 6 ++-- tests/test_contact.py | 6 ++-- tests/test_definition.py | 6 ++-- 12 files changed, 104 insertions(+), 63 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 52cc6bf..72f35fb 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -10,8 +10,11 @@ jobs: with: python-version: '3.8' architecture: x64 - - run: pip install nox==2019.11.9 - - run: pip install poetry==1.0.5 + - run: python3 -m pip install --user pipx + - run: python3 -m pipx ensurepath + - run: pipx install nox==2020.8.22 + - run: pipx install poetry==1.1.4 + - run: pipx inject nox nox-poetry - run: nox --sessions tests-3.8 coverage env: CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45f0226..4a4f614 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,8 +12,11 @@ jobs: with: python-version: '3.8' architecture: x64 - - run: pip install nox==2019.11.9 - - run: pip install poetry==1.0.5 + - run: python3 -m pip install --user pipx + - run: python3 -m pipx ensurepath + - run: pipx install nox==2020.8.22 + - run: pipx install poetry==1.1.4 + - run: pipx inject nox nox-poetry - run: nox - run: poetry build - run: poetry publish --username=__token__ --password=${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a21e1e3..9cff489 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,9 @@ jobs: with: python-version: ${{ matrix.python-version }} architecture: x64 - - run: pip install nox==2019.11.9 - - run: pip install poetry==1.0.5 + - run: python3 -m pip install --user pipx + - run: python3 -m pipx ensurepath + - run: pipx install nox==2020.8.22 + - run: pipx install poetry==1.1.4 + - run: pipx inject nox nox-poetry - run: nox diff --git a/README.md b/README.md index fd8cded..da56b8d 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,15 @@ Will print the concept according to the specification: ## Development ### Requirements +- [pipx](https://pipxproject.github.io/pipx/) (recommended) - [pyenv](https://github.com/pyenv/pyenv) (recommended) - [poetry](https://python-poetry.org/) - [nox](https://nox.thea.codes/en/stable/) +``` +% pipx install poetry +% pipx install nox +% pipx inject nox nox-poetry +``` ### Install ``` diff --git a/mypy.ini b/mypy.ini index be84c9c..d424bf5 100644 --- a/mypy.ini +++ b/mypy.ini @@ -5,3 +5,6 @@ ignore_missing_imports = True [mypy-rdflib.*] ignore_missing_imports = True + +[mypy-nox_poetry.*] +ignore_missing_imports = True diff --git a/noxfile.py b/noxfile.py index 1f4f052..183238d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,35 +1,21 @@ """Nox sessions.""" import tempfile -from typing import Any import nox from nox.sessions import Session +import nox_poetry # noqa: F401 package = "concepttordf" locations = "src", "tests", "noxfile.py", "docs/conf.py" nox.options.sessions = "lint", "mypy", "pytype", "tests" -def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> None: - """Install packages constrained by Poetry's lock file.""" - with tempfile.NamedTemporaryFile() as requirements: - session.run( - "poetry", - "export", - "--dev", - "--format=requirements.txt", - f"--output={requirements.name}", - external=True, - ) - session.install(f"--constraint={requirements.name}", *args, **kwargs) - - -@nox.session(python=["3.8", "3.7"]) +@nox.session(python=["3.8", "3.7", "3.9"]) def tests(session: Session) -> None: """Run the test suite.""" args = session.posargs or ["--cov"] - session.run("poetry", "install", "--no-dev", external=True) - install_with_constraints(session, "coverage[toml]", "pytest", "pytest-cov") + session.install(".") + session.install("coverage[toml]", "pytest", "pytest-cov") session.run("pytest", *args) @@ -37,16 +23,15 @@ def tests(session: Session) -> None: def black(session: Session) -> None: """Run black code formatter.""" args = session.posargs or locations - install_with_constraints(session, "black") + session.install("black") session.run("black", *args) -@nox.session(python=["3.8", "3.7"]) +@nox.session(python=["3.7", "3.8", "3.9"]) def lint(session: Session) -> None: """Lint using flake8.""" args = session.posargs or locations - install_with_constraints( - session, + session.install( "flake8", "flake8-annotations", "flake8-bandit", @@ -59,7 +44,7 @@ def lint(session: Session) -> None: session.run("flake8", *args) -@nox.session(python="3.8") +@nox.session(python="3.9") def safety(session: Session) -> None: """Scan dependencies for insecure packages.""" with tempfile.NamedTemporaryFile() as requirements: @@ -72,15 +57,15 @@ def safety(session: Session) -> None: f"--output={requirements.name}", external=True, ) - install_with_constraints(session, "safety") + session.install("safety") session.run("safety", "check", f"--file={requirements.name}", "--full-report") -@nox.session(python=["3.8", "3.7"]) +@nox.session(python=["3.7", "3.8", "3.9"]) def mypy(session: Session) -> None: """Type-check using mypy.""" args = session.posargs or locations - install_with_constraints(session, "mypy") + session.install("mypy") session.run("mypy", *args) @@ -88,7 +73,7 @@ def mypy(session: Session) -> None: def pytype(session: Session) -> None: """Run the static type checker using pytype.""" args = session.posargs or ["--disable=import-error,pyi-error", *locations] - install_with_constraints(session, "pytype") + session.install("pytype") session.run("pytype", *args) @@ -96,22 +81,22 @@ def pytype(session: Session) -> None: def xdoctest(session: Session) -> None: """Run examples with xdoctest.""" args = session.posargs or ["all"] - session.run("poetry", "install", "--no-dev", external=True) - install_with_constraints(session, "xdoctest") + session.install(".") + session.install("xdoctest") session.run("python", "-m", "xdoctest", package, *args) @nox.session(python="3.8") def docs(session: Session) -> None: """Build the documentation.""" - session.run("poetry", "install", "--no-dev", external=True) - install_with_constraints(session, "sphinx", "sphinx_autodoc_typehints") + session.install(".") + session.install("sphinx", "sphinx_autodoc_typehints") session.run("sphinx-build", "docs", "docs/_build") @nox.session(python="3.8") def coverage(session: Session) -> None: """Upload coverage data.""" - install_with_constraints(session, "coverage[toml]", "codecov") + session.install("coverage[toml]", "codecov") session.run("coverage", "xml", "--fail-under=0") session.run("codecov", *session.posargs) diff --git a/pyproject.toml b/pyproject.toml index e0b062d..d982a2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "concepttordf" -version = "1.0.0" +version = "1.0.1" description= "A library for mapping a concept collection to rdf" authors = ["Stig B. Dørmænen "] license = "Apache-2.0" diff --git a/src/concepttordf/concept.py b/src/concepttordf/concept.py index af7e4f1..10ebb25 100644 --- a/src/concepttordf/concept.py +++ b/src/concepttordf/concept.py @@ -385,9 +385,9 @@ def _add_alternativeterm_to_graph(self: Concept) -> None: if "name" in self.alternativeterm: _name = self.alternativeterm["name"] for key in _name: - for l in _name[key]: + for _l in _name[key]: self._g.add( - (altLabel, SKOSXL.literalForm, Literal(l, lang=key)) + (altLabel, SKOSXL.literalForm, Literal(_l, lang=key)) ) if "modified" in self.alternativeterm: self._g.add( @@ -406,9 +406,13 @@ def _add_datastrukturterm_to_graph(self: Concept) -> None: if "name" in self.datastrukturterm: _name = self.datastrukturterm["name"] for key in _name: - for l in _name[key]: + for _l in _name[key]: self._g.add( - (datastrukturterm, SKOSXL.literalForm, Literal(l, lang=key)) + ( + datastrukturterm, + SKOSXL.literalForm, + Literal(_l, lang=key), + ) ) if "modified" in self.datastrukturterm: self._g.add( @@ -429,9 +433,9 @@ def _add_hiddenterm_to_graph(self: Concept) -> None: if "name" in self.hiddenterm: _name = self.hiddenterm["name"] for key in _name: - for l in _name[key]: + for _l in _name[key]: self._g.add( - (hiddenLabel, SKOSXL.literalForm, Literal(l, lang=key)) + (hiddenLabel, SKOSXL.literalForm, Literal(_l, lang=key)) ) if "modified" in self.hiddenterm: self._g.add( @@ -616,7 +620,13 @@ def _add_text_to_bs_graph( if getattr(betydningsbeskrivelse, "text", None): _text = betydningsbeskrivelse.text for key in _text: - self._g.add((bsnode, RDFS.label, Literal(_text[key], lang=key),)) + self._g.add( + ( + bsnode, + RDFS.label, + Literal(_text[key], lang=key), + ) + ) def _add_remark_to_bs_graph( self: Concept, betydningsbeskrivelse: Betydningsbeskrivelse, bsnode: BNode @@ -639,7 +649,11 @@ def _add_scope_to_bs_graph( _scope = BNode() if "url" in betydningsbeskrivelse.scope: self._g.add( - (_scope, RDFS.seeAlso, URIRef(betydningsbeskrivelse.scope["url"]),) + ( + _scope, + RDFS.seeAlso, + URIRef(betydningsbeskrivelse.scope["url"]), + ) ) if "text" in betydningsbeskrivelse.scope: _text = betydningsbeskrivelse.scope["text"] @@ -660,14 +674,32 @@ def _add_relationtosource_bs_to_graph( RelationToSource(betydningsbeskrivelse.relationtosource) is RelationToSource.sitatFraKilde ): - self._g.add((bsnode, SKOSNO.forholdTilKilde, SKOSNO.sitatFraKilde,)) + self._g.add( + ( + bsnode, + SKOSNO.forholdTilKilde, + SKOSNO.sitatFraKilde, + ) + ) elif ( RelationToSource(betydningsbeskrivelse.relationtosource) is RelationToSource.basertPaKilde ): - self._g.add((bsnode, SKOSNO.forholdTilKilde, SKOSNO.basertPåKilde,)) + self._g.add( + ( + bsnode, + SKOSNO.forholdTilKilde, + SKOSNO.basertPåKilde, + ) + ) else: - self._g.add((bsnode, SKOSNO.forholdTilKilde, SKOSNO.egendefinert,)) + self._g.add( + ( + bsnode, + SKOSNO.forholdTilKilde, + SKOSNO.egendefinert, + ) + ) def _add_source_to_bs_graph( self: Concept, betydningsbeskrivelse: Betydningsbeskrivelse, bsnode: BNode @@ -706,4 +738,10 @@ def _add_example_to_bs_graph( if getattr(betydningsbeskrivelse, "example", None): _example = betydningsbeskrivelse.example for key in _example: - self._g.add((bsnode, SKOS.example, Literal(_example[key], lang=key),)) + self._g.add( + ( + bsnode, + SKOS.example, + Literal(_example[key], lang=key), + ) + ) diff --git a/tests/test_collection.py b/tests/test_collection.py index 81e73b1..f16c56a 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -113,6 +113,6 @@ def _dump_diff(g1: Graph, g2: Graph) -> None: def _dump_turtle(g: Graph) -> None: - for l in g.serialize(format="text/turtle").splitlines(): - if l: - print(l.decode()) + for _l in g.serialize(format="text/turtle").splitlines(): + if _l: + print(_l.decode()) diff --git a/tests/test_concept.py b/tests/test_concept.py index 9074bc3..dfb10af 100644 --- a/tests/test_concept.py +++ b/tests/test_concept.py @@ -274,6 +274,6 @@ def _dump_diff(g1: Graph, g2: Graph) -> None: def _dump_turtle(g: Graph) -> None: - for l in g.serialize(format="text/turtle").splitlines(): - if l: - print(l.decode()) + for _l in g.serialize(format="text/turtle").splitlines(): + if _l: + print(_l.decode()) diff --git a/tests/test_contact.py b/tests/test_contact.py index 751ab8b..7596351 100644 --- a/tests/test_contact.py +++ b/tests/test_contact.py @@ -63,6 +63,6 @@ def _dump_diff(g1: Graph, g2: Graph) -> None: def _dump_turtle(g: Graph) -> None: - for l in g.serialize(format="text/turtle").splitlines(): - if l: - print(l.decode()) + for _l in g.serialize(format="text/turtle").splitlines(): + if _l: + print(_l.decode()) diff --git a/tests/test_definition.py b/tests/test_definition.py index d8e22c3..68dfaaf 100644 --- a/tests/test_definition.py +++ b/tests/test_definition.py @@ -62,6 +62,6 @@ def _dump_diff(g1: Graph, g2: Graph) -> None: def _dump_turtle(g: Graph) -> None: - for l in g.serialize(format="text/turtle").splitlines(): - if l: - print(l.decode()) + for _l in g.serialize(format="text/turtle").splitlines(): + if _l: + print(_l.decode()) From c4c933d7e6e3180cefd9e59ca12a395ac3730c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20B=2E=20D=C3=B8rm=C3=A6nen?= Date: Thu, 26 Nov 2020 20:41:40 +0100 Subject: [PATCH 2/3] chore: use pip instead of pipx in actions --- .github/workflows/coverage.yml | 8 +++----- .github/workflows/release.yml | 8 +++----- .github/workflows/tests.yml | 8 +++----- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 72f35fb..3372eaf 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -10,11 +10,9 @@ jobs: with: python-version: '3.8' architecture: x64 - - run: python3 -m pip install --user pipx - - run: python3 -m pipx ensurepath - - run: pipx install nox==2020.8.22 - - run: pipx install poetry==1.1.4 - - run: pipx inject nox nox-poetry + - run: pip install nox==2020.8.22 + - run: pip install poetry==1.1.4 + - run: pip install nox-poetry - run: nox --sessions tests-3.8 coverage env: CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4a4f614..eaa8054 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,11 +12,9 @@ jobs: with: python-version: '3.8' architecture: x64 - - run: python3 -m pip install --user pipx - - run: python3 -m pipx ensurepath - - run: pipx install nox==2020.8.22 - - run: pipx install poetry==1.1.4 - - run: pipx inject nox nox-poetry + - run: pip install nox==2020.8.22 + - run: pip install poetry==1.1.4 + - run: pip install nox-poetry - run: nox - run: poetry build - run: poetry publish --username=__token__ --password=${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9cff489..0521596 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,9 +13,7 @@ jobs: with: python-version: ${{ matrix.python-version }} architecture: x64 - - run: python3 -m pip install --user pipx - - run: python3 -m pipx ensurepath - - run: pipx install nox==2020.8.22 - - run: pipx install poetry==1.1.4 - - run: pipx inject nox nox-poetry + - run: pip install nox==2020.8.22 + - run: pip install poetry==1.1.4 + - run: pip install nox-poetry - run: nox From ddbfe899924bcd190c418c19f14fe39ab374f054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20B=2E=20D=C3=B8rm=C3=A6nen?= Date: Thu, 26 Nov 2020 20:45:06 +0100 Subject: [PATCH 3/3] chore: also test under 3.9 --- .github/workflows/coverage.yml | 4 ++-- .github/workflows/release.yml | 2 +- .github/workflows/tests.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3372eaf..b38fc14 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -8,11 +8,11 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: '3.8' + python-version: '3.9' architecture: x64 - run: pip install nox==2020.8.22 - run: pip install poetry==1.1.4 - run: pip install nox-poetry - - run: nox --sessions tests-3.8 coverage + - run: nox --sessions tests-3.9 coverage env: CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eaa8054..3c67ee1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: '3.8' + python-version: '3.9' architecture: x64 - run: pip install nox==2020.8.22 - run: pip install poetry==1.1.4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0521596..39ba2bd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8'] + python-version: ['3.7', '3.8', '3.9'] name: Python ${{ matrix.python-version }} steps: - uses: actions/checkout@v2