Skip to content

Commit

Permalink
Merge branch 'master' into add-figures-to-generated-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis authored Nov 6, 2024
2 parents 65b2fa6 + 420c9e5 commit e41770a
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 344 deletions.
32 changes: 27 additions & 5 deletions .github/workflows/cd_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ on:
types: [published]

jobs:
publish:
build:
name: External
uses: SINTEF/ci-cd/.github/workflows/cd_release.yml@v2.7.4
uses: SINTEF/ci-cd/.github/workflows/cd_release.yml@v2.8.3
if: github.repository == 'emmo-repo/EMMOntoPy' && startsWith(github.ref, 'refs/tags/v')
with:
git_username: EMMOntoPy Developers
Expand All @@ -21,8 +21,11 @@ jobs:
# ontopy/__init__.py
package_dirs: ontopy
install_extras: "[dev]"
build_cmd: "python -m build"
publish_on_pypi: true
build_libs: build
build_cmd: "python -m build -o dists"
build_dir: dists
publish_on_pypi: false
upload_distribution: true

# Update documentation
update_docs: true
Expand All @@ -31,5 +34,24 @@ jobs:
changelog_exclude_labels: dependencies

secrets:
PyPI_token: ${{ secrets.PYPI_TOKEN }}
PAT: ${{ secrets.RELEASE_PAT }}

publish:
name: Publish on PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/project/EMMOntoPy
permissions:
id-token: write

steps:
- name: Download distribution
uses: actions/download-artifact@v4
with:
name: dist # The artifact will always be called 'dist'
path: dist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion .github/workflows/ci_automerge_dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
update-dependabot-branch:
name: External
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.7.4
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.8.3
if: github.repository_owner == 'emmo-repo' && startsWith(github.event.pull_request.head.ref, 'dependabot/') && github.actor == 'dependabot[bot]'
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
4 changes: 3 additions & 1 deletion .github/workflows/ci_cd_updated_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
updates-to-master:
name: External
uses: SINTEF/ci-cd/.github/workflows/ci_cd_updated_default_branch.yml@v2.7.4
uses: SINTEF/ci-cd/.github/workflows/ci_cd_updated_default_branch.yml@v2.8.3
if: github.repository_owner == 'emmo-repo'
with:
git_username: EMMOntoPy Developers
Expand All @@ -29,3 +29,5 @@ jobs:
(LICENSE.txt),(LICENSE.md)
(tools),(../tools)
changelog_exclude_labels: dependencies
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
2 changes: 1 addition & 1 deletion .github/workflows/ci_dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
create-collected-pr:
name: External
uses: SINTEF/ci-cd/.github/workflows/ci_update_dependencies.yml@v2.7.4
uses: SINTEF/ci-cd/.github/workflows/ci_update_dependencies.yml@v2.8.3
if: github.repository_owner == 'emmo-repo'
with:
git_username: EMMOntoPy Developers
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
tests:
name: External
uses: SINTEF/ci-cd/.github/workflows/ci_tests.yml@v2.7.4
uses: SINTEF/ci-cd/.github/workflows/ci_tests.yml@v2.8.3
with:
# General
install_extras: "[dev,docs]"
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-symlinks
- id: check-xml
Expand All @@ -17,13 +17,13 @@ repos:
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/ambv/black
rev: 24.4.2
rev: 24.10.0
hooks:
- id: black
name: Blacken

- repo: https://github.com/PyCQA/bandit
rev: '1.7.9'
rev: '1.7.10'
hooks:
- id: bandit
args: [-r]
Expand All @@ -36,7 +36,7 @@ repos:
# exclude: ^tests/.*$

- repo: https://github.com/SINTEF/ci-cd
rev: v2.7.4
rev: v2.8.3
hooks:
- id: docs-api-reference
args:
Expand Down
401 changes: 82 additions & 319 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ontopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# pylint: disable=wrong-import-position,wrong-import-order
import sys

__version__ = "0.7.1"
__version__ = "0.7.2"

# Ensure correct Python version
if sys.version_info < (3, 7):
Expand Down
31 changes: 29 additions & 2 deletions ontopy/excelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ExcelError(EMMOntoPyException):

def create_ontology_from_excel( # pylint: disable=too-many-arguments, too-many-locals
excelpath: str,
*,
concept_sheet_name: str = "Concepts",
metadata_sheet_name: str = "Metadata",
imports_sheet_name: str = "ImportedOntologies",
Expand Down Expand Up @@ -290,7 +291,7 @@ def _relative_to_absolute_paths(path):
)


