From c0fea40766bb16c329c1c7eba34dec62d3e5c625 Mon Sep 17 00:00:00 2001 From: Fabrice Normandin Date: Tue, 14 Mar 2023 14:50:09 -0400 Subject: [PATCH 1/2] Add pre-commit to prevent CI fails due to linting Signed-off-by: Fabrice Normandin --- .pre-commit-config.yaml | 33 +++++++++++++++++ poetry.lock | 80 ++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..2ddba824 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + # - id: trailing-whitespace + # - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black +- repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + name: isort (python) + args: ["--profile", "black", "--filter-files"] +# IDEA: Might want to look into poetry-specific hooks as well: +# https://python-poetry.org/docs/master/pre-commit-hooks/ + +# NOTE: Works, but takes like 15 seconds, which is too long IMO. +# - repo: local +# hooks: +# - id: pylint +# name: pylint +# entry: poetry +# language: system +# types: [python] +# pass_filenames: false +# args: ["run", "tox", "-e", "lint"] diff --git a/poetry.lock b/poetry.lock index 612466f5..cf6e8fb8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -225,6 +225,18 @@ files = [ [package.dependencies] pycparser = "*" +[[package]] +name = "cfgv" +version = "3.3.1" +description = "Validate configuration and produce human readable error messages." +category = "dev" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "cfgv-3.3.1-py2.py3-none-any.whl", hash = "sha256:c6a0883f3917a037485059700b9e75da2464e6c27051014ad85ba6aaa5884426"}, + {file = "cfgv-3.3.1.tar.gz", hash = "sha256:f5a830efb9ce7a445376bb66ec94c638a9787422f96264c98edc6bdeed8ab736"}, +] + [[package]] name = "chardet" version = "5.1.0" @@ -766,6 +778,21 @@ files = [ [package.dependencies] requests = ">=1.0.0" +[[package]] +name = "identify" +version = "2.5.20" +description = "File identification library for Python" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "identify-2.5.20-py2.py3-none-any.whl", hash = "sha256:5dfef8a745ca4f2c95f27e9db74cb4c8b6d9916383988e8791f3595868f78a33"}, + {file = "identify-2.5.20.tar.gz", hash = "sha256:c8b288552bc5f05a08aff09af2f58e6976bf8ac87beb38498a0e3d98ba64eb18"}, +] + +[package.extras] +license = ["ukkonen"] + [[package]] name = "idna" version = "3.4" @@ -1112,6 +1139,21 @@ files = [ {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, ] +[[package]] +name = "nodeenv" +version = "1.7.0" +description = "Node.js virtual environment builder" +category = "dev" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" +files = [ + {file = "nodeenv-1.7.0-py2.py3-none-any.whl", hash = "sha256:27083a7b96a25f2f5e1d8cb4b6317ee8aeda3bdd121394e5ac54e498028a042e"}, + {file = "nodeenv-1.7.0.tar.gz", hash = "sha256:e0e7f7dfb85fc5394c6fe1e8fa98131a2473e04311a45afb6508f7cf1836fa2b"}, +] + +[package.dependencies] +setuptools = "*" + [[package]] name = "numpy" version = "1.24.2" @@ -1368,6 +1410,25 @@ files = [ dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] +[[package]] +name = "pre-commit" +version = "3.1.1" +description = "A framework for managing and maintaining multi-language pre-commit hooks." +category = "dev" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pre_commit-3.1.1-py2.py3-none-any.whl", hash = "sha256:b80254e60668e1dd1f5c03a1c9e0413941d61f568a57d745add265945f65bfe8"}, + {file = "pre_commit-3.1.1.tar.gz", hash = "sha256:d63e6537f9252d99f65755ae5b79c989b462d511ebbc481b561db6a297e1e865"}, +] + +[package.dependencies] +cfgv = ">=2.0.0" +identify = ">=1.0.0" +nodeenv = ">=0.11.1" +pyyaml = ">=5.1" +virtualenv = ">=20.10.0" + [[package]] name = "prometheus-api-client" version = "0.5.3" @@ -2010,6 +2071,23 @@ dev = ["flake8", "flit", "mypy", "pandas-stubs", "pre-commit", "pytest", "pytest docs = ["ipykernel", "nbconvert", "numpydoc", "pydata_sphinx_theme (==0.10.0rc2)", "pyyaml", "sphinx-copybutton", "sphinx-design", "sphinx-issues"] stats = ["scipy (>=1.3)", "statsmodels (>=0.10)"] +[[package]] +name = "setuptools" +version = "67.6.0" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "setuptools-67.6.0-py3-none-any.whl", hash = "sha256:b78aaa36f6b90a074c1fa651168723acbf45d14cb1196b6f02c0fd07f17623b2"}, + {file = "setuptools-67.6.0.tar.gz", hash = "sha256:2ee892cd5f29f3373097f5a814697e397cf3ce313616df0af11231e2ad118077"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + [[package]] name = "simple-parsing" version = "0.1.0" @@ -2302,4 +2380,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "80d09f05800b6a248786468652eda21c8bde5b7c1c14719add5e2f43da1013f2" +content-hash = "4be4f306ec4db5bef0e59edd9df0cf5df6e4ce0c839490c5a0183b172065edf0" diff --git a/pyproject.toml b/pyproject.toml index c2f31ff4..394c335f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ pytest-regressions = ">= 2.4.2" tox = ">= 4.4.5" pytest-freezegun = ">= 0.4.2" fabric = {extras = ["testing"], version = "^3.0.0"} +pre-commit = "^3.1.1" [tool.poetry.group.examples.dependencies] seaborn = "^0.12.2" From 18c4f6c54912e95232f914fc3ab938e4885f09ee Mon Sep 17 00:00:00 2001 From: Fabrice Normandin Date: Tue, 14 Mar 2023 15:46:46 -0400 Subject: [PATCH 2/2] Add poetry-based hooks as option (takes longer) Signed-off-by: Fabrice Normandin --- .pre-commit-config.yaml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ddba824..3068c423 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,8 +4,8 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.2.0 hooks: - # - id: trailing-whitespace - # - id: end-of-file-fixer + - id: trailing-whitespace + - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - repo: https://github.com/psf/black @@ -18,12 +18,28 @@ repos: - id: isort name: isort (python) args: ["--profile", "black", "--filter-files"] + # IDEA: Might want to look into poetry-specific hooks as well: # https://python-poetry.org/docs/master/pre-commit-hooks/ -# NOTE: Works, but takes like 15 seconds, which is too long IMO. +# NOTE: Does the same thing, but doesn't require hard-coding a version (uses poetry to run the +# hook). This takes much longer (like 7 secs without pylint, and 25 seconds with pylint) vs <1 sec. # - repo: local # hooks: +# - id: black +# name: black +# entry: poetry +# language: system +# types: [python] +# pass_filenames: false +# args: ["run", "tox", "-e", "black_fix"] +# - id: isort +# name: isort +# entry: poetry +# language: system +# types: [python] +# pass_filenames: false +# args: ["run", "tox", "-e", "isort_fix"] # - id: pylint # name: pylint # entry: poetry