Skip to content

Commit

Permalink
CI move non-standard-import checks over to pre-commit (pandas-dev#37240)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored and JulianWgs committed Oct 26, 2020
1 parent daff98c commit 14b4793
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
42 changes: 37 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,44 @@ 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)
# 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|
versionchanged|warning
):[^:]
files: \.(py|pyx|rst)$
- id: non-standard-imports
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|
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
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
types: [python]
files: ^pandas/tests/
- id: incorrect-code-directives
name: Check for incorrect code block or IPython directives
language: pygrep
Expand Down
25 changes: 0 additions & 25 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,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"
Expand Down

0 comments on commit 14b4793

Please sign in to comment.