Skip to content

Commit

Permalink
Merge pull request #8 from Informasjonsforvaltning/chore/upgrade_build
Browse files Browse the repository at this point in the history
Chore/upgrade build
  • Loading branch information
stigbd authored Nov 26, 2020
2 parents 82b9c41 + ddbfe89 commit 910cec8
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 67 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +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==2019.11.9
- run: pip install poetry==1.0.5
- run: nox --sessions tests-3.8 coverage
- run: pip install nox==2020.8.22
- run: pip install poetry==1.1.4
- run: pip install nox-poetry
- run: nox --sessions tests-3.9 coverage
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,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==2019.11.9
- run: pip install poetry==1.0.5
- 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 }}
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: pip install nox==2019.11.9
- run: pip install poetry==1.0.5
- run: pip install nox==2020.8.22
- run: pip install poetry==1.1.4
- run: pip install nox-poetry
- run: nox
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ ignore_missing_imports = True

[mypy-rdflib.*]
ignore_missing_imports = True

[mypy-nox_poetry.*]
ignore_missing_imports = True
49 changes: 17 additions & 32 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,37 @@
"""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)


@nox.session(python="3.8")
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",
Expand All @@ -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:
Expand All @@ -72,46 +57,46 @@ 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)


@nox.session(python="3.7")
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)


@nox.session(python=["3.8", "3.7"])
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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "Apache-2.0"
Expand Down
62 changes: 50 additions & 12 deletions src/concepttordf/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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
Expand Down Expand Up @@ -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),
)
)
6 changes: 3 additions & 3 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
6 changes: 3 additions & 3 deletions tests/test_concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
6 changes: 3 additions & 3 deletions tests/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
6 changes: 3 additions & 3 deletions tests/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 910cec8

Please sign in to comment.