From 0d01715e4bf8587ba73cebba32b00b25fca3fd13 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 16 Dec 2019 23:24:55 +0100 Subject: [PATCH 1/5] [pre-commit] Add configuration file for pre-commit, flake8 and isort --- .flake8 | 4 ++++ .isort.cfg | 7 +++++++ .pre-commit-config.yaml | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 .flake8 create mode 100644 .isort.cfg create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000000..24c80daa6f4 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +max-line-length = 79 +select = B,C,E,F,W,T4,B9,B950 +ignore = E501, W503, E203 diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000000..a8ee33b7a5d --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,7 @@ +[settings] +multi_line_output=3 +include_trailing_comma=true +force_grid_wrap=0 +use_parentheses=true +ensure_newline_before_comments=true +line_length=79 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..6fc0c606708 --- /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/timothycrosley/isort + rev: 5.6.4 + hooks: + - id: isort + files: .*.py + - repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + args: ["--line-length", "79"] + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: check-ast + - id: check-case-conflict + - id: trailing-whitespace + - id: end-of-file-fixer + - id: debug-statements + - id: check-added-large-files + - id: check-docstring-first + - id: check-yaml + exclude: conda/meta.yaml + - repo: https://github.com/PyCQA/flake8 + rev: 3.8.4 + hooks: + - id: flake8 + - repo: https://github.com/PyCQA/bandit + rev: 1.6.2 + hooks: + - id: bandit From 64202e06ff6319ceb2911c19f39bcde8560659c9 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Thu, 15 Oct 2020 09:23:17 +0200 Subject: [PATCH 2/5] [setup] Pre-commit cleanup --- setup.py | 107 ++++++++++++++++++++++++------------------------------- 1 file changed, 47 insertions(+), 60 deletions(-) diff --git a/setup.py b/setup.py index 59cd134d59e..ecf64b46e85 100644 --- a/setup.py +++ b/setup.py @@ -20,95 +20,82 @@ import codecs import re from glob import glob -from os.path import join, dirname, abspath +from os.path import abspath, dirname, join -from setuptools import setup, find_namespace_packages +from setuptools import find_namespace_packages, setup here = abspath(dirname(__file__)) def read(*parts): - with codecs.open(join(here, *parts), 'r') as fp: + with codecs.open(join(here, *parts), "r") as fp: return fp.read() def find_version(*file_paths): version_file = read(*file_paths) - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", - version_file, re.M) + version_match = re.search( + r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M + ) if version_match: return version_match.group(1) raise RuntimeError("Unable to find version string.") install_requires = [ - 'aiofiles==0.5.*', - 'ansimarkup>=1.0.0', - 'colorama>=0.4,<=1', - 'click>=7.0', - 'graphene>=2.1,<3', - 'jinja2==2.11.*', - 'metomi-isodatetime>=1!2.0.2, <1!2.1.0', - 'protobuf==3.13.*', - 'pyuv==1.4.*', - 'pyzmq==19.0.*', - 'psutil>=5.6.0', - 'urwid==2.*' + "aiofiles==0.5.*", + "ansimarkup>=1.0.0", + "colorama>=0.4,<=1", + "click>=7.0", + "graphene>=2.1,<3", + "jinja2==2.11.*", + "metomi-isodatetime>=1!2.0.2, <1!2.1.0", + "protobuf==3.13.*", + "pyuv==1.4.*", + "pyzmq==19.0.*", + "psutil>=5.6.0", + "urwid==2.*", ] tests_require = [ - 'async-timeout>=3.0.0', - 'async_generator', - 'codecov>=2.0.0', - 'coverage>=5.0.0', - 'flake8>=3.0.0', - 'pycodestyle>=2.5.0', - 'pytest-asyncio>=0.14.0', - 'pytest-cov>=2.8.0', - 'pytest-xdist>=2', - 'pytest>=6', - 'testfixtures>=6.11.0' + "async-timeout>=3.0.0", + "async_generator", + "codecov>=2.0.0", + "coverage>=5.0.0", + "flake8>=3.0.0", + "pycodestyle>=2.5.0", + "pytest-asyncio>=0.14.0", + "pytest-cov>=2.8.0", + "pytest-xdist>=2", + "pytest>=6", + "testfixtures>=6.11.0", ] extra_requires = { - 'empy': [ - 'EmPy==3.3.*' - ], - 'all': [], - 'report-timings': [ - 'pandas==1.*' - ], - 'main_loop-log_data_store': [ - 'pympler', - 'matplotlib' - ], - 'main_loop-log_main_loop': [ - 'matplotlib' - ], - 'main_loop-log_memory': [ - 'pympler', - 'matplotlib' - ] + "empy": ["EmPy==3.3.*"], + "all": [], + "report-timings": ["pandas==1.*"], + "main_loop-log_data_store": ["pympler", "matplotlib"], + "main_loop-log_main_loop": ["matplotlib"], + "main_loop-log_memory": ["pympler", "matplotlib"], } -extra_requires['all'] = ( - tests_require - + list({ - req - for reqs in extra_requires.values() - for req in reqs - }) +extra_requires["all"] = tests_require + list( + {req for reqs in extra_requires.values() for req in reqs} ) setup( version=find_version("cylc", "flow", "__init__.py"), - long_description=open('README.md').read(), + long_description=open("README.md").read(), long_description_content_type="text/markdown", - scripts=glob(join('bin', '*')), + scripts=glob(join("bin", "*")), packages=find_namespace_packages(include=["cylc.*"]), package_data={ - 'cylc.flow': [ - 'etc/*.yaml', 'etc/flow*.eg', 'etc/job.sh', - 'etc/syntax/*', 'etc/cylc-bash-completion' + "cylc.flow": [ + "etc/*.yaml", + "etc/flow*.eg", + "etc/job.sh", + "etc/syntax/*", + "etc/cylc-bash-completion", ] }, install_requires=install_requires, @@ -117,6 +104,6 @@ def find_version(*file_paths): project_urls={ "Documentation": "https://cylc.github.io/documentation.html", "Source": "https://github.com/cylc/cylc-flow", - "Tracker": "https://github.com/cylc/cylc-flow/issues" - } + "Tracker": "https://github.com/cylc/cylc-flow/issues", + }, ) From 65b8e5b2fc6ae8818fcaee989d954eb0b7f25fa2 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Thu, 15 Oct 2020 09:24:38 +0200 Subject: [PATCH 3/5] [setup] Add pre-commit to extra dependencies --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index ecf64b46e85..fbbde3ebe8e 100644 --- a/setup.py +++ b/setup.py @@ -77,6 +77,7 @@ def find_version(*file_paths): "main_loop-log_data_store": ["pympler", "matplotlib"], "main_loop-log_main_loop": ["matplotlib"], "main_loop-log_memory": ["pympler", "matplotlib"], + "dev": ["pre-commit"], } extra_requires["all"] = tests_require + list( {req for reqs in extra_requires.values() for req in reqs} From 897c31b9a95d4c0555ad2a88156c0c5e4b208137 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sun, 19 Jan 2020 23:13:04 +0100 Subject: [PATCH 4/5] [contributing] Add contribution setup and pre-commit steps --- CONTRIBUTING.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ac3c9206b62..b7a63ddfacd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,6 +24,17 @@ add their details to the [Code Contributors](#code-contributors) section of this file as part of their first Pull Request, and reviewers are responsible for checking this before merging the new branch into *master*. +In order to start modifying cylc-flow and test these changes, the first step is +to call `pip install -e .[all]`. This will install the package in development +mode along all needed dependencies. + +Before the first commit care should be taken to call `pre-commit install` in +order for the git pre-commit hooks to be run on commit. [pre-commit +](https://pre-commit.com) is used for code style consistency. It can also be run +manually when developing with the `pre-commit run` command. To run the hooks on +a reduced set of files, cal `pre-commit run --files` followed by one of more +files to process. + ## Code Contributors The following people have contributed to this code under the terms of From 385bd1a6c4468bcf9adc60a7b886bf94ee4fb9ed Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Wed, 28 Oct 2020 00:24:19 +0100 Subject: [PATCH 5/5] [tests] Fix pycodestyle issue --- tests/functional/jinja2/filters/Jinja2Filters/truly.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/jinja2/filters/Jinja2Filters/truly.py b/tests/functional/jinja2/filters/Jinja2Filters/truly.py index bc71ec7f1ba..6b0359ec9d5 100644 --- a/tests/functional/jinja2/filters/Jinja2Filters/truly.py +++ b/tests/functional/jinja2/filters/Jinja2Filters/truly.py @@ -14,5 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + def truly(bar): return 'true'