Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmungall committed Mar 30, 2023
1 parent 61ccfee commit 3118747
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 88 deletions.
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = "LinkML Authors"


autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"

# -- General configuration ---------------------------------------------------

Expand Down Expand Up @@ -65,8 +65,8 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"
html_theme = "alabaster"
# html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
10 changes: 2 additions & 8 deletions src/semdsl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
"""semdsl package."""
import importlib_metadata
__version__ = "0.0.0"

try:
__version__ = importlib_metadata.version(__name__)
except importlib_metadata.PackageNotFoundError:
# package is not installed
__version__ = "0.0.0" # pragma: no cover

from semdsl.datamodel.semdsl_model import *
from semdsl.datamodel.semdsl_model import SchemaGrammar
from semdsl.dsl_engine import DSLEngine

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion src/semdsl/dsl_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
from pathlib import Path
from types import ModuleType
from typing import Any, Optional, TextIO, Type, Union
from typing import Optional, TextIO, Type, Union

import yaml
from lark import Tree
Expand Down
9 changes: 2 additions & 7 deletions src/semdsl/importers/importer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import sys
from abc import abstractmethod
from dataclasses import dataclass, field
from io import StringIO
from types import ModuleType
from typing import Any, TextIO

from linkml_runtime.utils.compile_python import compile_python
from dataclasses import dataclass
from typing import Any

from semdsl.datamodel.semdsl_model import SchemaGrammar

Expand Down
3 changes: 1 addition & 2 deletions src/semdsl/importers/schema_importer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from copy import copy
from dataclasses import dataclass
from io import StringIO
from typing import List, Optional, TextIO, Union
Expand Down Expand Up @@ -188,7 +187,7 @@ def _add_enum(self, sg: SchemaGrammar, enum: EnumDefinition):
sym = self._enum_symbol(enum.name)
rule = ProductionRule(is_terminal=True, lhs_symbol=sym)
disj = Disjunction(operands=[])
for text, pv in enum.permissible_values.items():
for text in enum.permissible_values.keys():
seq = AtomicSequence(elements=[])
self._add_terminal(seq, text)
disj.operands.append(seq)
Expand Down
3 changes: 1 addition & 2 deletions src/semdsl/mapper/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from linkml_runtime.linkml_model import SlotDefinition

