diff --git a/.github/workflows/cd_publish.yml b/.github/workflows/cd_publish.yml index 18b58ca54..6491ad4d7 100644 --- a/.github/workflows/cd_publish.yml +++ b/.github/workflows/cd_publish.yml @@ -4,121 +4,32 @@ on: release: types: [published] -env: - PUBLISH_UPDATE_BRANCH: master - GIT_USER_NAME: EMMOntoPy Developers - GIT_USER_EMAIL: "Team4.0@SINTEF.no" - jobs: - update-and-publish: - name: Update CHANGELOG and documentation - if: github.repository == 'emmo-repo/EMMOntoPy' - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Python 3.7 - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel - pip install -U -e .[dev] - - - name: Set up git user - run: | - git config --global user.name "${GIT_USER_NAME}" - git config --global user.email "${GIT_USER_EMAIL}" - - - name: Update changelog - uses: CharMixer/auto-changelog-action@v1 - with: - token: ${{ secrets.RELEASE_PAT }} - release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }} - - - name: Update version and tag - run: | - invoke setver --ver="${GITHUB_REF#refs/tags/}" - git add ontopy/__init__.py CHANGELOG.md - git commit -m "Release ${GITHUB_REF#refs/tags/}" - - TAG_MSG=.github/utils/release_tag_msg.txt - sed -i "s|TAG_NAME|${GITHUB_REF#refs/tags/}|" "${TAG_MSG}" - git tag -af -F "${TAG_MSG}" ${GITHUB_REF#refs/tags/} - - - name: Push new commit and update tag - uses: CasperWA/push-protected@v2 - with: - token: ${{ secrets.RELEASE_PAT }} - branch: ${{ env.PUBLISH_UPDATE_BRANCH }} - force: true - tags: true - unprotect_reviews: true - - - name: Get tagged versions - run: echo "PREVIOUS_VERSION=$(git tag -l --sort -version:refname | grep -E "^v0\.[1-8].*$" | sed -n 2p)" >> $GITHUB_ENV - - - name: Create release-specific changelog - uses: CharMixer/auto-changelog-action@v1 - with: - token: ${{ secrets.RELEASE_PAT }} - release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }} - since_tag: "${{ env.PREVIOUS_VERSION }}" - output: "release_changelog.md" - - - name: Append changelog to release body - run: | - gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} --jq '.body' > release_body.md - cat release_changelog.md >> release_body.md - gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} -X PATCH -F body='@release_body.md' - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }} - - - name: Build source and built distributions - run: python setup.py sdist bdist_wheel - - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} - - deploy-docs: - name: Deploy new documentation - runs-on: ubuntu-latest - needs: update-and-publish - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - ref: ${{ env.PUBLISH_UPDATE_BRANCH }} - - - name: Set up Python 3.7 - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel - pip install -U -e .[docs] - - - name: Set up git user - run: | - git config --global user.name "${{ env.GIT_USER_NAME }}" - git config --global user.email "${{ env.GIT_USER_EMAIL }}" - - - name: Deploy documentation - run: | - mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml ${GITHUB_REF#refs/tags/v} stable - mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest ${{ env.PUBLISH_UPDATE_BRANCH }} + publish: + name: External + uses: SINTEF/ci-cd/.github/workflows/cd_release.yml@v1 + if: github.repository == 'emmo-repo/EMMOntoPy' && startsWith(github.ref, 'refs/tags/v') + with: + git_username: EMMOntoPy Developers + git_email: "Team4.0@SINTEF.no" + release_branch: master + + # Publish package + python_package: true + python_version_build: "3.7" + # We're mentioning only 'ontopy', since the version is set statically only in + # ontopy/__init__.py + package_dirs: ontopy + install_extras: "[dev]" + build_cmd: "python -m build" + publish_on_pypi: true + + # Update documentation + update_docs: true + python_version_docs: "3.7" + doc_extras: "[docs]" + changelog_exclude_labels: dependencies + + secrets: + PyPI_token: ${{ secrets.PYPI_TOKEN }} + PAT: ${{ secrets.RELEASE_PAT }} diff --git a/.github/workflows/ci_automerge_dependabot.yml b/.github/workflows/ci_automerge_dependabot.yml index 2ab15f7cd..d241f92f8 100644 --- a/.github/workflows/ci_automerge_dependabot.yml +++ b/.github/workflows/ci_automerge_dependabot.yml @@ -6,25 +6,8 @@ on: jobs: update-dependabot-branch: - name: Update permanent dependabot branch + name: External + uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v1 if: github.repository_owner == 'emmo-repo' && startsWith(github.event.pull_request.head.ref, 'dependabot/') && github.actor == 'dependabot[bot]' - runs-on: ubuntu-latest - - env: - DEPENDABOT_BRANCH: ci/dependabot-updates - GIT_USER_NAME: EMMOntoPy Developers - GIT_USER_EMAIL: "Team4.0@SINTEF.no" - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - ref: ${{ github.event.pull_request.head.ref }} - - - name: Activate auto-merge - run: | - PR_ID="$(gh api graphql -F owner='{owner}' -F name='{repo}' -f query='query($owner: String!, $name: String!) {repository(owner: $owner, name: $name) {pullRequest(number: ${{ github.event.pull_request.number }}) {id}}}' --jq '.data.repository.pullRequest.id')" - gh api graphql -f pr_id="$PR_ID" -f query='mutation($pr_id: ID!) {enablePullRequestAutoMerge(input:{mergeMethod:SQUASH,pullRequestId:$pr_id }) {pullRequest {number}}}' - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }} + secrets: + PAT: ${{ secrets.RELEASE_PAT }} diff --git a/.github/workflows/ci_cd_updated_master.yml b/.github/workflows/ci_cd_updated_master.yml index d9607ee29..812b92c27 100644 --- a/.github/workflows/ci_cd_updated_master.yml +++ b/.github/workflows/ci_cd_updated_master.yml @@ -4,122 +4,28 @@ on: push: branches: [master] -env: - DEPENDABOT_BRANCH: ci/dependabot-updates - GIT_USER_NAME: EMMOntoPy Developers - GIT_USER_EMAIL: "Team4.0@SINTEF.no" - DEFAULT_REPO_BRANCH: master - jobs: - update-dependabot-branch: - name: Update permanent dependabot branch - if: github.repository_owner == 'emmo-repo' - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - ref: ${{ env.DEPENDABOT_BRANCH }} - fetch-depth: 0 - - - name: Set up git config - run: | - git config --global user.name "${{ env.GIT_USER_NAME }}" - git config --global user.email "${{ env.GIT_USER_EMAIL }}" - - - name: Update '${{ env.DEPENDABOT_BRANCH }}' - run: | - git fetch origin - - LATEST_PR_BODY="$(gh api /repos/${{ github.repository}}/pulls -X GET -f state=closed -f per_page=1 -f sort=updated -f direction=desc --jq '.[].body')" - cat .github/utils/single_dependency_pr_body.txt | head -8 > .tmp_file.txt - if [ -z "$(printf '%s\n' "${LATEST_PR_BODY}" | head -8 | diff - .tmp_file.txt --strip-trailing-cr)" ]; then - # The dependency branch has just been merged into `${{ env.DEFAULT_REPO_BRANCH }}` - # The dependency branch should be reset to `${{ env.DEFAULT_REPO_BRANCH }}` - echo "The dependencies have just been updated! Reset to ${{ env.DEFAULT_REPO_BRANCH }}." - git reset --hard origin/${{ env.DEFAULT_REPO_BRANCH }} - echo "FORCE_PUSH=yes" >> $GITHUB_ENV - else - # Normal procedure: Merge `${{ env.DEFAULT_REPO_BRANCH }}` into `${{ env.DEPENDABOT_BRANCH }}` - echo "Merge new updates to ${{ env.DEFAULT_REPO_BRANCH }} into ${{ env.DEPENDABOT_BRANCH }}" - git merge -m "Keep '${{ env.DEPENDABOT_BRANCH }}' up-to-date with '${{ env.DEFAULT_REPO_BRANCH }}'" origin/${{ env.DEFAULT_REPO_BRANCH }} - echo "FORCE_PUSH=no" >> $GITHUB_ENV - fi - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Push to '${{ env.DEPENDABOT_BRANCH }}' - uses: CasperWA/push-protected@v2 - with: - token: ${{ secrets.RELEASE_PAT }} - branch: ${{ env.DEPENDABOT_BRANCH }} - sleep: 15 - force: ${{ env.FORCE_PUSH }} - - deploy-docs: - name: Deploy `latest` documentation + updates-to-master: + name: External + uses: SINTEF/ci-cd/.github/workflows/ci_cd_updated_default_branch.yml@v1 if: github.repository_owner == 'emmo-repo' - runs-on: ubuntu-latest - - steps: - - name: Release check - run: | - COMMIT_MSG="$(gh api /repos/${{ github.repository}}/commits/${{ env.DEFAULT_REPO_BRANCH }} --jq '.commit.message')" - if [[ "${COMMIT_MSG}" =~ ^Release\ v.*$ ]]; then - echo "In a release - do not run this job !" - echo "RELEASE_RUN=true" >> $GITHUB_ENV - else - echo "Not a release - update docs" - echo "RELEASE_RUN=false" >> $GITHUB_ENV - fi - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Checkout repository - if: env.RELEASE_RUN == 'false' - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Python 3.7 - if: env.RELEASE_RUN == 'false' - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - - name: Install dependencies - if: env.RELEASE_RUN == 'false' - run: | - python -m pip install --upgrade pip - pip install -U setuptools wheel - pip install -U -e .[docs] - - - name: Set up git user - if: env.RELEASE_RUN == 'false' - run: | - git config --global user.name "${{ env.GIT_USER_NAME }}" - git config --global user.email "${{ env.GIT_USER_EMAIL }}" - - - name: Check API Reference and landing page - if: env.RELEASE_RUN == 'false' - run: | - invoke create-api-reference-docs --pre-clean - invoke create-docs-index - - if [ -n "$(git status --porcelain docs/api_reference docs/index.md)" ]; then - echo -e "\u274c Discrepancies found !" - echo -e "The following files in the documentation must be committed:" - git status --porcelain docs/api_reference docs/index.md - echo -e "\nRun:\n" - echo " invoke create-api-reference-docs --pre-clean" - echo -e " invoke create-docs-index\n" - echo "And commit the changed files." - exit 1 - else - echo -e "\u2705 All good !" - fi - - - name: Deploy documentation - if: env.RELEASE_RUN == 'false' - run: mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest ${{ env.DEFAULT_REPO_BRANCH }} + with: + git_username: EMMOntoPy Developers + git_email: "Team4.0@SINTEF.no" + permanent_dependencies_branch: ci/dependabot-updates + default_repo_branch: master + + # Update documentation + update_docs: true + update_python_api_ref: true + update_docs_landing_page: true + package_dirs: | + emmopy + ontopy + python_version: "3.7" + doc_extras: "[docs]" + special_file_api_ref_options: "emmopy/emmocheck.py,show_bases: false" + landing_page_replacements: | + (LICENSE.txt),(LICENSE.md) + (tools),(../tools) + changelog_exclude_labels: dependencies diff --git a/.github/workflows/ci_dependabot.yml b/.github/workflows/ci_dependabot.yml index f8285a34e..8c4b9d201 100644 --- a/.github/workflows/ci_dependabot.yml +++ b/.github/workflows/ci_dependabot.yml @@ -6,98 +6,23 @@ on: # Dependabot runs once a week (every Monday) (pip) # and every day (GH Actions) between 7:00 and 7:30 (5:00-5:30 UTC) - cron: "30 6 * * 3" + workflow_dispatch: jobs: create-collected-pr: - name: Single dependabot PR + name: External + uses: SINTEF/ci-cd/.github/workflows/ci_update_dependencies.yml@v1 if: github.repository_owner == 'emmo-repo' - runs-on: ubuntu-latest - env: - DEPENDABOT_BRANCH: ci/dependabot-updates - GIT_USER_NAME: EMMOntoPy Developers - GIT_USER_EMAIL: "Team4.0@SINTEF.no" - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - ref: master - - - name: Set up Python 3.8 - uses: actions/setup-python@v4 - with: - python-version: "3.8" - - - name: Install `pre-commit` and dependencies - run: | - python -m pip install -U pip - pip install -U setuptools wheel - - while IFS="" read -r line || [ -n "${line}" ]; do - if [[ "${line}" =~ ^pre-commit.*$ ]]; then - pre_commit="${line}" - fi - done < requirements_dev.txt - - while IFS="" read -r line || [ -n "${line}" ]; do - if [[ "${line}" =~ ^invoke.*$ ]]; then - invoke="${line}" - fi - done < requirements_docs.txt - - pip install ${pre_commit} ${invoke} - - - name: Set up git user info - run: | - git config --global user.name "${{ env.GIT_USER_NAME }}" - git config --global user.email "${{ env.GIT_USER_EMAIL }}" - - - name: Reset to '${{ env.DEPENDABOT_BRANCH }}' - run: | - git fetch origin ${{ env.DEPENDABOT_BRANCH }}:${{ env.DEPENDABOT_BRANCH }} - git reset --hard ${{ env.DEPENDABOT_BRANCH }} - - - name: Auto-update `pre-commit` hooks - run: | - pre-commit autoupdate - - if [ -n "$(git status --porcelain .pre-commit-config.yaml)" ]; then - # Set environment variable notifying next steps that the hooks changed - echo "Pre-commit hooks have been updated !" - echo "UPDATED_PRE_COMMIT_HOOKS=true" >> $GITHUB_ENV - else - echo "No pre-commit hooks have been updated." - echo "UPDATED_PRE_COMMIT_HOOKS=false" >> $GITHUB_ENV - fi - - - name: Possibly run `pre-commit` with updated hooks - if: env.UPDATED_PRE_COMMIT_HOOKS == 'true' - continue-on-error: true # Still create the PR if this step fails - run: SKIP=pylint pre-commit run --all-files - - - name: Possibly commit changes and updates - if: env.UPDATED_PRE_COMMIT_HOOKS == 'true' - run: git commit -am "Update \`pre-commit\` hooks" - - - name: Fetch PR body - id: pr_body - uses: chuhlomin/render-template@v1.5 - with: - template: .github/utils/single_dependency_pr_body.txt - - - name: Create PR - id: cpr - uses: peter-evans/create-pull-request@v4 - with: - token: ${{ secrets.RELEASE_PAT }} - commit-message: New @dependabot-fueled updates - committer: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>" - author: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>" - branch: ci/update-dependencies - delete-branch: true - title: "[Auto-generated] Update dependencies" - body: ${{ steps.pr_body.outputs.result }} - labels: dependencies,github_actions - - - name: Information - run: 'echo "${{ steps.cpr.outputs.pull-request-operation }} PR #${{ steps.cpr.outputs.pull-request-number }}: ${{ steps.cpr.outputs.pull-request-url }}"' + with: + git_username: EMMOntoPy Developers + git_email: "Team4.0@SINTEF.no" + permanent_dependencies_branch: ci/dependabot-updates + default_repo_branch: master + pr_labels: dependencies,github_actions + extra_to_dos: "- [ ] Make sure that the PR is **squash** merged, with a sensible commit message." + update_pre-commit: true + python_version: "3.8" + install_extras: "[dev,docs]" + skip_pre-commit_hooks: pylint + secrets: + PAT: ${{ secrets.RELEASE_PAT }} diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 4df49d1cc..48688f76a 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -8,89 +8,75 @@ on: - 'push-action/**' jobs: - - pre-commit: - name: pre-commit - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python 3.8 - uses: actions/setup-python@v4 - with: - python-version: "3.8" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -U setuptools wheel - - while IFS="" read -r line || [ -n "${line}" ]; do - if [[ "${line}" =~ ^pre-commit.*$ ]]; then - pre_commit="${line}" - fi - done < requirements_dev.txt - - while IFS="" read -r line || [ -n "${line}" ]; do - if [[ "${line}" =~ ^invoke.*$ ]]; then - invoke="${line}" - fi - done < requirements_docs.txt - - pip install ${pre_commit} ${invoke} - - - name: Run pre-commit - run: SKIP=pylint pre-commit run --all-files --show-diff-on-failure - - - pylint-safety: - name: PyLint and safety - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python 3.7 - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -U setuptools wheel - - pip install -U -r requirements.txt -r requirements_dev.txt -r requirements_docs.txt - pip install safety - - - name: Run PyLint - run: pylint --rcfile=pyproject.toml *.py tools emmopy ontopy - - # Ignore ID 44715 for now. - # See this NumPy issue for more information: https://github.com/numpy/numpy/issues/19038 - # Also ignore IDs 44716 and 44717 as they are not deemed to be as severe as it is - # laid out in the CVE. - # Remove ignoring 48547 as soon as RDFLib/rdflib#1844 has been fixed and the fix - # has been released. - - name: Run safety - run: pip freeze | safety check --stdin -i 44715 -i 44716 -i 44717 -i 48547 - - tests: + name: External + uses: SINTEF/ci-cd/.github/workflows/ci_tests.yml@v1 + with: + # General + install_extras: "[dev,docs]" + + # pre-commit + run_pre-commit: true + python_version_pre-commit: "3.8" + skip_pre-commit_hooks: pylint + + # pylint + run_pylint: true + python_version_pylint_safety: "3.7" + pylint_options: "--rcfile=pyproject.toml" + pylint_targets: "*.py tools emmopy ontopy" + + # safety + # Ignore ID 44715 for now. + # See this NumPy issue for more information: https://github.com/numpy/numpy/issues/19038 + # Also ignore IDs 44716 and 44717 as they are not deemed to be as severe as it is + # laid out in the CVE. + # Remove ignoring 48547 as soon as RDFLib/rdflib#1844 has been fixed and the fix + # has been released. + run_safety: true + safety_options: | + --ignore=44715 + --ignore=44716 + --ignore=44717 + --ignore=48547 + + # Build distribution + run_build_package: true + python_version_package: "3.7" + build_cmd: "python -m build" + + # Build documentation + # Exclude base classes in emmopy.emmocheck + run_build_docs: true + python_version_docs: "3.7" + update_python_api_ref: true + update_docs_landing_page: true + package_dirs: | + emmopy + ontopy + special_file_api_ref_options: "emmopy/emmocheck.py,show_bases: false" + landing_page_replacements: | + (LICENSE.txt),(LICENSE.md) + (tools),(../tools) + + + pytest: name: pytest runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] + steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up Python 3.7 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: ${{ matrix.python-version }} - name: Install system dependencies run: sudo apt-get update && sudo apt-get install -y graphviz openjdk-11-jre-headless @@ -99,11 +85,14 @@ jobs: run: | python -m pip install --upgrade pip pip install -U setuptools wheel - pip install -U -e .[dev] - - name: Test with pytest - run: pytest + - name: Test + run: pytest -vvv --cov=ontopy --cov=emmopy --cov-report=xml --cov-report=term + + - name: Upload coverage to Codecov + if: matrix.python-version == '3.7' && github.repository == 'emmo-repo/EMMOntoPy' + uses: codecov/codecov-action@v3 # - name: Run vertical demo # run: | @@ -131,7 +120,7 @@ jobs: - name: Set up Python 3.7 uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: "3.7" - name: Check Ubuntu version we are running under run: | @@ -175,106 +164,3 @@ jobs: # needs to be resolved if we decide to keep ontodoc as a tool. # python ../../tools/ontodoc -t emmo.md emmo-inferred emmo.pdf cd - - - - build_package: - name: Build Python package and install (integrity test) - runs-on: ubuntu-latest - env: - SDIST_DIR: sdist_action - BDIST_DIR: bdist_action - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python 3.7 - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - - name: Install Python dependencies - run: | - python -m pip install --upgrade pip - pip install -U setuptools wheel - pip install -r requirements.txt - - - name: Build source and built distributions - run: python setup.py sdist bdist_wheel - - - name: Check build and installation of PyPI source distribution - run: | - python setup.py -v sdist -d ${SDIST_DIR} bdist_wheel -d ${BDIST_DIR} - SDIST_FILE=$( ls ${SDIST_DIR}/ ) - echo "BDIST_FILE=$( ls ${BDIST_DIR}/ )" >> $GITHUB_ENV - ORIGINAL_PWD=$(pwd) - mkdir -p /tmp/installation_dir - cd /tmp/installation_dir - pip install ${ORIGINAL_PWD}/${SDIST_DIR}/${SDIST_FILE} - - - name: Remove installation again - run: pip uninstall -y EMMO - - - name: Install built distribution (wheel) - run: | - ORIGINAL_PWD=$(pwd) - - if [ "${ORIGINAL_PWD}" == "/tmp/installation_dir" ]; then echo "Wrong original dir: ${ORIGINAL_PWD}"; exit 1; fi - mkdir -p /tmp/installation_dir - cd /tmp/installation_dir - pip install ${ORIGINAL_PWD}/${BDIST_DIR}/${{ env.BDIST_FILE }} - - documentation: - name: Check documentation - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python 3.7 - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -U setuptools wheel - pip install -U -e .[docs] - - - name: Set up git user - run: | - git config --global user.name "EMMOntoPy Developers" - git config --global user.email "Team4.0@SINTEF.no" - - - name: Check API Reference and landing page - run: | - invoke create-api-reference-docs --pre-clean - invoke create-docs-index - - if [ -n "$(git status --porcelain docs/api_reference docs/index.md)" ]; then - echo -e "\u274c Discrepancies found !" - echo -e "The following files in the documentation must be committed:" - git status --porcelain docs/api_reference docs/index.md - echo -e "\nRun:\n" - echo " invoke create-api-reference-docs --pre-clean" - echo -e " invoke create-docs-index\n" - echo "And commit the changed files." - exit 1 - else - echo -e "\u2705 All good !" - fi - - - name: Build check - run: | - mkdocs build 2>build_out.txt - WARNING_LINES=$( cat build_out.txt | grep WARNING | wc -l ) - if [ ${WARNING_LINES} != 1 ]; then - echo -e "FAIL !\n\n" - cat build_out.txt - exit 1 - else - echo -e "Only 1 warning - that's workable :)\n\n" - cat build_out.txt - fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1740ae0a7..20702edf8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,24 +35,25 @@ repos: # - id: mypy # exclude: ^tests/.*$ -- repo: local +- repo: https://github.com/SINTEF/ci-cd + rev: b648cea02c07ef2c2a81b60696c0e3eb283fa3d0 # frozen: v1 hooks: - - id: update-docs-api-reference - name: Update API Reference in Documentation - entry: invoke - args: [create-api-reference-docs, --pre-clean, --pre-commit] - language: python - pass_filenames: false + - id: docs-api-reference + args: + - --package-dir=emmopy + - --package-dir=ontopy + - "--special-option=emmopy/emmocheck.py,show_bases: false" + - --unwanted-folder=__pycache__ + - --unwanted-folder=java files: ^(emmopy|ontopy)/.*\.py$ - description: Update the API Reference documentation, whenever a Python file is touched in the code base. - - id: update-docs-index - name: Update Landing Page for Documentation - entry: invoke - args: [create-docs-index] - language: python - pass_filenames: false + - id: docs-landing-page + args: + - --replacement=(LICENSE.txt),(LICENSE.md) + - --replacement=(tools),(../tools) files: ^README.md$ - description: Update the landing page for the documentation if the source file (README.md) is changed. + +- repo: local + hooks: - id: pylint name: pylint entry: pylint diff --git a/LICENSE.txt b/LICENSE.txt index 28550535c..2da9e5b92 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2019 SINTEF +Copyright 2019-2022 SINTEF Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are diff --git a/README.md b/README.md index 215dd96bb..f66709aa0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ + # EMMOntoPy *Python API for the Elemental Multiperspective Material Ontology ([EMMO]).* - - ![CI tests](https://github.com/emmo-repo/EMMOntoPy/workflows/CI%20Tests/badge.svg) [![PyPI version](https://badge.fury.io/py/EMMOntoPy.svg)](https://badge.fury.io/py/EMMOntoPy) @@ -98,12 +97,12 @@ pip install EMMOntoPy ### Required Dependencies -- [Python] 3.6 or later. +- [Python] 3.7 or later. - [Owlready2] v0.23 or later. ### Optional Dependencies -- [Graphviz]: Needed for graph generation. +- [Graphviz][graphviz_website]: Needed for graph generation. With support for generation pdf, png and svg figures for tests and generation of documentation automatically (`ontodoc`). - [pandoc]: Only used for generated documentation from markdown to nicely formatted html or pdf. Tested with v2.1.2. @@ -114,7 +113,7 @@ pip install EMMOntoPy Needed for reasoning. - Optional Python packages: - - [graphviz]: Generation of documentation and graphs. + - [graphviz][graphviz_python]: Generation of documentation and graphs. - [PyYAML]: Required for generating documentation with pandoc. - [blessings]: Clean output for `emmocheck`. - [Pygments]: Coloured output for `emmocheck`. @@ -144,9 +143,11 @@ It has mainly been developed by [SINTEF](https://www.sintef.no/), specifically: ### Contributing projects -- [EMMC-CSA](https://emmc.info/about-emmc-csa/); +- EMMC-CSA; Grant Agreement No: 723867 - + + + The [EMMC-ASBL organization](https://emmc.eu/emmc-members/mission/) takes on the efforts of continuing and expanding on the efforts of the CSA. - [MarketPlace](https://www.the-marketplace-project.eu/); Grant Agreement No: 760173 @@ -169,11 +170,11 @@ It has mainly been developed by [SINTEF](https://www.sintef.no/), specifically: [IPython]: https://ipython.org/ [DLite]: https://github.com/SINTEF/dlite/ [pydot]: https://pypi.org/project/pydot/ -[Graphviz]: https://www.graphviz.org/ +[graphviz_website]: https://www.graphviz.org/ [pandoc]: http://pandoc.org/ [XeLaTeX]: https://www.overleaf.com/learn/latex/XeLaTeX/ [pdfLaTeX]: https://www.latex-project.org/ -[graphviz]: https://pypi.org/project/graphviz +[graphviz_python]: https://pypi.org/project/graphviz [PyYAML]: https://pypi.org/project/PyYAML/ [blessings]: https://pypi.org/project/blessings/ [Pygments]: https://pypi.org/project/Pygments/ diff --git a/docs/api_reference/.pages b/docs/api_reference/.pages index a848e7c2f..9385270ba 100644 --- a/docs/api_reference/.pages +++ b/docs/api_reference/.pages @@ -1,2 +1 @@ title: "API Reference" -collapse_single_pages: false diff --git a/docs/api_reference/emmopy/.pages b/docs/api_reference/emmopy/.pages index 1f6fed708..3169cd7d4 100644 --- a/docs/api_reference/emmopy/.pages +++ b/docs/api_reference/emmopy/.pages @@ -1,2 +1 @@ title: "emmopy" -collapse_single_pages: false diff --git a/docs/api_reference/emmopy/emmocheck.md b/docs/api_reference/emmopy/emmocheck.md index 17c16dc05..6c9000f96 100644 --- a/docs/api_reference/emmopy/emmocheck.md +++ b/docs/api_reference/emmopy/emmocheck.md @@ -1,5 +1,5 @@ # emmocheck ::: emmopy.emmocheck - rendering: + options: show_bases: false diff --git a/docs/api_reference/ontopy/.pages b/docs/api_reference/ontopy/.pages index 01e236003..7e57e1f51 100644 --- a/docs/api_reference/ontopy/.pages +++ b/docs/api_reference/ontopy/.pages @@ -1,2 +1 @@ title: "ontopy" -collapse_single_pages: false diff --git a/docs/api_reference/ontopy/factpluspluswrapper/.pages b/docs/api_reference/ontopy/factpluspluswrapper/.pages index a117fa2ee..a90122175 100644 --- a/docs/api_reference/ontopy/factpluspluswrapper/.pages +++ b/docs/api_reference/ontopy/factpluspluswrapper/.pages @@ -1,2 +1 @@ title: "factpluspluswrapper" -collapse_single_pages: false diff --git a/docs/developers/release-instructions.md b/docs/developers/release-instructions.md index 9d8c7750f..c9f1b5e7c 100644 --- a/docs/developers/release-instructions.md +++ b/docs/developers/release-instructions.md @@ -2,15 +2,16 @@ 1. Create a release on GitHub with a short release description. - Ensure you add a `# ` title to the description. + Ensure you add a `# ` title to the description. + + Set the tag to the version number prefixed with `"v"` and title to the version number as explained above. - Set the tag to the version number prefixed with `"v"` and title to the version number as explained above. 1. Ensure the GitHub Action CD workflows run as expected. !!! danger "The workflow failed" - If something is wrong and the workflow fails **before** publishing the package to PyPI, make sure to remove all traces of the release and tag, fix the bug, and try again. + If something is wrong and the workflow fails **before** publishing the package to PyPI, make sure to remove all traces of the release and tag, fix the bug, and try again. - If something is wrong and the workflow fails **after** publishing the package to PyPI: **DO NOT REMOVE THE RELEASE OR TAG !** + If something is wrong and the workflow fails **after** publishing the package to PyPI: **DO NOT REMOVE THE RELEASE OR TAG !** - Deployment of the documentation should (in theory) be the only thing that has failed. - This can be deployed manually using similar steps as in the workflow. + Deployment of the documentation should (in theory) be the only thing that has failed. + This can be deployed manually using similar steps as in the workflow. diff --git a/docs/developers/setup.md b/docs/developers/setup.md index 7106a8b7b..3bf84a7df 100644 --- a/docs/developers/setup.md +++ b/docs/developers/setup.md @@ -7,7 +7,7 @@ This section outlines some suggestions as well as conventions used by the EMMOnt ## Setup !!! important "Requirements" - This section expects you to be running on a Unix-like system (e.g., Linux) with *minimum* Python 3.6. + This section expects you to be running on a Unix-like system (e.g., Linux) with *minimum* Python 3.7. ### Virtual environment diff --git a/docs/images/emmc_logo.png b/docs/images/emmc_logo.png new file mode 100644 index 000000000..4b3e69fbe Binary files /dev/null and b/docs/images/emmc_logo.png differ diff --git a/docs/index.md b/docs/index.md index e9830b24e..d6f5b8c42 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,11 +1,10 @@ + # EMMOntoPy *Python API for the Elemental Multiperspective Material Ontology ([EMMO]).* - - ![CI tests](https://github.com/emmo-repo/EMMOntoPy/workflows/CI%20Tests/badge.svg) [![PyPI version](https://badge.fury.io/py/EMMOntoPy.svg)](https://badge.fury.io/py/EMMOntoPy) @@ -98,12 +97,12 @@ pip install EMMOntoPy ### Required Dependencies -- [Python] 3.6 or later. +- [Python] 3.7 or later. - [Owlready2] v0.23 or later. ### Optional Dependencies -- [Graphviz]: Needed for graph generation. +- [Graphviz][graphviz_website]: Needed for graph generation. With support for generation pdf, png and svg figures for tests and generation of documentation automatically (`ontodoc`). - [pandoc]: Only used for generated documentation from markdown to nicely formatted html or pdf. Tested with v2.1.2. @@ -114,7 +113,7 @@ pip install EMMOntoPy Needed for reasoning. - Optional Python packages: - - [graphviz]: Generation of documentation and graphs. + - [graphviz][graphviz_python]: Generation of documentation and graphs. - [PyYAML]: Required for generating documentation with pandoc. - [blessings]: Clean output for `emmocheck`. - [Pygments]: Coloured output for `emmocheck`. @@ -144,9 +143,11 @@ It has mainly been developed by [SINTEF](https://www.sintef.no/), specifically: ### Contributing projects -- [EMMC-CSA](https://emmc.info/about-emmc-csa/); +- EMMC-CSA; Grant Agreement No: 723867 - + + + The [EMMC-ASBL organization](https://emmc.eu/emmc-members/mission/) takes on the efforts of continuing and expanding on the efforts of the CSA. - [MarketPlace](https://www.the-marketplace-project.eu/); Grant Agreement No: 760173 @@ -169,11 +170,11 @@ It has mainly been developed by [SINTEF](https://www.sintef.no/), specifically: [IPython]: https://ipython.org/ [DLite]: https://github.com/SINTEF/dlite/ [pydot]: https://pypi.org/project/pydot/ -[Graphviz]: https://www.graphviz.org/ +[graphviz_website]: https://www.graphviz.org/ [pandoc]: http://pandoc.org/ [XeLaTeX]: https://www.overleaf.com/learn/latex/XeLaTeX/ [pdfLaTeX]: https://www.latex-project.org/ -[graphviz]: https://pypi.org/project/graphviz +[graphviz_python]: https://pypi.org/project/graphviz [PyYAML]: https://pypi.org/project/PyYAML/ [blessings]: https://pypi.org/project/blessings/ [Pygments]: https://pypi.org/project/Pygments/ diff --git a/emmopy/__init__.py b/emmopy/__init__.py index a2e8df3f9..fa7822cb0 100644 --- a/emmopy/__init__.py +++ b/emmopy/__init__.py @@ -6,8 +6,8 @@ __version__ = __ontopy_version__ # Ensure correct Python version -if sys.version_info < (3, 6): - raise RuntimeError("emmopy requires Python 3.6 or later") +if sys.version_info < (3, 7): + raise RuntimeError("emmopy requires Python 3.7 or later") # Ensure emmopy is imported before owlready2... if "owlready2" in sys.modules and "emmopy" not in sys.modules: diff --git a/mkdocs.yml b/mkdocs.yml index ffee0b983..93a8beb1d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,7 +1,7 @@ site_name: EMMOntoPy site_description: Documentation for the EMMOntoPy library site_url: https://emmo-repo.github.io/EMMOntoPy -copyright: Copyright © 2019-2021 SINTEF +copyright: Copyright © 2019-2022 SINTEF theme: name: material @@ -17,6 +17,7 @@ theme: features: - navigation.instant - navigation.top + - content.tabs.link repo_name: EMMOntoPy repo_url: https://github.com/emmo-repo/EMMOntoPy @@ -40,7 +41,8 @@ markdown_extensions: - pymdownx.highlight - pymdownx.superfences - pymdownx.inlinehilite - - pymdownx.tabbed + - pymdownx.tabbed: + alternate_style: true - pymdownx.caret - pymdownx.tilde - pymdownx.keys @@ -69,18 +71,11 @@ plugins: - "!^_" - "^__init__$" members: null - # inherited_members: false + inherited_members: false docstring_style: google - # docstring_options: - # replace_admonitions: true - # setup_commands: - # - import os - # - os.environ["MKDOCS_BUILD"] = "1" - watch: - - emmopy - - ontopy - - awesome-pages: - collapse_single_pages: true + docstring_options: + replace_admonitions: true + - awesome-pages nav: - Home: index.md @@ -88,8 +83,17 @@ nav: - Docker: docker-instructions.md - License: LICENSE.md - Examples and demonstrations: - - ... | demo/** - - ... | examples/** + - Demo: + - demo/README.md + - demo/horizontal/README.md + - demo/vertical/README.md + - Examples: + - EMMOdoc: examples/emmodoc/README.md + - Jupyter visualization: examples/jupyter-visualization/README.md - ... | developers/** - Changelog: CHANGELOG.md - ... | api_reference/** + +watch: + - emmopy + - ontopy diff --git a/ontopy/__init__.py b/ontopy/__init__.py index 50b7cf870..b269a6411 100644 --- a/ontopy/__init__.py +++ b/ontopy/__init__.py @@ -5,8 +5,8 @@ __version__ = "0.4.0" # Ensure correct Python version -if sys.version_info < (3, 6): - raise RuntimeError("ontopy requires Python 3.6 or later") +if sys.version_info < (3, 7): + raise RuntimeError("ontopy requires Python 3.7 or later") # Ensure ontopy is imported before owlready2... if "owlready2" in sys.modules and "ontopy" not in sys.modules: diff --git a/requirements_dev.txt b/requirements_dev.txt index 60232ff5c..0a0daa7c7 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,3 +1,4 @@ pre-commit~=2.20 pylint~=2.15 pytest~=7.1 +pytest-cov~=4.0 diff --git a/requirements_docs.txt b/requirements_docs.txt index 2101caeed..c1170b8fe 100644 --- a/requirements_docs.txt +++ b/requirements_docs.txt @@ -1,6 +1,5 @@ -invoke~=1.7 mike~=1.1 mkdocs~=1.4 mkdocs-awesome-pages-plugin~=2.8 mkdocs-material~=8.5 -mkdocstrings[python]~=0.19.0 +mkdocstrings[python-legacy]~=0.19.0 diff --git a/setup.py b/setup.py index 858f091f0..b2d024b46 100644 --- a/setup.py +++ b/setup.py @@ -82,7 +82,7 @@ def fglob(patt): long_description_content_type="text/markdown", url="https://github.com/emmo-repo/EMMOntoPy", license="BSD", - python_requires=">=3.6.0", + python_requires=">=3.7", classifiers=[ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", @@ -91,8 +91,10 @@ def fglob(patt): "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Information Analysis", "Topic :: Scientific/Engineering :: Visualization", diff --git a/tasks.py b/tasks.py deleted file mode 100644 index 666fc569c..000000000 --- a/tasks.py +++ /dev/null @@ -1,207 +0,0 @@ -"""Repository management tasks powered by `invoke`. - -More information on `invoke` can be found at http://www.pyinvoke.org/. -""" -# pylint: disable=import-outside-toplevel,too-many-locals -import re -import sys -from typing import TYPE_CHECKING -from pathlib import Path - -from invoke import task - -if TYPE_CHECKING: - from typing import Tuple - - from invoke import Context, Result - - -TOP_DIR = Path(__file__).parent.resolve() - - -def update_file( - filename: str, sub_line: "Tuple[str, str]", strip: str = None -) -> None: - """Utility function for tasks to read, update, and write files""" - with open(filename, "r") as handle: - lines = [ - re.sub(sub_line[0], sub_line[1], line.rstrip(strip)) - for line in handle - ] - - with open(filename, "w") as handle: - handle.write("\n".join(lines)) - handle.write("\n") - - -@task(help={"ver": "EMMOntoPy version to set"}) -def setver(_, ver=""): - """Sets the EMMOntoPy version.""" - match = re.fullmatch( - ( - r"v?(?P[0-9]+(\.[0-9]+){2}" # Major.Minor.Patch - r"(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?" # pre-release - r"(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?)" # build metadata - ), - ver, - ) - if not match: - sys.exit( - "Error: Please specify version as " - "'Major.Minor.Patch(-Pre-Release+Build Metadata)' or " - "'vMajor.Minor.Patch(-Pre-Release+Build Metadata)'" - ) - ver = match.group("version") - - update_file( - TOP_DIR / "ontopy" / "__init__.py", - (r"__version__ = ('|\").*('|\")", f'__version__ = "{ver}"'), - ) - - print(f"Bumped version to {ver}") - - -@task( - help={ - "pre-clean": ( - "Remove the 'api_reference' sub directory prior to (re)creation." - ) - } -) -def create_api_reference_docs( - context, pre_clean=False, pre_commit=False -): # pylint: disable=too-many-branches - """Create the API Reference in the documentation""" - import os - import shutil - - def write_file(full_path: Path, content: str) -> None: - """Write file with `content` to `full_path`""" - if full_path.exists(): - with open(full_path, "r") as handle: - cached_content = handle.read() - if content == cached_content: - del cached_content - return - del cached_content - with open(full_path, "w") as handle: - handle.write(content) - - package_dirs = (TOP_DIR / "emmopy", TOP_DIR / "ontopy") - docs_api_ref_dir = TOP_DIR / "docs" / "api_reference" - - unwanted_subdirs = ("__pycache__",) - unwanted_files = ("__init__.py",) - - pages_template = 'title: "{name}"\ncollapse_single_pages: false\n' - md_template = "# {name}\n\n::: {py_path}\n" - - if docs_api_ref_dir.exists() and pre_clean: - shutil.rmtree(docs_api_ref_dir, ignore_errors=True) - if docs_api_ref_dir.exists(): - sys.exit(f"{docs_api_ref_dir} should have been removed!") - docs_api_ref_dir.mkdir(exist_ok=True) - - write_file( - full_path=docs_api_ref_dir / ".pages", - content=pages_template.format(name="API Reference"), - ) - library_dir = TOP_DIR - - for package_dir in package_dirs: - for dirpath, dirnames, filenames in os.walk(package_dir): - for unwanted_dir in unwanted_subdirs: - if unwanted_dir in dirnames: - # Avoid walking into or through unwanted directories - dirnames.remove(unwanted_dir) - - relpath = Path(dirpath).relative_to(library_dir) - - if not (relpath / "__init__.py").exists(): - # Avoid paths that are not included in the public Python API - continue - - # Create `.pages` - docs_sub_dir = docs_api_ref_dir / relpath - docs_sub_dir.mkdir(exist_ok=True) - if str(relpath) != ".": - write_file( - full_path=docs_sub_dir / ".pages", - content=pages_template.format( - name=str(relpath).rsplit("/", maxsplit=1)[-1] - ), - ) - - # Create markdown files - for filename in filenames: - if ( - re.match(r".*\.py$", filename) is None - or filename in unwanted_files - ): - # Not a Python file: We don't care about it! - # Or filename is in the tuple of unwanted files: - # We don't want it! - continue - - basename = filename[: -len(".py")] - py_path = ( - f"{relpath}/{basename}".replace("/", ".") - if str(relpath) != "." - else f"{basename}".replace("/", ".") - ) - md_filename = filename.replace(".py", ".md") - - # For emmopy.emmocheck we want to exclude base clases - template = md_template - if str(relpath) == "emmopy" and basename == "emmocheck": - template += ( - f"{' ' * 4}rendering:\n{' ' * 6}show_bases: false\n" - ) - - write_file( - full_path=docs_sub_dir / md_filename, - content=template.format(name=basename, py_path=py_path), - ) - - if pre_commit: - # Check if there have been any changes. - # List changes if yes. - if TYPE_CHECKING: - context: "Context" = context - - # NOTE: grep returns an exit code of 1 if it doesn't find anything - # (which will be good in this case). - # Concerning the weird last grep command see: - # http://manpages.ubuntu.com/manpages/precise/en/man1/git-status.1.html - result: "Result" = context.run( - "git status --porcelain docs/api_reference | " - "grep -E '^[? MARC][?MD]' || exit 0", - hide=True, - ) - if result.stdout: - sys.exit( - "The following files have been changed/added, please stage " - f"them:\n\n{result.stdout}" - ) - - -@task -def create_docs_index(_): - """Create the documentation index page from README.md""" - readme = TOP_DIR / "README.md" - docs_index = TOP_DIR / "docs" / "index.md" - - with open(readme) as handle: - content = handle.read() - - replacement_mapping = [ - ("docs/", ""), - ("(LICENSE.txt)", "(LICENSE.md)"), - ("(tools)", "(../tools)"), - ] - - for old, new in replacement_mapping: - content = content.replace(old, new) - - with open(docs_index, "w") as handle: - handle.write(content) diff --git a/tests/tools/conftest.py b/tests/tools/conftest.py index 5a3fc7c9c..ec4c79080 100644 --- a/tests/tools/conftest.py +++ b/tests/tools/conftest.py @@ -20,7 +20,8 @@ def tool(request: "Dict[str, Any]") -> "ModuleType": original_tool_path: Path = ( Path(__file__).resolve().parent.parent.parent / "tools" / request.param ) - sys.path.append(str(original_tool_path.parent.parent)) + if str(original_tool_path.parent) not in sys.path: + sys.path.append(str(original_tool_path.parent)) assert ( original_tool_path.exists() @@ -29,7 +30,7 @@ def tool(request: "Dict[str, Any]") -> "ModuleType": tool_path = original_tool_path.rename( original_tool_path.with_name(f"{request.param}.py") ) - yield importlib.import_module(f"tools.{request.param}") + yield importlib.import_module(request.param) finally: if tool_path and tool_path.exists(): tool_path.rename(tool_path.with_name(request.param)) diff --git a/tools/emmocheck b/tools/emmocheck index a390fa910..e7c5d161f 100755 --- a/tools/emmocheck +++ b/tools/emmocheck @@ -8,9 +8,12 @@ import os rootdir = os.path.abspath( os.path.realpath((os.path.dirname(os.path.dirname(__file__)))) ) -sys.path.insert(1, rootdir) +if rootdir not in sys.path: + sys.path.insert(1, rootdir) -from emmopy.emmocheck import main # pylint: disable=wrong-import-position +from emmopy.emmocheck import ( # pylint: disable=wrong-import-position,import-error + main, +) if __name__ == "__main__": diff --git a/tools/ontodoc b/tools/ontodoc index 9b325be6c..608e1aae4 100755 --- a/tools/ontodoc +++ b/tools/ontodoc @@ -10,10 +10,11 @@ import subprocess # nosec rootdir = os.path.abspath( os.path.realpath((os.path.dirname(os.path.dirname(__file__)))) ) -sys.path.insert(1, rootdir) +if rootdir not in sys.path: + sys.path.insert(1, rootdir) -from ontopy import World, onto_path -from ontopy.ontodoc import ( +from ontopy import World, onto_path # pylint: disable=import-error +from ontopy.ontodoc import ( # pylint: disable=import-error OntoDoc, get_format, get_style, diff --git a/tools/ontograph b/tools/ontograph index fd66e6c6f..acc185222 100755 --- a/tools/ontograph +++ b/tools/ontograph @@ -10,11 +10,16 @@ import json rootdir = os.path.abspath( os.path.realpath((os.path.dirname(os.path.dirname(__file__)))) ) -sys.path.insert(1, rootdir) +if rootdir not in sys.path: + sys.path.insert(1, rootdir) -from ontopy import World, onto_path -from ontopy.graph import OntoGraph, plot_modules, _default_style -from ontopy.utils import get_label +from ontopy import World, onto_path # pylint: disable=import-error +from ontopy.graph import ( # pylint: disable=import-error + OntoGraph, + plot_modules, + _default_style, +) +from ontopy.utils import get_label # pylint: disable=import-error import owlready2