Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dic2owl to new annotated ontology schema #52

Merged
merged 9 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/static/get_dic2owl_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
# Retrieve dependencies
Retrieve dependencies from a `requirements.txt`-style file.
"""
import argparse
from pathlib import Path
import re
from typing import Set


def main(argv_input: list = None) -> Set[str]:
"""Retrieve dependencies"""
parser = argparse.ArgumentParser(
description=main.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"requirements_files",
metavar="FILE",
type=Path,
nargs="+",
help="The path(s) to one or several requirements.txt-style file(s).",
)
args = parser.parse_args(argv_input)

requirements_regex = re.compile(
r"^(?P<name>[A-Za-z0-9_-]+)(~=|>=|==).*\n$"
)
dependencies = set()
for file in args.requirements_files:
if not file.exists():
raise FileNotFoundError(f"Could not find {file} !")
with open(file.resolve(), "r") as handle:
for line in handle.readlines():
match = requirements_regex.fullmatch(line)
if match is None:
raise ValueError(
(
"Couldn't determine package name from line:\n\n "
f"{line}"
)
)
dependencies.add(match.group("name"))
return dependencies


if __name__ == "__main__":
from sys import argv

parsed_dependencies = main(argv[1:])
grep_extended_regex = f"({'|'.join(parsed_dependencies)})"
print(grep_extended_regex)
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push, pull_request]
on: [push]

jobs:

Expand All @@ -22,4 +22,4 @@ jobs:
pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
13 changes: 8 additions & 5 deletions .github/workflows/dic2owl_ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: CI - dic2owl

on: [push, pull_request]
on:
push:
paths:
- 'dic2owl/**'

jobs:

Expand All @@ -21,19 +24,19 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -U -r dic2owl/requirements.txt
pip install -U -e dic2owl
pip install bandit pylint safety mypy pytest pytest-cov

- name: Run bandit
run: bandit -r dic2owl/dic2owl

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

- name: Run safety
run: |
safety check -r dic2owl/requirements.txt --bare
safety check -r dic2owl/requirements_dev.txt --bare
DEPENDENCIES=$( python .github/static/get_dic2owl_deps.py dic2owl/requirements.txt dic2owl/requirements_dev.txt )
pip freeze | grep -E "${DEPENDENCIES}" | safety check --stdin

- name: Lint with MyPy
run: mypy --ignore-missing-imports --scripts-are-modules dic2owl/dic2owl
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ old
__pycache__
*.pyc

.mypy*

*.dic
*.cif

Expand Down
18 changes: 7 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ repos:
rev: 21.7b0
hooks:
- id: black
name: Blacken
args:
- --config=dic2owl/pyproject.toml

- repo: https://gitlab.com/pycqa/flake8
rev: '3.9.2'
- repo: https://github.com/pycqa/pylint
rev: 'v2.10.1'
hooks:
- id: flake8
- id: pylint
args:
- --count
- --show-source
- --statistics
# E501: Line to long. Handled by black.
# W503: Line break before binary operator. This is preferred formatting for black.
# E203: Whitespace before ':'.
- --ignore=E501,W503,E203
- --rcfile=dic2owl/pyproject.toml
- --disable=import-error
2 changes: 2 additions & 0 deletions dic2owl/dic2owl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cif_core.ttl
catalog-v001.xml
19 changes: 16 additions & 3 deletions dic2owl/dic2owl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
__version__ = "0.1.0"
__author__ = "Jesper Friis"
__author_email__ = "[email protected]"
"""
# `dic2owl` Python package
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.
"""
# pylint: disable=line-too-long

__version__ = "0.2.0"
__author__ = "Jesper Friis <[email protected]>, Casper Welzel Andersen <[email protected]>, Francesca Lønstad Bleken <[email protected]>"
__author_email__ = "[email protected]"
34 changes: 25 additions & 9 deletions dic2owl/dic2owl/cli.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
"""
# `dic2owl` CLI
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(args: list = None):
def main(argv: list = None) -> None:
"""Ontologize CIF dictionaries (`.dic`) using OWL.
Produce an OWL Turtle (`.ttl`) file from a CIF dictionary (`.dic`) file.
"""
# pylint: disable=import-outside-toplevel
from dic2owl import __version__
from dic2owl.generate_cif import main as dic2owl_run
from dic2owl.dic2owl import main as dic2owl_run

parser = argparse.ArgumentParser(
description=main.__doc__,
Expand Down Expand Up @@ -43,24 +52,31 @@ def main(args: list = 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(args)
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)
Loading