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

[WIP] Introduce code-quality checks to the repo (details TBD) #1099

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

devProdigy
Copy link
Contributor

What this PR offers:

  • check code-quality with flakehell (flake8 + plugins) and "black" on the CI before tests. In such way we'll eliminate waiting time to know that some space is missing.
    • I know that there's a lot of legacy stuff here and no code-analysers (except black) was run previously, so this checks run only on changed code. Old code could be "unified" with time.
  • separate code-quality steps from tests
    • here's CI job that shows how the flow looks like and how caching with pythonLocation speeds up the process. If I missed any downsides/risks of using pythonLocation instead of pip cache - please let me know. We should fix cache limit range.
    • here's job that shows how CI will behave on quality-check error.

Motivation:

  • unifies code is easier to read;
  • code-checkers allow us not to spend code-review time on comments with formatting and styles discussions;
  • etc.

P.S. Previous PR was closed due to some un-reverted issues :) Here's lates comment from @flikka about this idea.
P.S.2. Feel free to add your opinion :)

Comment on lines 26 to 27
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/*requirements.txt') }}
Copy link
Contributor Author

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.

Comment on lines +136 to +138
- uses: actions/cache@v2
with:
path: ~/.cache/pip
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cause of this tests were failing.

@codecov
Copy link

codecov bot commented Dec 9, 2020

Codecov Report

Merging #1099 (f6bc597) into master (6974cca) will not change coverage.
The diff coverage is 87.50%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1099   +/-   ##
=======================================
  Coverage   94.63%   94.63%           
=======================================
  Files          62       62           
  Lines        2965     2965           
=======================================
  Hits         2806     2806           
  Misses        159      159           
Impacted Files Coverage Δ
gordo/cli/custom_types.py 89.47% <0.00%> (ø)
gordo/builder/build_model.py 98.39% <100.00%> (ø)
gordo/cli/cli.py 96.26% <100.00%> (ø)
gordo/cli/client.py 97.80% <100.00%> (ø)
gordo/machine/validators.py 86.88% <100.00%> (ø)
gordo/reporters/mlflow.py 97.85% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6974cca...66aa81e. Read the comment docs.

flake8-bugbear = ["+*"]
flake8-builtins = ["+*"]
# - C812 exclude trailing comma for one line expression (black conflicts)
flake8-commas = ["+*", "-C812"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add exclude that is logical from our perspective of view.

Comment on lines +21 to +37
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment on lines -24 to -26
# Black formatting
testformatting = pytest --addopts "tests/test_formatting.py"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black will be checked now on the CI step at first place, not to wait for the tests to end.

@devProdigy devProdigy requested a review from koropets December 9, 2020 19:00

- name: Run code quality checks
run: |
FILES_TO_CHECK=$(git diff origin/master..origin/${{ steps.extract_branch.outputs.branch }} --name-only --diff-filter=ACM '*py')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request could be created to another branch except for master. Also, it would not work with push into the branch which will not be merged into master.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, good point. I'll see how to make origin/master dynamical.

About push - what do you mean? Diff will compare target branch with the current one and get the diff. Even if it push or pull_request.

pip install --upgrade pip-tools
pip install -r requirements/test_requirements.txt

- name: Run code quality checks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is better to reuse code from Makefile in this step:

run: |
  make ${{ matrix.code-check }}-check

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
So it'll be different diffs with different info needed to it.
So I split them not to make logic hard to understand and get lost among params.

.github/workflows/main.yml Outdated Show resolved Hide resolved
.github/workflows/main.yml Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
tests/gordo/server/test_base_view.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants