From 7ba9c50e79ad18a25d7285bde5333fc76521aac1 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Mon, 19 Oct 2020 10:18:47 +0100 Subject: [PATCH 1/6] move non-standard-imports over to pre-commit --- .pre-commit-config.yaml | 29 ++++++++++++++++++++++++----- ci/code_checks.sh | 25 ------------------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index df10e35288144..c30dcb3b46baa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,12 +56,31 @@ repos: - id: incorrect-sphinx-directives name: Check for incorrect Sphinx directives language: pygrep - entry: >- - \.\. (autosummary|contents|currentmodule|deprecated - |function|image|important|include|ipython|literalinclude - |math|module|note|raw|seealso|toctree|versionadded - |versionchanged|warning):[^:] + entry: "\ + \\.\\. (autosummary|contents|currentmodule|deprecated\ + |function|image|important|include|ipython|literalinclude\ + |math|module|note|raw|seealso|toctree|versionadded\ + |versionchanged|warning):[^:]" files: \.(py|pyx|rst)$ + - id: non-standard-imports + name: Check for non-standard imports + language: pygrep + entry: "\ + from pandas\\.core\\.common import\ + |from pandas\\.core import common\ + |from collections\\.abc import\ + |from numpy import nan" + types: [python] + - id: non-standard-imports-in-tests + name: Check for non-standard imports in test suite + language: pygrep + entry: "\ + from pandas\\._testing import\ + |from pandas import _testing as tm\ + |conftest import\ + |import conftest" + types: [python] + files: ^pandas/tests/ - id: incorrect-code-directives name: Check for incorrect code block or IPython directives language: pygrep diff --git a/ci/code_checks.sh b/ci/code_checks.sh index cb34652e11cd3..c40afe4ec81e3 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -143,31 +143,6 @@ fi ### PATTERNS ### if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then - # Check for imports from pandas.core.common instead of `import pandas.core.common as com` - # Check for imports from collections.abc instead of `from collections import abc` - MSG='Check for non-standard imports' ; echo $MSG - invgrep -R --include="*.py*" -E "from pandas.core.common import" pandas - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "from pandas.core import common" pandas - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "from collections.abc import" pandas - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "from numpy import nan" pandas - RET=$(($RET + $?)) ; echo $MSG "DONE" - - # Checks for test suite - # Check for imports from pandas._testing instead of `import pandas._testing as tm` - invgrep -R --include="*.py*" -E "from pandas._testing import" pandas/tests - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "from pandas import _testing as tm" pandas/tests - RET=$(($RET + $?)) ; echo $MSG "DONE" - - # No direct imports from conftest - invgrep -R --include="*.py*" -E "conftest import" pandas/tests - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "import conftest" pandas/tests - RET=$(($RET + $?)) ; echo $MSG "DONE" - MSG='Check for use of exec' ; echo $MSG invgrep -R --include="*.py*" -E "[^a-zA-Z0-9_]exec\(" pandas RET=$(($RET + $?)) ; echo $MSG "DONE" From 7ce873d39f8c9e202eee9284855ebbe894acb2f1 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Tue, 20 Oct 2020 17:37:08 +0100 Subject: [PATCH 2/6] update to use verbose regular expression --- .pre-commit-config.yaml | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c30dcb3b46baa..c5be00f709168 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,29 +56,35 @@ repos: - id: incorrect-sphinx-directives name: Check for incorrect Sphinx directives language: pygrep - entry: "\ - \\.\\. (autosummary|contents|currentmodule|deprecated\ - |function|image|important|include|ipython|literalinclude\ - |math|module|note|raw|seealso|toctree|versionadded\ - |versionchanged|warning):[^:]" + entry: | + (?x)\.\.\ ( + autosummary|contents|currentmodule|deprecated| + function|image|important|include|ipython|literalinclude| + math|module|note|raw|seealso|toctree|versionadded| + versionchanged|warning + ):[^:] files: \.(py|pyx|rst)$ - id: non-standard-imports name: Check for non-standard imports language: pygrep - entry: "\ - from pandas\\.core\\.common import\ - |from pandas\\.core import common\ - |from collections\\.abc import\ - |from numpy import nan" + entry: | + (?x)^( + from\ pandas\.core\.common\ import + from\ pandas\.core\ import\ common| + from\ collections\.abc\ import| + from\ numpy\ import\ nan + ) types: [python] - id: non-standard-imports-in-tests name: Check for non-standard imports in test suite language: pygrep - entry: "\ - from pandas\\._testing import\ - |from pandas import _testing as tm\ - |conftest import\ - |import conftest" + entry: | + (?x)^( + from\ pandas\._testing\ import| + from\ pandas\ import\ _testing\ as\ tm| + conftest\ import| + import\ conftest + ) types: [python] files: ^pandas/tests/ - id: incorrect-code-directives From fd1b359b10d865886f3072026fa85255bcdc202b Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Tue, 20 Oct 2020 17:38:08 +0100 Subject: [PATCH 3/6] missing or --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c5be00f709168..6a060419a1379 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,7 +69,7 @@ repos: language: pygrep entry: | (?x)^( - from\ pandas\.core\.common\ import + from\ pandas\.core\.common\ import| from\ pandas\.core\ import\ common| from\ collections\.abc\ import| from\ numpy\ import\ nan From d414d7b1075e3ff843593b0ce77cee4313afba87 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Wed, 21 Oct 2020 10:23:14 +0100 Subject: [PATCH 4/6] add comments --- .pre-commit-config.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a060419a1379..451fbfd712fd3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,7 +57,9 @@ repos: name: Check for incorrect Sphinx directives language: pygrep entry: | - (?x)\.\.\ ( + (?x) + # Check for cases of e.g. .. warning: instead of .. warning:: + \.\.\ ( autosummary|contents|currentmodule|deprecated| function|image|important|include|ipython|literalinclude| math|module|note|raw|seealso|toctree|versionadded| @@ -69,7 +71,9 @@ repos: language: pygrep entry: | (?x)^( + # Check for imports from pandas.core.common instead of `import pandas.core.common as com` from\ pandas\.core\.common\ import| + # Check for imports from collections.abc instead of `from collections import abc` from\ pandas\.core\ import\ common| from\ collections\.abc\ import| from\ numpy\ import\ nan @@ -80,8 +84,10 @@ repos: language: pygrep entry: | (?x)^( + # Check for imports from pandas._testing instead of `import pandas._testing as tm` from\ pandas\._testing\ import| from\ pandas\ import\ _testing\ as\ tm| + # No direct imports from conftest conftest\ import| import\ conftest ) From e35d843c63c9b0190b44c0d6c80e7902df08d1af Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Wed, 21 Oct 2020 10:25:24 +0100 Subject: [PATCH 5/6] dedent --- .pre-commit-config.yaml | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 451fbfd712fd3..acb1adc49812e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,27 +70,25 @@ repos: name: Check for non-standard imports language: pygrep entry: | - (?x)^( - # Check for imports from pandas.core.common instead of `import pandas.core.common as com` - from\ pandas\.core\.common\ import| - # Check for imports from collections.abc instead of `from collections import abc` - from\ pandas\.core\ import\ common| - from\ collections\.abc\ import| - from\ numpy\ import\ nan - ) + (?x) + # Check for imports from pandas.core.common instead of `import pandas.core.common as com` + from\ pandas\.core\.common\ import| + # Check for imports from collections.abc instead of `from collections import abc` + from\ pandas\.core\ import\ common| + from\ collections\.abc\ import| + from\ numpy\ import\ nan types: [python] - id: non-standard-imports-in-tests name: Check for non-standard imports in test suite language: pygrep entry: | - (?x)^( - # Check for imports from pandas._testing instead of `import pandas._testing as tm` - from\ pandas\._testing\ import| - from\ pandas\ import\ _testing\ as\ tm| - # No direct imports from conftest - conftest\ import| - import\ conftest - ) + (?x) + # Check for imports from pandas._testing instead of `import pandas._testing as tm` + from\ pandas\._testing\ import| + from\ pandas\ import\ _testing\ as\ tm| + # No direct imports from conftest + conftest\ import| + import\ conftest types: [python] files: ^pandas/tests/ - id: incorrect-code-directives From 55a07c08faa11d2dccc41f57245fbb47493faa9e Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Wed, 21 Oct 2020 10:28:41 +0100 Subject: [PATCH 6/6] :art: --- .pre-commit-config.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index acb1adc49812e..e7738fb9a2979 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -73,9 +73,11 @@ repos: (?x) # Check for imports from pandas.core.common instead of `import pandas.core.common as com` from\ pandas\.core\.common\ import| - # Check for imports from collections.abc instead of `from collections import abc` from\ pandas\.core\ import\ common| + + # Check for imports from collections.abc instead of `from collections import abc` from\ collections\.abc\ import| + from\ numpy\ import\ nan types: [python] - id: non-standard-imports-in-tests @@ -86,6 +88,7 @@ repos: # Check for imports from pandas._testing instead of `import pandas._testing as tm` from\ pandas\._testing\ import| from\ pandas\ import\ _testing\ as\ tm| + # No direct imports from conftest conftest\ import| import\ conftest