From 634019529d950927938d648b8f2434b40e423ef2 Mon Sep 17 00:00:00 2001 From: Joseph Burling Date: Wed, 20 Apr 2022 21:43:47 -0500 Subject: [PATCH] build(retrocookie): reflect updates to source template from generated project 'science-institute_brain-lab' --- .../.pre-commit-config.yaml | 19 ++++++++++-- .../docker/.devcontainer/devcontainer.json | 6 ++-- .../docker-compose-standard_workflow.yaml | 2 +- .../{{cookiecutter.github_repo}}/noxfile.py | 31 ++++++++++++++++--- .../pyproject.toml | 4 +-- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/datajoint-workflow/{{cookiecutter.github_repo}}/.pre-commit-config.yaml b/datajoint-workflow/{{cookiecutter.github_repo}}/.pre-commit-config.yaml index a6341e6..7d0c25a 100644 --- a/datajoint-workflow/{{cookiecutter.github_repo}}/.pre-commit-config.yaml +++ b/datajoint-workflow/{{cookiecutter.github_repo}}/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - id: name-tests-test args: ["--django"] - id: check-added-large-files - args: ["--maxkb=5000"] + args: ["--maxkb=25000"] - id: end-of-file-fixer exclude: LICENSE - id: mixed-line-ending @@ -43,12 +43,11 @@ repos: rev: 5.10.1 hooks: - id: isort - name: isort (python) args: - "--settings-file" - "./pyproject.toml" - # Run black on python code blocks in documentation files. + # run black on python code blocks in documentation files. - repo: https://github.com/asottile/blacken-docs rev: v1.12.1 hooks: @@ -60,3 +59,17 @@ repos: rev: 0.5.0 hooks: - id: nbstripout + + # python linting + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + exclude: ^tests/(integration/fixtures|unit/data)/ + args: + # making isort line length compatible with black + # https://flake8.pycqa.org/en/latest/user/error-codes.html + - "--max-line-length=88" + - "--max-complexity=18" + - "--select=B,C,E,F,W,T4,B9" + - "--ignore=E203,E266,E501,W503,F403,F401,E402" diff --git a/datajoint-workflow/{{cookiecutter.github_repo}}/docker/.devcontainer/devcontainer.json b/datajoint-workflow/{{cookiecutter.github_repo}}/docker/.devcontainer/devcontainer.json index d1f5acf..d8660ee 100644 --- a/datajoint-workflow/{{cookiecutter.github_repo}}/docker/.devcontainer/devcontainer.json +++ b/datajoint-workflow/{{cookiecutter.github_repo}}/docker/.devcontainer/devcontainer.json @@ -15,9 +15,6 @@ "vivaxy.vscode-conventional-commits", "yzhang.markdown-all-in-one" ], - "features": { - "github": "latest" - }, "service": "devcontainer_env", // Set *default* container specific settings.json values on container create. "settings": { @@ -69,5 +66,6 @@ "python.terminal.activateEnvironment": true }, "shutdownAction": "none", - "workspaceFolder": "/home/{{cookiecutter.github_user}}/{{cookiecutter.__org}}_{{cookiecutter.__wf}}" + "workspaceFolder": "/home/{{cookiecutter.github_user}}/{{cookiecutter.__org}}_{{cookiecutter.__wf}}", + "initializeCommand": "test -f \"${localWorkspaceFolder}/.env\" || exit 1" } diff --git a/datajoint-workflow/{{cookiecutter.github_repo}}/docker/docker-compose-standard_workflow.yaml b/datajoint-workflow/{{cookiecutter.github_repo}}/docker/docker-compose-standard_workflow.yaml index dad5526..1f8df7c 100644 --- a/datajoint-workflow/{{cookiecutter.github_repo}}/docker/docker-compose-standard_workflow.yaml +++ b/datajoint-workflow/{{cookiecutter.github_repo}}/docker/docker-compose-standard_workflow.yaml @@ -23,5 +23,5 @@ services: - /bin/bash - -c - | - wf_entrypoint --help & + {{cookiecutter.__pkg_import_name}}_entrypoint --help & tail -f /dev/null diff --git a/datajoint-workflow/{{cookiecutter.github_repo}}/noxfile.py b/datajoint-workflow/{{cookiecutter.github_repo}}/noxfile.py index 68491f1..57c033d 100644 --- a/datajoint-workflow/{{cookiecutter.github_repo}}/noxfile.py +++ b/datajoint-workflow/{{cookiecutter.github_repo}}/noxfile.py @@ -5,6 +5,7 @@ """ import argparse +import os import re import nox @@ -100,6 +101,17 @@ def git_action_bot( session.run("git", "push", *push, external=True) +@nox.session(python=default_python_version, reuse_venv=True) +def run_entrypoint(session: nox.Session) -> None: + """Install all dependencies then run package entrypoint 'help'. + + nox -s run_entrypoint + """ + + install_dependencies(session, "dev", "test", "doc", "sciops") + session.run("{{cookiecutter.__pkg_import_name}}_entrypoint", "--help") + + @nox.session(python=default_python_version, reuse_venv=True) def write_version(session: nox.Session) -> None: """Bump version.py to the latest version. @@ -137,19 +149,28 @@ def pre_commit(session: nox.Session) -> None: install_dependencies(session, "dev") session.run("pre-commit", "install") - failed_hooks = [] + failed_hooks = {} + log_file = ".nox.pre-commit.log" for hook in hooks: try: - session.run("pre-commit", "run", "--all-files", "-v", hook) + with open(log_file, "w") as fout: + session.run("pre-commit", "run", "--all-files", hook, stdout=fout) + except Exception as err: session.log(err) - failed_hooks.append(hook) + with open(log_file, "r") as fin: + failed_hooks[hook] = fin.read() + + finally: + os.remove(log_file) if failed_hooks: failed_str = "Failed pre-commit hooks:" - failed_str += "".join([f"\n - {hk}" for hk in failed_hooks]) + failed_str += "".join( + [f"\n::{hk}\n\n{txt}\n" for hk, txt in failed_hooks.items()] + ) if raise_exception: - raise SyntaxError(failed_str) + session.error(failed_str) else: session.log(failed_str) diff --git a/datajoint-workflow/{{cookiecutter.github_repo}}/pyproject.toml b/datajoint-workflow/{{cookiecutter.github_repo}}/pyproject.toml index f1c963b..7e35a68 100644 --- a/datajoint-workflow/{{cookiecutter.github_repo}}/pyproject.toml +++ b/datajoint-workflow/{{cookiecutter.github_repo}}/pyproject.toml @@ -49,7 +49,7 @@ dependencies = [ ] [project.optional-dependencies] -dev = ["black", "flake8", "pre-commit", "nox", "mypy"] +dev = ["black", "isort", "flake8", "pre-commit", "nox", "mypy"] doc = [ "mkdocs", "mkdocstrings-python", @@ -65,7 +65,7 @@ test = ["pytest"] sciops = ["ipykernel", "djsciops", "datajoint>=0.13.4"] [project.scripts] -wf_entrypoint = "{{cookiecutter.__pkg_import_name}}.entrypoint:cli" +{{cookiecutter.__pkg_import_name}}_entrypoint = "{{cookiecutter.__pkg_import_name}}.entrypoint:cli" [project.urls] Homepage = "{{cookiecutter.homepage_url}}"