Skip to content

Commit

Permalink
feat: added flake8, black, isort, and pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bskqd committed Oct 21, 2022
1 parent 540f640 commit e985dcf
Show file tree
Hide file tree
Showing 57 changed files with 1,291 additions and 974 deletions.
9 changes: 9 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,__init__.py,./lib/*
inline-quotes='
max-line-length=120
select=E,F,W,C4,Q0,N80,ABS,W504
ignore=W503,Q003,C417
extend-ignore=E203
per-file-ignores=
bin/yang_figures.py:F405,F403
10 changes: 10 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r lint_requirements.txt
cd bin/resources/HTML
python setup.py install
- name: Check isort
uses: jamescurtin/isort-action@master

- name: Check flake8
run: flake8 .

- name: Check black
uses: psf/black@stable

- name: Test with pytest
run: |
export YANGCATALOG_CONFIG_PATH=$PWD/tests/resources/test.conf
Expand Down
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.3.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/pycqa/flake8
rev: '5.0.4'
hooks:
- id: flake8
args:
- '--config=.flake8'
additional_dependencies: [
flake8-docstrings, flake8-quotes, flake8-print, pep8-naming, flake8-absolute-import, flake8-comprehensions,
flake8-commas, flake8-multiline-containers,
]
21 changes: 11 additions & 10 deletions bin/check_archived_drafts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import time

import requests

from create_config import create_config
from extractors.draft_extractor import DraftExtractor
from job_log import job_log
Expand All @@ -51,10 +50,7 @@ def main():
yang_path = os.path.join(ietf_directory, 'archived-drafts-modules')

parser = argparse.ArgumentParser(description='Check if modules from all the Drafts are populated in YANG Catalog')
parser.add_argument('--debug',
help='Debug level - default is 0',
type=int,
default=0)
parser.add_argument('--debug', help='Debug level - default is 0', type=int, default=0)
args = parser.parse_args()

custom_print('Starting {} script'.format(os.path.basename(__file__)))
Expand All @@ -66,7 +62,7 @@ def main():
'draft_path': archived_draft_path,
'yang_path': yang_path,
'all_yang_draft_path_strict': all_yang_drafts_strict,
'all_yang_path': all_yang_path
'all_yang_path': all_yang_path,
}

try:
Expand All @@ -75,9 +71,14 @@ def main():
remove_directory_content(all_yang_drafts_strict, args.debug)

custom_print('Extracting modules from drafts stored in {}'.format(archived_draft_path))
draftExtractor = DraftExtractor(draft_extractor_paths, args.debug,
extract_elements=False, extract_examples=False, copy_drafts=False)
draftExtractor.extract()
draft_extractor = DraftExtractor(
draft_extractor_paths,
args.debug,
extract_elements=False,
extract_examples=False,
copy_drafts=False,
)
draft_extractor.extract()
except Exception as err:
custom_print('Error occured while extracting modules')
end = int(time.time())
Expand Down Expand Up @@ -110,7 +111,7 @@ def main():

missing_modules = []
incorrect_revision_modules = []
for yang_file in draftExtractor.inverted_draft_yang_dict:
for yang_file in draft_extractor.inverted_draft_yang_dict:
name_revision = yang_file.split('.yang')[0]
if any(yang_file in module for module in (old_modules, unparsable_modules)) or yang_file.startswith('example'):
continue
Expand Down
5 changes: 4 additions & 1 deletion bin/compilation_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def yanglint_compilation_status(compilation_result: str) -> str:
ret = 'UNKNOWN'
# 'err : Input data contains submodule which cannot be parsed directly without its main module.' error message
# => still print the message, but doesn't report it as FAILED
if 'err : Input data contains submodule which cannot be parsed directly without its main module.' in compilation_result:
if (
'err : Input data contains submodule which cannot be parsed directly without its main module.'
in compilation_result
):
ret = 'PASSED'
return ret

Expand Down
Loading

0 comments on commit e985dcf

Please sign in to comment.