Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

feat: refactor ci steps and add pre-commit validations #124

Open
wants to merge 12 commits into
base: development
Choose a base branch
from

Conversation

KnowYourselves
Copy link
Contributor

@KnowYourselves KnowYourselves commented Jan 6, 2022

What is being added

This PR refactors the CI steps executed by CircleCI and adds a new series of pre-commit and pre-push validations by using git hooks, husky, and pre-commit (python package).

The following packages are being used:

  • flake8 for linting code and detecting errors.
  • black for formatting code.
  • isort for sorting the imports.
  • husky for setting up the git hooks
  • pre-commit to define the use of flake8, black and isort before every commit and checking migrations before every push.

The CI steps are changed in the following ways:

  • Two jobs are executed in parallel, test and lint
  • The test is the old build job, but now it caches the npm cache.
  • The lint job checks the code with flake8, black and isort

How is everything configured

  • Black comes with its default settings.
  • Flake8 is being called in a way so it follows black.
  • Isort is separating the imports in the following sections:
    • "FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"
    • STDLIB, DJANGO, and THIRDPARTY are preceded y comments
    • Any preexisting comments will be maintained

pyproject.toml

The last two years a new settings format, pyproject.toml has been gaining traction.

Now we can configure a lot of python-only tools (like poetry) in this file. For example, all the isort configuration is in this file under [tools.isort], which allows the dev to simply use isort isntead of a really long line of flags and configs. If we where to configure black, we would use this file too.

Pytest added support for this format on its 6.0.0 version, since we are already on that version I moved the configuration to this file.

The only problem with this setup is that flake8 doesn't support this config file.

TO-DO

  • Validate black formatting decisions and configure it if necessary
  • Validate current isort configuration and change it if necessary
  • Decide between flake8 or another linter.

Flake8 is a good linter as is, but we would have to add another file to configure it. If we where to use another linter, for example, pylint, that supports pyproject.toml, we could have all our python-only config in just one file.

  • Check if .coveragerc can be translated to pyproject.toml
  • Apply the black, isort and the selected linter to all the files
  • Change the startapp template to follow black, isort, and the linter.

@KnowYourselves KnowYourselves changed the title feat: add lint action feat: add lint job to circleci Jan 6, 2022
@KnowYourselves KnowYourselves force-pushed the feat/add-lint-action-to-circleci branch 5 times, most recently from 11195bf to 9589d0a Compare January 14, 2022 02:00
@KnowYourselves KnowYourselves force-pushed the feat/add-lint-action-to-circleci branch 2 times, most recently from 1b9e061 to bddcf07 Compare January 14, 2022 02:13
@KnowYourselves KnowYourselves force-pushed the feat/add-lint-action-to-circleci branch from 3648ed0 to 7012c85 Compare January 14, 2022 02:15
@KnowYourselves KnowYourselves changed the title feat: add lint job to circleci feat: refactor ci steps and add pre-commit validations Jan 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant