From 85bb3658c7a413bdfa3522ad26a47cadaf904cc4 Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Tue, 9 Feb 2021 20:26:58 +0100 Subject: [PATCH] Dogfood pre-commit hooks Signed-off-by: Vadim Markovtsev --- .github/workflows/push.yml | 4 +++- .pre-commit-config.yaml | 9 +++++++++ .pre-commit-hooks.yaml | 8 -------- CONTRIBUTING.md | 2 +- LICENSE | 2 +- Makefile | 2 +- mloq.yml | 3 ++- mloq/assets/requirements/dogfood.txt | 3 ++- mloq/assets/requirements/requirements-lint.txt | 3 ++- mloq/assets/static/.pre-commit-config.yaml | 9 +++++++++ mloq/assets/templates/CODE_OF_CONDUCT.md | 1 - mloq/assets/templates/CONTRIBUTING.md | 2 +- mloq/assets/templates/MIT_LICENSE | 2 +- mloq/assets/templates/setup.txt | 3 ++- mloq/files.py | 2 ++ mloq/git.py | 1 + mloq/templating.py | 1 + requirements-lint.txt | 3 ++- requirements.txt | 3 ++- setup.py | 1 + 20 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100644 .pre-commit-hooks.yaml create mode 100644 mloq/assets/static/.pre-commit-config.yaml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index a6900a37..8dfed2d6 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -95,6 +95,7 @@ jobs: diff CONTRIBUTING.md generated/CONTRIBUTING.md diff LICENSE generated/LICENSE diff Makefile generated/Makefile + diff .pre-commit-config.yaml generated/.pre-commit-config.yaml - name: Test with pytest run: | @@ -188,6 +189,7 @@ jobs: diff CONTRIBUTING.md generated/CONTRIBUTING.md diff LICENSE generated/LICENSE diff Makefile generated/Makefile + diff .pre-commit-config.yaml generated/.pre-commit-config.yaml - name: Test package run: | @@ -278,4 +280,4 @@ jobs: uses: pypa/gh-action-pypi-publish@master with: user: __token__ - password: ${{ secrets.PYPI_PASS }} \ No newline at end of file + password: ${{ secrets.PYPI_PASS }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..a274dbf6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black +- repo: https://github.com/life4/flakehell + rev: v.0.8.0 + hooks: + - id: flakehell \ No newline at end of file diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml deleted file mode 100644 index 1056c2c0..00000000 --- a/.pre-commit-hooks.yaml +++ /dev/null @@ -1,8 +0,0 @@ -- id: black - name: black - description: "Black: The uncompromising Python code formatter" - entry: black - language: python - language_version: python3 - require_serial: true - types: [python] \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d713bf5..ab70dd9c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,4 +53,4 @@ Remove unused code Fix a bug ``` -Every commit details should describe what was changed, under which context and, if applicable, the GitHub issue it relates to. \ No newline at end of file +Every commit details should describe what was changed, under which context and, if applicable, the GitHub issue it relates to. diff --git a/LICENSE b/LICENSE index 1b989900..6f55ad87 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/Makefile b/Makefile index 58c47282..23412867 100644 --- a/Makefile +++ b/Makefile @@ -68,4 +68,4 @@ remove-dev-packages: docker-push: docker push ${DOCKER_ORG}/${DOCKER_TAG}:${VERSION} docker tag ${DOCKER_ORG}/${DOCKER_TAG}:${VERSION} ${DOCKER_ORG}/${DOCKER_TAG}:latest - docker push ${DOCKER_ORG}/${DOCKER_TAG}:latest \ No newline at end of file + docker push ${DOCKER_ORG}/${DOCKER_TAG}:latest diff --git a/mloq.yml b/mloq.yml index 31eff993..40868b4b 100644 --- a/mloq.yml +++ b/mloq.yml @@ -6,7 +6,7 @@ project: requirements: - dogfood git_init: false - git_push: null + git_push: false template: project_name: mloq default_branch: master @@ -50,4 +50,5 @@ template: diff CONTRIBUTING.md generated/CONTRIBUTING.md diff LICENSE generated/LICENSE diff Makefile generated/Makefile + diff .pre-commit-config.yaml generated/.pre-commit-config.yaml git_message: null diff --git a/mloq/assets/requirements/dogfood.txt b/mloq/assets/requirements/dogfood.txt index fb9e4461..6faba7a4 100644 --- a/mloq/assets/requirements/dogfood.txt +++ b/mloq/assets/requirements/dogfood.txt @@ -2,4 +2,5 @@ click==7.1.2 flogging==0.0.10 invoke==1.5.0 jinja2==2.11.3 -hydra-core==1.0.6 \ No newline at end of file +hydra-core==1.0.6 +pre-commit==2.10.1 \ No newline at end of file diff --git a/mloq/assets/requirements/requirements-lint.txt b/mloq/assets/requirements/requirements-lint.txt index 3e0c4683..647def3e 100644 --- a/mloq/assets/requirements/requirements-lint.txt +++ b/mloq/assets/requirements/requirements-lint.txt @@ -9,4 +9,5 @@ pylint==2.6.0 pydocstyle==5.1.1 pycodestyle==2.6.0 flakehell==0.9.0 -black==20.8b1 \ No newline at end of file +black==20.8b1 +pre-commit==2.10.1 \ No newline at end of file diff --git a/mloq/assets/static/.pre-commit-config.yaml b/mloq/assets/static/.pre-commit-config.yaml new file mode 100644 index 00000000..a274dbf6 --- /dev/null +++ b/mloq/assets/static/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black +- repo: https://github.com/life4/flakehell + rev: v.0.8.0 + hooks: + - id: flakehell \ No newline at end of file diff --git a/mloq/assets/templates/CODE_OF_CONDUCT.md b/mloq/assets/templates/CODE_OF_CONDUCT.md index 7b9adc42..a8228031 100644 --- a/mloq/assets/templates/CODE_OF_CONDUCT.md +++ b/mloq/assets/templates/CODE_OF_CONDUCT.md @@ -130,4 +130,3 @@ at [https://www.contributor-covenant.org/translations][translations]. [Mozilla CoC]: https://github.com/mozilla/diversity [FAQ]: https://www.contributor-covenant.org/faq [translations]: https://www.contributor-covenant.org/translations - diff --git a/mloq/assets/templates/CONTRIBUTING.md b/mloq/assets/templates/CONTRIBUTING.md index 428114ff..a2b385d3 100644 --- a/mloq/assets/templates/CONTRIBUTING.md +++ b/mloq/assets/templates/CONTRIBUTING.md @@ -53,4 +53,4 @@ Remove unused code Fix a bug ``` -Every commit details should describe what was changed, under which context and, if applicable, the GitHub issue it relates to. \ No newline at end of file +Every commit details should describe what was changed, under which context and, if applicable, the GitHub issue it relates to. diff --git a/mloq/assets/templates/MIT_LICENSE b/mloq/assets/templates/MIT_LICENSE index 12183700..8e756bd8 100644 --- a/mloq/assets/templates/MIT_LICENSE +++ b/mloq/assets/templates/MIT_LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/mloq/assets/templates/setup.txt b/mloq/assets/templates/setup.txt index a316e57f..2f44f480 100644 --- a/mloq/assets/templates/setup.txt +++ b/mloq/assets/templates/setup.txt @@ -5,7 +5,8 @@ from setuptools import find_packages, setup version = SourceFileLoader( - "{{project_name}}.version", str(Path(__file__).parent / "{{project_name}}" / "version.py"), + "{{project_name}}.version", + str(Path(__file__).parent / "{{project_name}}" / "version.py"), ).load_module() with open(Path(__file__).with_name("README.md"), encoding="utf-8") as f: diff --git a/mloq/files.py b/mloq/files.py index fd56a3e3..544593c8 100644 --- a/mloq/files.py +++ b/mloq/files.py @@ -28,6 +28,7 @@ def file( # Common files mloq_yml = file("mloq.yml", STATIC_FILES_PATH, is_static=True) gitignore = file(".gitignore", STATIC_FILES_PATH, is_static=True) +pre_commit_hook = file(".pre-commit-config.yaml", STATIC_FILES_PATH, is_static=True) dco = file("DCO.md", STATIC_FILES_PATH, is_static=True) init = file("init.txt", STATIC_FILES_PATH, "__init__.py", is_static=True) main = file("main.txt", STATIC_FILES_PATH, "__main__.py", is_static=True) @@ -63,6 +64,7 @@ def file( ROOT_PATH_FILES = [ gitignore, + pre_commit_hook, pyproject_toml, makefile, dockerfile, diff --git a/mloq/git.py b/mloq/git.py index e5a635ae..ab761796 100644 --- a/mloq/git.py +++ b/mloq/git.py @@ -28,6 +28,7 @@ def setup_git( try: _git_cmd(path, "init") _git_cmd(path, *f"remote add origin ssh://git@github.com/{owner}/{project_name}".split()) + subprocess.run(("pre-commit", "install"), check=True, cwd=path) _git_cmd(path, *"add .".split()) _git_cmd(path, *f"commit {'--signoff' if sign_off else ''} -m".split(), message) if push: diff --git a/mloq/templating.py b/mloq/templating.py index dd5a4360..2e8b2237 100644 --- a/mloq/templating.py +++ b/mloq/templating.py @@ -14,6 +14,7 @@ jinja_env = Environment( loader=FileSystemLoader([str(TEMPLATES_PATH), str(WORKFLOWS_PATH)]), autoescape=select_autoescape(["html", "xml"]), + keep_trailing_newline=True, ) diff --git a/requirements-lint.txt b/requirements-lint.txt index 3e0c4683..647def3e 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -9,4 +9,5 @@ pylint==2.6.0 pydocstyle==5.1.1 pycodestyle==2.6.0 flakehell==0.9.0 -black==20.8b1 \ No newline at end of file +black==20.8b1 +pre-commit==2.10.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5a9cc174..7be58b82 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ click==7.1.2 flogging==0.0.10 hydra-core==1.0.6 invoke==1.5.0 -jinja2==2.11.3 \ No newline at end of file +jinja2==2.11.3 +pre-commit==2.10.1 \ No newline at end of file diff --git a/setup.py b/setup.py index 071345e1..aa179301 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,7 @@ "click>=7.1.2,<8.0.0", "invoke>=1.4.1", "hydra-core>=1.0,<1.1", + "pre-commit>=2.10.0", ], package_data={ "": ["README.md"],