Skip to content

Commit

Permalink
setup.cfg -> pyproject.toml
Browse files Browse the repository at this point in the history
Set line-length to 79 (80) in `black` (`pylint`) tools.
  • Loading branch information
CasperWA committed Aug 23, 2021
1 parent f7d62f8 commit be967f3
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 229 deletions.
9 changes: 7 additions & 2 deletions .github/static/get_dic2owl_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def main(argv_input: list = None) -> Set[str]:
)
args = parser.parse_args(argv_input)

requirements_regex = re.compile(r"^(?P<name>[A-Za-z0-9_-]+)(~=|>=|==).*\n$")
requirements_regex = re.compile(
r"^(?P<name>[A-Za-z0-9_-]+)(~=|>=|==).*\n$"
)
dependencies = set()
for file in args.requirements_files:
if not file.exists():
Expand All @@ -34,7 +36,10 @@ def main(argv_input: list = None) -> Set[str]:
match = requirements_regex.fullmatch(line)
if match is None:
raise ValueError(
f"Couldn't determine package name from line:\n\n {line}"
(
"Couldn't determine package name from line:\n\n "
f"{line}"
)
)
dependencies.add(match.group("name"))
return dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dic2owl_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: bandit -r dic2owl/dic2owl

- name: Run PyLint
run: pylint --rcfile=dic2owl/setup.cfg dic2owl/dic2owl
run: pylint --rcfile=dic2owl/pyproject.toml dic2owl/dic2owl

- name: Run safety
run: |
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ repos:
rev: 21.7b0
hooks:
- id: black
args:
- --config=dic2owl/pyproject.toml

- repo: https://github.com/pycqa/pylint
rev: 'v2.10.1'
hooks:
- id: pylint
args:
- --rcfile
- dic2owl/setup.cfg
- --disable
- import-error
- --rcfile=dic2owl/pyproject.toml
- --disable=import-error
8 changes: 5 additions & 3 deletions dic2owl/dic2owl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
This is a tool to generate ontologies from a CIF `.dic`-file.
It can be used either by importing and using the `dic2owl.dic2owl.main` function or running it via
the `dic2owl` CLI, which will be automatically installed when `pip install`-ing this package.
For more information on how to run the CLI, run `dic2owl --help` in your terminal.
It can be used either by importing and using the `dic2owl.dic2owl.main`
function or running it via the `dic2owl` CLI, which will be automatically
installed when `pip install`-ing this package.
For more information on how to run the CLI, run `dic2owl --help` in your
terminal.
"""

__version__ = "0.1.0"
Expand Down
25 changes: 17 additions & 8 deletions dic2owl/dic2owl/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""
# `dic2owl` CLI
The `dic2owl` command line interface (CLI) is an easy way of running the ontology-generation tool
for CIF `.dic`-files.
The `dic2owl` command line interface (CLI) is an easy way of running the
ontology-generation tool for CIF `.dic`-files.
"""
import argparse
import logging
from pathlib import Path


LOGGING_LEVELS = [logging.getLevelName(level).lower() for level in range(0, 51, 10)]
LOGGING_LEVELS = [
logging.getLevelName(level).lower() for level in range(0, 51, 10)
]


def main(argv: list = None) -> None:
Expand Down Expand Up @@ -50,24 +52,31 @@ def main(argv: list = None) -> None:
dest="ttlfile",
type=Path,
help=(
'The generated output file. Example "--output cif_core.ttl". If output is not '
"provided, the filename will be taken to be similar to the CIF_DIC file."
'The generated output file. Example "--output cif_core.ttl". If '
"output is not provided, the filename will be taken to be similar "
"to the CIF_DIC file."
),
)
parser.add_argument(
"dicfile",
metavar="CIF_DIC",
type=Path,
help="The CIF dictionary file from which to generate an OWL ontologized Turtle file.",
help=(
"The CIF dictionary file from which to generate an OWL ontologized"
" Turtle file."
),
)

args = parser.parse_args(argv)

if args.ttlfile is None:
args.ttlfile = args.dicfile.resolve().name[: -len(args.dicfile.suffix)] + ".ttl"
args.ttlfile = (
args.dicfile.resolve().name[: -len(args.dicfile.suffix)] + ".ttl"
)

if not args.dicfile.resolve().exists():
# The dic-file does not exist, use it as a string instead so it can be downloaded.
# The dic-file does not exist, use it as a string instead so it can be
# downloaded.
args.dicfile = str(args.dicfile)

dic2owl_run(dicfile=args.dicfile, ttlfile=args.ttlfile)
11 changes: 8 additions & 3 deletions dic2owl/dic2owl/dic2owl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

"""The absolute, normalized path to the `ontology` directory in this
repository"""
ONTOLOGY_DIR = Path(__file__).resolve().parent.parent.parent.joinpath("ontology")
ONTOLOGY_DIR = (
Path(__file__).resolve().parent.parent.parent.joinpath("ontology")
)


def lang_en(string: str) -> locstr:
Expand Down Expand Up @@ -218,7 +220,9 @@ def _add_metadata(self) -> None:

for comment in self.comments:
self.onto.metadata.comment.append(comment)
self.onto.metadata.comment.append(f"Generated with dic2owl from {self.dicfile}")
self.onto.metadata.comment.append(
f"Generated with dic2owl from {self.dicfile}"
)


def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator:
Expand Down Expand Up @@ -250,7 +254,8 @@ def main(dicfile: Union[str, Path], ttlfile: Union[str, Path]) -> Generator:
for dic in ("ddl.dic", "templ_attr.cif", "templ_enum.cif", dicfile):
if not Path(dic).resolve().exists():
print("downloading", dic)
# Since `baseurl` is used, the retrieved URL will never be a `file://` or similar.
# Since `baseurl` is used, the retrieved URL will never be a
# `file://` or similar.
urllib.request.urlretrieve(baseurl + dic, dic) # nosec

gen = Generator(dicfile=dicfile, base_iri=base_iri)
Expand Down
Loading

0 comments on commit be967f3

Please sign in to comment.