-
Notifications
You must be signed in to change notification settings - Fork 23
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
[WIP] Introduce code-quality checks to the repo (details TBD) #1099
base: master
Are you sure you want to change the base?
Changes from 4 commits
3ff5d24
7a18384
3d828fe
3a27db0
9015910
5ee8476
e8b2a16
4407203
12ce9ad
f6bc597
66aa81e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,67 @@ on: | |
pull_request: | ||
|
||
jobs: | ||
code_checks: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
code-check: [black, flakehell] | ||
python-version: [3.7] | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: 'x64' | ||
|
||
- uses: actions/cache@v2 | ||
if: startsWith(runner.os, 'Linux') | ||
with: | ||
path: ${{ env.pythonLocation }} | ||
key: ${{ env.pythonLocation }}-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/*requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.python-version }}-pip- | ||
|
||
- name: Extract branch name # works for both 'push' and 'pull_request' events | ||
shell: bash | ||
run: echo "##[set-output name=branch;]$( if [ ${{ github.event_name }} = push ]; then echo ${GITHUB_REF#refs/heads/}; else echo ${{ github.event.pull_request.head.ref }}; fi )" | ||
devProdigy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id: extract_branch | ||
|
||
- name: Install test requirements | ||
run: | | ||
pip install --upgrade pip | ||
pip install --upgrade pip-tools | ||
pip install -r requirements/test_requirements.txt | ||
|
||
- name: Run code quality checks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is better to reuse code from Makefile in this step:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's different for CI approach and local. Locally we should check for any changes (not event committed), on the other hand on CI we should compare two remote branches. |
||
run: | | ||
FILES_TO_CHECK=$(git diff origin/master..origin/${{ steps.extract_branch.outputs.branch }} --name-only --diff-filter=ACM '*py') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pull request could be created to another branch except for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, good point. I'll see how to make About |
||
echo "> Changed Python files: ${FILES_TO_CHECK}" | ||
|
||
if [ -z "${FILES_TO_CHECK}" ] | ||
then | ||
echo "> No Python files to check, exiting." | ||
exit 0 | ||
fi | ||
|
||
if [ ${{ matrix.code-check }} = black ] | ||
then | ||
echo "> Starting Black code-formatting check for files: ${FILES_TO_CHECK}" | ||
black --check ${FILES_TO_CHECK} | ||
else | ||
echo "> Starting Flakehell code-quality check for diff in files: ${FILES_TO_CHECK}" | ||
git diff origin/master..origin/${{ steps.extract_branch.outputs.branch }} -U0 --diff-filter=ACM '*.py' | flakehell lint --diff | ||
fi | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
needs: code_checks | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
component: [builder, cli, client, machine, reporters, serializer, server, util, workflow, formatting, allelse] | ||
component: [builder, cli, client, machine, reporters, serializer, server, util, workflow, allelse] | ||
python-version: [3.7] | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
@@ -20,13 +75,13 @@ jobs: | |
python-version: ${{ matrix.python-version }} | ||
architecture: 'x64' | ||
|
||
- uses: actions/cache@v1 | ||
- uses: actions/cache@v2 | ||
if: startsWith(runner.os, 'Linux') | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-new-${{ hashFiles('requirements/*requirements.txt') }} | ||
path: ${{ env.pythonLocation }} | ||
key: ${{ env.pythonLocation }}-${{ runner.os }}-${{ matrix.python-version }}-env-${{ hashFiles('**/*requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.python-version }}-pip-new- | ||
${{ env.pythonLocation }}-${{ runner.os }}-${{ matrix.python-version }}-env- | ||
|
||
- name: Install | ||
run: | | ||
|
@@ -69,6 +124,7 @@ jobs: | |
|
||
build-docs: | ||
runs-on: ubuntu-latest | ||
needs: code_checks | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
|
@@ -77,6 +133,13 @@ jobs: | |
python-version: '3.7' # Version range or exact version of a Python version to use, using semvers version range syntax. | ||
architecture: 'x64' | ||
|
||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/.cache/pip | ||
Comment on lines
+80
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can save some time on packages downloading. Don't know if this is worth it. |
||
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-new-${{ hashFiles('**/*requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.python-version }}-pip-new- | ||
devProdigy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Install deps | ||
run: | | ||
pip install --upgrade pip | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,7 +145,7 @@ def build( | |
model=model, machine=machine, output_dir=output_dir # type: ignore | ||
) | ||
logger.info(f"Built model, and deposited at {self.cached_model_path}") | ||
logger.info(f"Writing model-location to model registry") | ||
logger.info("Writing model-location to model registry") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cause of this tests were failing. |
||
disk_registry.write_key( # type: ignore | ||
model_register_dir, self.cache_key, self.cached_model_path | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[tool.flakehell] | ||
format = "grouped" | ||
max_line_length = 120 | ||
show_source = true | ||
no-isort-config = true | ||
max-line-complexity = 15 | ||
|
||
exclude = [".cache", ".git", "__pycache__", "old", "build", "dist", "junk"] | ||
|
||
[tool.flakehell.plugins] | ||
flake8-broken-line = ["+*"] | ||
flake8-bugbear = ["+*"] | ||
flake8-builtins = ["+*"] | ||
# - C812 exclude trailing comma for one line expression (black conflicts) | ||
flake8-commas = ["+*", "-C812"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can add exclude that is logical from our perspective of view. |
||
flake8-comprehensions = ["+*"] | ||
flake8-darglint = ["+*"] | ||
flake8-debugger = ["+*"] | ||
flake8-docstrings = ["+*"] | ||
flake8-eradicate = ["+*"] | ||
flake8-isort = ["+*"] | ||
flake8-string-format = ["+*"] | ||
flake8-mutable = ["+*"] | ||
mccabe = ["+*"] | ||
pep8-naming = ["+*"] | ||
pycodestyle = ["+*"] | ||
pyflakes = ["+*"] | ||
|
||
[tool.black] | ||
target-version = ['py37'] | ||
include = '\.pyi?$' | ||
exclude = ''' | ||
( | ||
/( | ||
\.eggs # exclude a few common directories in the | ||
| \.git # root of the project | ||
| \.hg | ||
| \.mypy_cache | ||
| \.tox | ||
| \.venv | ||
| \.cache | ||
| __pycache__ | ||
| _build | ||
| buck-out | ||
| build | ||
| dist | ||
)/ | ||
) | ||
''' | ||
|
||
[tool.isort] | ||
skip = [".cache", ".venv"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,20 @@ nbconvert~=5.6 | |
urllib3>=1.24.2,<2.0 | ||
pytest-benchmark~=3.2 | ||
mock~=3.0 | ||
flakehell~=0.7.0 | ||
flake8-broken-line~=0.3 | ||
flake8-bugbear~=20.11 | ||
flake8-builtins~=1.5 | ||
flake8-commas~=2.0 | ||
flake8-comprehensions~=3.3 | ||
darglint~=1.5 | ||
flake8-debugger~=4.0 | ||
flake8-docstrings~=1.5 | ||
flake8-eradicate~=1.0 | ||
flake8-isort~=4.0 | ||
flake8-mutable~=1.2 | ||
flake8-string-format~=0.3 | ||
mccabe~=0.6 | ||
pep8-naming~=0.11.1 | ||
pycodestyle~=2.6 | ||
pyflakes~=2.2 | ||
Comment on lines
+21
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. versions should be low and freezed cause of the massive conflicts in the requirements files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This speeds up the CI requirements install process for code-quality and tests jobs that run in parallel.