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

Implement pre-commit & various tools #245

Merged
merged 30 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5b6f7dd
Add pre-commit config hooks and dependency
CasperWA Sep 29, 2021
7835438
Update files according to pre-commit hooks
CasperWA Sep 29, 2021
64a62bf
Update code according to `bandit`
CasperWA Sep 29, 2021
0922299
Add local `pre-commit` hooks for docs inv tasks
CasperWA Sep 29, 2021
2a40c22
Ensure update-docs-api-reference hook can fail
CasperWA Sep 29, 2021
e25ba51
Update flake8 CI job to pre-commit CI job
CasperWA Sep 29, 2021
baa3ddb
Add safety CI job and use vMAJOR version actions
CasperWA Sep 29, 2021
9003b70
Add `pytest` to `dev` requirements
CasperWA Sep 29, 2021
18c1265
Update CI job names for packages
CasperWA Sep 29, 2021
72ff6e4
Add documentation for developer setup/install
CasperWA Sep 29, 2021
94f220e
Move section after installation one tier up in doc
CasperWA Sep 29, 2021
e552546
Optimize diff check in API ref. doc task
CasperWA Sep 29, 2021
49f1c1a
Add black pre-commit hook and run for all files
CasperWA Oct 12, 2021
fd21566
Add pylint hook and CI
CasperWA Oct 12, 2021
c178ed1
Starting to comply with pylint (slow progress)
CasperWA Oct 12, 2021
8061434
Further satisfy pylint
CasperWA Oct 13, 2021
1b38351
Further pylint stuff
CasperWA Oct 14, 2021
75d08e5
Further pylint updates
CasperWA Oct 21, 2021
8b9def0
Further pylint stuff
CasperWA Oct 25, 2021
a8c3013
Move exceptions to ontopy.utils
CasperWA Oct 25, 2021
52143f5
Complete pylint edits
CasperWA Oct 26, 2021
68301de
Fully satisfy pylint (outside ontopy/emmopy)
CasperWA Oct 26, 2021
f018b64
Run pylint in CI for all python files in repo
CasperWA Oct 26, 2021
23ff380
Fix pytest issues
CasperWA Oct 26, 2021
9865d62
Remove all specified encoding for open()
CasperWA Oct 26, 2021
1e40260
Adapt to changed use of NamedTemporaryFile
CasperWA Oct 26, 2021
d37af38
Update pre-commit hook `black`
CasperWA Nov 1, 2021
384d844
Run pre-commit and update code base accordingly
CasperWA Nov 2, 2021
b2ee8de
Add `venv` to dev-setup instructions
CasperWA Nov 8, 2021
ebd36fa
Update development env setup documentation
CasperWA Nov 8, 2021
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
123 changes: 87 additions & 36 deletions .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,121 @@ on:

jobs:

lint:
name: Lint with flake8
pre-commit:
name: pre-commit
runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Lint with flake8
- name: Install dependencies
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --extend-exclude "tests/*"
flake8 . --count --statistics --extend-exclude "tests/*"
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@v2

- name: Set up Python 3.7
uses: actions/setup-python@v2
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

- name: Run safety
run: pip freeze | safety check --stdin


tests:
name: Pytest and demos
name: pytest
runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install other dependencies
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y graphviz openjdk-11-jre-headless

- name: Install Python dependencies (and EMMOntoPy)
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest
sudo apt-get install -y graphviz openjdk-11-jre-headless
pip install -U setuptools wheel

- name: Install EMMOntoPy
run: python setup.py install
pip install -U -e .[dev]

- name: Test with pytest
run: pytest

- name: Run vertical demo
run: |
cd demo/vertical
#python define_ontology.py
#python plot_ontology.py
cd -
- name: Run horizontal demo
run: |
cd demo/horizontal
#python step1_generate_metadata.py
#python step2_define_metadata.py
#python step3_instantiate.py
#python step4_map_instance.py
cd -
# - name: Run vertical demo
# run: |
# cd demo/vertical
# python define_ontology.py
# python plot_ontology.py
# cd -

# - name: Run horizontal demo
# run: |
# cd demo/horizontal
# python step1_generate_metadata.py
# python step2_define_metadata.py
# python step3_instantiate.py
# python step4_map_instance.py
# cd -


ontodoc:
name: EMMO documentation (test using ontodoc)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: 3.7

Expand Down Expand Up @@ -117,6 +167,7 @@ jobs:
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
Expand All @@ -126,10 +177,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: 3.7

Expand Down
62 changes: 62 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-symlinks
- id: check-xml
name: Check XML
files: \.(xml|rdf|ttl)$
- id: check-yaml
name: Check YAML
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: requirements-txt-fixer
name: Fix requirements*.txt
files: ^requirements.*\.txt$
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/ambv/black
rev: 21.10b0
hooks:
- id: black
name: Blacken

- repo: https://github.com/PyCQA/bandit
rev: '1.7.0'
hooks:
- id: bandit
args: [-r]
exclude: ^tests/.*$

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.910
# hooks:
# - id: mypy
# exclude: ^tests/.*$

- repo: local
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
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
files: ^README.md$
description: Update the landing page for the documentation if the source file (README.md) is changed.
- id: pylint
name: pylint
entry: pylint
language: python
types: [python]
require_serial: true
exclude: ^tests/.*$
Loading