from semdsl.datamodel.semdsl_model import AtomicSequence, Disjunction, SchemaGrammar
from semdsl.view.view import rule_by_non_terminal, rule_lhs_symbol
from semdsl.view.view import rule_lhs_symbol

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,7 +54,6 @@ def transform(
if tgt_class not in sv.all_classes():
raise ValueError(f"Unknown class {tgt_class}")
target = tgt_class
rule = rule_by_non_terminal(self.schemagrammar, token.value)
is_object = (
tgt_class and not class_defs[tgt_class].abstract and not class_defs[tgt_class].mixin
)
Expand Down
6 changes: 3 additions & 3 deletions src/semdsl/view/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def rule_lhs_symbol(rule: ProductionRule) -> Optional[str]:
def _sequence_lhs_symbol(sequence: Sequence) -> Optional[str]:
if isinstance(sequence, Disjunction):
if len(sequence.operands) != 1:
raise ValueError(f"Disjunction {sequence} must have exactly one operand; in {rule}")
raise ValueError(f"Disjunction {sequence} must have exactly one operand")
return lhs_symbol(sequence.operands[0])
if isinstance(sequence, AtomicSequence):
if len(sequence.elements) != 1:
raise ValueError(f"AtomicSequence {sequence} must have exactly one element; in {rule}")
raise ValueError(f"AtomicSequence {sequence} must have exactly one element")
el = sequence.elements[0]
if not isinstance(el, NonTerminal):
raise ValueError(
f"AtomicSequence {sequence} must have exactly one NonTerminal element; in {rule}"
f"AtomicSequence {sequence} must have exactly one NonTerminal element"
)
return el.name
raise AssertionError(f"Unexpected sequence type {type(sequence)}")
2 changes: 0 additions & 2 deletions src/semdsl/writers/lark_writer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from dataclasses import dataclass
from typing import Union

from linkml_runtime.utils.compile_python import compile_python

from semdsl.datamodel.semdsl_model import (
AtomicSequence,
Disjunction,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from linkml_runtime import SCHEMA_DIRECTORY, SchemaView

from semdsl.cli import main
from tests import EXAMPLE_CLUE_DIR, EXAMPLE_DIR, OUTPUT_DIR
from tests import OUTPUT_DIR
from tests.input.examples.arithmetic import ARITHMETIC_DSL, ARITHMETIC_EXAMPLE, ARITHMETIC_MODEL
from tests.input.examples.clue import CLUE_MODEL
from tests.input.examples.linkml_lite import LINKML_DSL, LINKML_EXAMPLE
Expand Down
2 changes: 1 addition & 1 deletion tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lark import Token
from linkml_runtime import SchemaView

from semdsl.datamodel.semdsl_model import AtomicSequence, ProductionRule, SchemaGrammar
from semdsl.datamodel.semdsl_model import SchemaGrammar
from semdsl.dsl_engine import DSLEngine
from semdsl.mapper.mapper import Mapper
from semdsl.writers.lark_writer import LarkWriter
Expand Down
5 changes: 3 additions & 2 deletions tests/test_importers/test_schema_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import unittest

from lark import UnexpectedCharacters, UnexpectedToken

from semdsl import DSLEngine
from tests import EXAMPLE_DIR
from tests.input.examples.arithmetic import ARITHMETIC_MODEL

CLUE_SCHEMA = """
Expand Down Expand Up @@ -85,7 +86,7 @@ def test_schema_guided(self):
for case in cases:
passes, ser, target_class, expected = case
if not passes:
with self.assertRaises(Exception):
with self.assertRaises((UnexpectedCharacters, UnexpectedToken)) :
obj = engine.parse_as_object(ser, target_class=target_class)
continue
obj = engine.parse_as_object(ser, target_class=target_class)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_importers/test_schema_importer_metamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def test_model(self):
mod = writer.compile(sg)
print(f"Compiled to {mod}")
mapper = Mapper(schemaview=self.schemaview, schemagrammar=sg)
print("Parsing: SchemaDefinition(id=x name=y)")
print(mapper)
tree = mod.grammar.parse("SchemaDefinition(id=x name=y)")
# print(tree.pretty())
print(tree.pretty())
95 changes: 42 additions & 53 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,41 @@
# and then run "tox" from this directory.

[tox]
# To use a PEP 517 build-backend you are required to configure tox to use an isolated_build:
# https://tox.readthedocs.io/en/latest/example/package.html
isolated_build = True
skipsdist = True

isolated_build = true
envlist =
# always keep coverage-clean first
coverage-clean
lint
flake8
mypy
docstr-coverage
py

[testenv]
whitelist_externals =
poetry
commands =
poetry run pytest
description = Run unit tests with pytest. This is a special environment that does not get a name, and
can be referenced with "py".

[testenv:coverage-clean]
deps = coverage
skip_install = true
commands = coverage erase
coverage run -p -m pytest --durations=20 {posargs:tests}
coverage combine
coverage xml
deps =
pytest
coverage

[testenv:lint]
deps =
black
isort
skip_install = true
commands =
black src/ tests/
isort src/ tests/
black .
isort .
description = Run linters.

[testenv:doclint]
deps =
rstfmt
skip_install = true
commands =
rstfmt docs/source/
description = Run documentation linters.

[testenv:flake8]
skip_install = true
deps =
darglint
flake8<5.0.0
flake8-black
flake8-bandit
flake8-black
flake8-bugbear
flake8-colors
flake8-docstrings
flake8-isort
flake8-print
pydocstyle
pep8-naming
commands =
flake8 src/ tests/
description = Run the flake8 tool with several plugins (bandit, docstrings, import order, pep8 naming).
Expand All @@ -72,22 +49,34 @@ description = Run the flake8 tool with several plugins (bandit, docstrings, impo
#########################
[flake8]
ignore =
DAR101 # Missing parameter(s) in Docstring: - with_git_hash
DAR201 # Missing "Returns" in Docstring: - return
DAR301 # Missing "Yields" in Docstring: - yield
E111 # indentation is not a multiple of 4
T201 # print found.

[testenv:mypy]
deps = mypy
skip_install = true
commands = mypy --install-types --non-interactive --ignore-missing-imports src/
description = Run the mypy tool to check static typing on the project.

[testenv:docstr-coverage]
skip_install = true
deps =
docstr-coverage
commands =
docstr-coverage src/ tests/ --skip-private --skip-magic
description = Run the docstr-coverage tool to check documentation coverage
E203
W503
C901 # needs code change so ignoring for now.
E731 # needs code change so ignoring for now.
S101 # asserts are fine
S106 # flags false positives with test_table_filler
N801 # mixed case is bad but there's a lot of auto-generated code
N815 # same ^
S404 # Consider possible security implications associated with the subprocess module.
S108 # Probable insecure usage of temp file/directory.
S307 # Use of possibly insecure function - consider using safer ast.literal_eval.
S603 # subprocess call - check for execution of untrusted input.
S607 # Starting a process with a partial executable path ["open" in both cases]
S608 # Possible SQL injection vector through string-based query construction.
B024 # StreamingWriter is an abstract base class, but it has no abstract methods.
# Remember to use @abstractmethod, @abstractclassmethod and/or @abstractproperty decorators.
B027 # empty method in an abstract base class, but has no abstract decorator. Consider adding @abstractmethod
N803 # math-oriented classes can ignore this (e.g. hypergeometric.py)
N806 # math-oriented classes can ignore this (e.g. hypergeometric.py)
B019
S113 # new check - deal with this later

max-line-length = 120
max-complexity = 13
import-order-style = pycharm
application-import-names =
semdsl
tests
exclude =
datamodel ## datamodels are auto-generated
tests/input/examples

0 comments on commit 3118747

Please sign in to comment.