def create_ontology_from_pandas( # pylint:disable=too-many-locals,too-many-branches,too-many-statements,too-many-arguments
def create_ontology_from_pandas( # pylint:disable=too-many-locals,too-many-branches,too-many-statements,too-many-arguments, too-many-positional-arguments
data: pd.DataFrame,
objectproperties: pd.DataFrame,
annotationproperties: pd.DataFrame,
Expand All @@ -312,6 +313,15 @@ def create_ontology_from_pandas( # pylint:disable=too-many-locals,too-many-bran
if input_ontology:
onto = input_ontology
catalog = {}
# Since we will remove newly created python_name added
# by owlready2 in the triples, we keep track of those
# that come from the input ontology
pyname_triples_to_keep = list(
onto.get_unabbreviated_triples(
predicate="http://www.lesfleursdunormal.fr/static/_downloads/"
"owlready_ontology.owl#python_name"
)
)
else: # Create new ontology
onto, catalog = get_metadata_from_dataframe(
metadata, base_iri, imports=imports
Expand Down Expand Up @@ -455,6 +465,22 @@ def create_ontology_from_pandas( # pylint:disable=too-many-locals,too-many-bran
entities_with_errors = {
key: set(value) for key, value in entities_with_errors.items()
}

# Remove triples with predicate 'python_name' added by owlready2
onto._del_data_triple_spod( # pylint: disable=protected-access
p=onto._abbreviate( # pylint: disable=protected-access
"http://www.lesfleursdunormal.fr/static/_downloads/"
"owlready_ontology.owl#python_name"
)
)

# Add back the triples python name triples that were in the input_ontology.
if input_ontology:
for triple in pyname_triples_to_keep:
onto._add_data_triple_spod( # pylint: disable=protected-access
s=triple[0], p=triple[1], o=triple[2]
)

return onto, catalog, entities_with_errors


Expand Down Expand Up @@ -585,6 +611,7 @@ def _add_literal( # pylint: disable=too-many-arguments
data: Union[pd.DataFrame, pd.Series],
destination: owlready2.prop.IndividualValueList, #
name: str,
*,
metadata: bool = False,
only_one: bool = False,
sep: str = ";",
Expand Down Expand Up @@ -903,7 +930,7 @@ def _add_range_domain(
return onto, properties_with_errors


def _make_entity_list( # pylint: disable=too-many-arguments
def _make_entity_list( # pylint: disable=too-many-arguments, too-many-positional-arguments
onto: owlready2.Ontology,
row: pd.Series,
rowheader: str,
Expand Down
9 changes: 8 additions & 1 deletion ontopy/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-locals
self,
ontology,
root=None,
*,
leaves=None,
entities=None,
relations="isA",
Expand Down Expand Up @@ -296,7 +297,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-locals
elif root:
self.add_branch(
root,
leaves,
leaves=leaves,
relations=relations,
edgelabels=edgelabels,
addnodes=addnodes,
Expand Down Expand Up @@ -326,6 +327,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-locals
def add_entities( # pylint: disable=too-many-arguments
self,
entities=None,
*,
relations="isA",
edgelabels=None,
addnodes=False,
Expand Down Expand Up @@ -353,6 +355,7 @@ def add_entities( # pylint: disable=too-many-arguments
def add_branch( # pylint: disable=too-many-arguments,too-many-locals
self,
root,
*,
leaves=None,
include_leaves=True,
strict_leaves=False,
Expand Down Expand Up @@ -427,6 +430,7 @@ def add_branch( # pylint: disable=too-many-arguments,too-many-locals
def add_parents( # pylint: disable=too-many-arguments
self,
name,
*,
levels=1,
relations="isA",
edgelabels=None,
Expand Down Expand Up @@ -522,6 +526,7 @@ def add_edge(self, subject, predicate, obj, edgelabel=None, **attrs):
def add_source_edges( # pylint: disable=too-many-arguments,too-many-branches
self,
source,
*,
relations=None,
edgelabels=None,
addnodes=None,
Expand Down Expand Up @@ -607,6 +612,7 @@ def add_source_edges( # pylint: disable=too-many-arguments,too-many-branches

def add_edges( # pylint: disable=too-many-arguments
self,
*,
sources=None,
relations=None,
edgelabels=None,
Expand Down Expand Up @@ -998,6 +1004,7 @@ def setmodules(onto):
def plot_modules( # pylint: disable=too-many-arguments
src,
filename=None,
*,
fmt=None,
show=False,
strip_base=None,
Expand Down
6 changes: 5 additions & 1 deletion ontopy/ontodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ def __init__( # pylint: disable=too-many-arguments
template,
ontodoc,
basedir=".",
*,
figdir="genfigs",
figformat="png",
figscale=1.0,
Expand Down Expand Up @@ -756,7 +757,7 @@ def process_branches(self):
branch, int(opts.header_level) # pylint: disable=no-member
).split("\n")

def _make_branchfig( # pylint: disable=too-many-arguments,too-many-locals
def _make_branchfig( # pylint: disable=too-many-arguments,too-many-locals, too-many-positional-arguments
self,
name: str,
path: "Union[Path, str]",
Expand Down Expand Up @@ -1142,6 +1143,7 @@ def process(self):
def write( # pylint: disable=too-many-arguments
self,
outfile,
*,
fmt=None,
pandoc_option_files=(),
pandoc_options=(),
Expand Down Expand Up @@ -1288,6 +1290,7 @@ def run_pandoc( # pylint: disable=too-many-arguments
genfile,
outfile,
fmt,
*,
pandoc_option_files=(),
pandoc_options=(),
verbose=True,
Expand Down Expand Up @@ -1444,6 +1447,7 @@ def get_maxwidth(fmt):
def get_docpp( # pylint: disable=too-many-arguments
ontodoc,
infile,
*,
figdir="genfigs",
figformat="png",
maxwidth=None,
Expand Down
8 changes: 8 additions & 0 deletions ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def get_unabbreviated_triples(
):
# pylint: disable=invalid-name
"""Returns all triples unabbreviated.
Imported ontologies not included.
If any of the `subject`, `predicate` or `obj` arguments are given,
only matching triples will be returned.
Expand Down Expand Up @@ -311,6 +312,7 @@ def set_default_label_annotations(self):
def get_by_label(
self,
label: str,
*,
label_annotations: str = None,
prefix: str = None,
imported: bool = True,
Expand Down Expand Up @@ -586,6 +588,7 @@ def set_common_prefix(

def load( # pylint: disable=too-many-arguments,arguments-renamed
self,
*,
only_local=False,
filename=None,
format=None, # pylint: disable=redefined-builtin
Expand Down Expand Up @@ -677,6 +680,7 @@ def load( # pylint: disable=too-many-arguments,arguments-renamed

def _load( # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
self,
*,
only_local=False,
filename=None,
format=None, # pylint: disable=redefined-builtin
Expand Down Expand Up @@ -864,6 +868,7 @@ def save(
filename=None,
format=None,
dir=".",
*,
mkdir=False,
overwrite=False,
recursive=False,
Expand Down Expand Up @@ -1128,6 +1133,7 @@ def rec_imported(onto, imported):

def get_entities( # pylint: disable=too-many-arguments
self,
*,
imported=True,
classes=True,
individuals=True,
Expand Down Expand Up @@ -1537,6 +1543,7 @@ def get_branch( # pylint: disable=too-many-arguments
root,
leaves=(),
include_leaves=True,
*,
strict_leaves=False,
exclude=None,
sort=False,
Expand Down Expand Up @@ -2151,6 +2158,7 @@ def _get_unabbreviated_triples(
onto, subject=None, predicate=None, obj=None, blank=None
):
"""Help function returning all matching triples unabbreviated.
Does not include imported ontologies.
If `blank` is given, it will be used to represent blank nodes.
"""
Expand Down
2 changes: 2 additions & 0 deletions ontopy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class ReadCatalogError(IOError):

def read_catalog( # pylint: disable=too-many-locals,too-many-statements,too-many-arguments
uri,
*,
catalog_file="catalog-v001.xml",
baseuri=None,
recursive=False,
Expand Down Expand Up @@ -602,6 +603,7 @@ def _validate_installed_version(
def convert_imported( # pylint: disable=too-many-arguments,too-many-locals
input_ontology: "Union[Path, str]",
output_ontology: "Union[Path, str]",
*,
input_format: "Optional[str]" = None,
output_format: str = "xml",
url_from_catalog: "Optional[bool]" = None,
Expand Down
Loading

0 comments on commit e41770a

Please sign in to comment.