From 4d271f981c3ae37f0a556f1b736109be3b543fba Mon Sep 17 00:00:00 2001 From: Nathan Painchaud Date: Mon, 19 Oct 2020 16:19:02 -0400 Subject: [PATCH 1/6] added isort CI job and updated isort config --- .github/workflows/code-formatting.yml | 15 +++++++++++++++ pyproject.toml | 5 +++++ setup.cfg | 5 ----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index e549f5b8f1cfb..25510ba4910d4 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -7,6 +7,21 @@ on: # Trigger the workflow on push or pull request, but only for the master bra branches: [master, "release/*"] jobs: + isort: + name: Check valid import formatting with isort + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install isort + run: pip install isort==5.6.4 + - name: Run isort + run: isort --settings-path=./pyproject.toml --check-only . + code-black: name: Check code formatting with Black runs-on: ubuntu-20.04 diff --git a/pyproject.toml b/pyproject.toml index 539d8117be4d2..4bd2d1a314e37 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,3 +13,8 @@ ignore = ["W504", "W504", "E402", "E731", "C40", "E741", "F40", "F841"] line-length = 120 target-version = ["py38"] exclude = "(.eggs|.git|.hg|.mypy_cache|.nox|.tox|.venv|.svn|_build|buck-out|build|dist)" + +[tool.isort] +known_first_party = ["pytorch_lightning","tests","pl_examples"] +profile = "black" +line_length = 120 diff --git a/setup.cfg b/setup.cfg index 7c31ee5f5542f..f1026b1eac136 100644 --- a/setup.cfg +++ b/setup.cfg @@ -90,8 +90,3 @@ convention = pep257 # D202: Ignore a blank line after docstring (collision with Python Black in decorators) add-ignore = D104,D107,D202 max-line-length = 120 - -[tool:isort] -known_first_party = pytorch_lightning,tests -default_section=THIRDPARTY -line_length=120 From 7ec72d3173ea53f07d90da7f83cc2b0f8520e7ab Mon Sep 17 00:00:00 2001 From: Nathan Painchaud Date: Sun, 25 Oct 2020 22:27:04 -0400 Subject: [PATCH 2/6] changed CI check output from files to full diff --- .github/workflows/code-formatting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 25510ba4910d4..31445c7ae96a3 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -20,7 +20,7 @@ jobs: - name: Install isort run: pip install isort==5.6.4 - name: Run isort - run: isort --settings-path=./pyproject.toml --check-only . + run: isort --settings-path=./pyproject.toml --check-only --diff . code-black: name: Check code formatting with Black From 6852819e952d8a2e3c5cb37005f5083122cfb87b Mon Sep 17 00:00:00 2001 From: Nathan Painchaud Date: Mon, 19 Oct 2020 16:23:06 -0400 Subject: [PATCH 3/6] added isort pre-commit hook --- .pre-commit-config.yaml | 9 +++++++++ requirements/test.txt | 1 + 2 files changed, 10 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 63987145ce9c0..9b481e9ecf0a1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,3 +21,12 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer + + - repo: local + hooks: + - id: isort + name: isort + entry: python -m isort + args: [--settings-path, ./pyproject.toml] + language: system + types: [python] diff --git a/requirements/test.txt b/requirements/test.txt index d98048568fa75..73ec319443e4f 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -9,6 +9,7 @@ check-manifest twine==1.13.0 scikit-image black>=20.8b1 +isort>=5.6.4 pre-commit>=1.0 cloudpickle>=1.2 From 54f3aa545266e7752bce723726337bbf07657014 Mon Sep 17 00:00:00 2001 From: Nathan Painchaud Date: Tue, 10 Nov 2020 11:44:38 -0500 Subject: [PATCH 4/6] Added missing first party and restricted files affected by isort --- pyproject.toml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4bd2d1a314e37..83109f5b6cbb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,17 @@ target-version = ["py38"] exclude = "(.eggs|.git|.hg|.mypy_cache|.nox|.tox|.venv|.svn|_build|buck-out|build|dist)" [tool.isort] -known_first_party = ["pytorch_lightning","tests","pl_examples"] +known_first_party = [ + "bencharmks", + "docs", + "pl_examples", + "pytorch_lightning", + "tests", +] +skip_glob = [ + "pl_examples/*", + "pytorch_lightning/*", + "tests/*" +] # Only apply formatting on root-level scripts, docs and benchmarks profile = "black" line_length = 120 From 91e2b81344b353f71b08681ea5bbf4e265c787ff Mon Sep 17 00:00:00 2001 From: Nathan Painchaud Date: Tue, 10 Nov 2020 11:52:16 -0500 Subject: [PATCH 5/6] Applied isort to root-level, docs and benchmarks --- benchmarks/test_parity.py | 2 +- docs/source/conf.py | 10 +++++----- setup.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/benchmarks/test_parity.py b/benchmarks/test_parity.py index d2bc97deff598..d54742489a62c 100644 --- a/benchmarks/test_parity.py +++ b/benchmarks/test_parity.py @@ -6,7 +6,7 @@ import tests.base.develop_utils as tutils from pytorch_lightning import Trainer, seed_everything -from tests.base.models import ParityModuleRNN, ParityModuleMNIST +from tests.base.models import ParityModuleMNIST, ParityModuleRNN @pytest.mark.parametrize('cls_model,max_diff', [ diff --git a/docs/source/conf.py b/docs/source/conf.py index c662e1e9c912e..bb725893d3346 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -12,14 +12,14 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -import os -import sys +# import m2r +import builtins import glob -import shutil import inspect +import os +import shutil +import sys -# import m2r -import builtins import pt_lightning_sphinx_theme PATH_HERE = os.path.abspath(os.path.dirname(__file__)) diff --git a/setup.py b/setup.py index d25918417e639..e811f7a33d972 100755 --- a/setup.py +++ b/setup.py @@ -15,8 +15,9 @@ import os from io import open + # Always prefer setuptools over distutils -from setuptools import setup, find_packages +from setuptools import find_packages, setup try: import builtins From b07f8fcc98e6ef283a2e79fbcc1d10cbc8c53f0b Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 10 Nov 2020 22:36:58 +0100 Subject: [PATCH 6/6] Apply suggestions from code review --- .github/workflows/code-formatting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 31445c7ae96a3..203c0fb846251 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -7,7 +7,7 @@ on: # Trigger the workflow on push or pull request, but only for the master bra branches: [master, "release/*"] jobs: - isort: + imports-check-isort: name: Check valid import formatting with isort runs-on: ubuntu-20.04 steps: