Skip to content

Commit

Permalink
fix: infinite loop when climbing directories on Windows
Browse files Browse the repository at this point in the history
Fixes #108 (thanks to @Skrierz)
  • Loading branch information
andreoliwa authored Oct 31, 2019
1 parent b8aab98 commit 9915c74
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 56 deletions.
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ root = true
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

# Whitespace at the end of lines
trim_trailing_whitespace = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# Whitespace at the end of lines
trim_trailing_whitespace = true

[*.{yml,yaml}]
indent_size = 2

[Makefile]
indent_style = tab
indent_size = 4
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
# Thanks to https://github.com/sloria/environs/blob/master/.pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v2.4.0
hooks:
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v1.25.0
rev: v1.25.1
hooks:
- id: pyupgrade
- repo: https://github.com/python/black
rev: 19.3b0
rev: 19.10b0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.3.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.3b0]
additional_dependencies: [black==19.10b0]
- repo: https://github.com/asottile/seed-isort-config
rev: v1.9.3
hooks:
Expand All @@ -48,7 +48,7 @@ repos:
types: [python]
always_run: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v2.4.0
hooks:
- id: flake8
additional_dependencies: [flake8-blind-except, flake8-bugbear, flake8-comprehensions,
Expand Down
45 changes: 33 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# https://docs.travis-ci.com/user/reference/xenial/
dist: xenial
env:
global:
- CC_TEST_REPORTER_ID=2da342a92e29aa78fcf1dc84b18af77f8eede63db675363fd1151673be3ce4f3
Expand All @@ -13,22 +11,20 @@ cache:
- $PRE_COMMIT_HOME
# https://docs.travis-ci.com/user/languages/python/
language: python
python:
- "3.5"
- "3.6"
- "3.7"
# https://docs.travis-ci.com/user/reference/xenial/
dist: xenial
install:
- pip3 install --upgrade pip poetry coveralls pre-commit
- poetry install --no-ansi --no-interaction
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then chmod +x ./cc-test-reporter; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then ./cc-test-reporter before-build; fi
script:
- "./.travis/script.sh"
- "./.travis/script.sh $TRAVIS_OS_NAME $TRAVIS_PYTHON_VERSION"
after_script:
- coverage xml
- if [[ "$TRAVIS_PULL_REQUEST" == "false" && "$TRAVIS_PYTHON_VERSION" == "3.6" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
install:
- pip install -U poetry coveralls pre-commit
- poetry install --no-ansi --no-interaction
after_success:
- coverage combine
- coveralls
Expand All @@ -39,6 +35,7 @@ notifications:
stages:
- name: release
if: branch = master
- name: test
jobs:
include:
# Define the release stage that runs semantic-release
Expand All @@ -52,3 +49,27 @@ jobs:
provider: script
skip_cleanup: true
script: semantic-release
- stage: test
python: 3.7
- python: 3.6
- python: 3.5
# Thanks to https://github.com/cclauss/Travis-CI-Python-on-three-OSes/blob/master/.travis.yml
# TODO Build freezing on Windows, see comments on .travis/script.sh
# - name: "Python: 3.8"
# os: windows
# language: shell
# before_install:
# - choco install python
# - python -m pip install --upgrade pip
# env:
# - PATH=/c/Python38:/c/Python38/Scripts:$PATH
# - PYTHONPATH=/c/Users/travis/AppData/Local/pypoetry/Cache/virtualenvs/nitpick-py3.8/lib/site-packages
# - name: "Python: 3.7"
# os: windows
# language: shell
# before_install:
# - choco install python3 --version=3.7.4
# - python -m pip install --upgrade pip
# env:
# - PATH=/c/Python37:/c/Python37/Scripts:$PATH
# - PYTHONPATH=/c/Users/travis/AppData/Local/pypoetry/Cache/virtualenvs/nitpick-py3.7/lib/site-packages
62 changes: 48 additions & 14 deletions .travis/script.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
#!/usr/bin/env bash
echo "Python version = $TRAVIS_PYTHON_VERSION"
export ARG_OS_NAME=$1
export ARG_PYTHON_VERSION=$2

fix=
test "$TRAVIS_PYTHON_VERSION" == '3.4' && fix=fix
test "$TRAVIS_PYTHON_VERSION" == '3.5' && fix=fix
echo "OS = $ARG_OS_NAME"
echo "Python version = $ARG_PYTHON_VERSION"

# Run all pre-commit hooks on Travis.
if [[ "$fix" == 'fix' ]]; then
python3 .travis/fix_pre_commit.py
pre-commit run --all-files --config .travis/.temp-without-black.yaml
else
if [[ "$ARG_OS_NAME" == 'linux' && "$ARG_PYTHON_VERSION" == '3.7' ]]; then
echo "Run all pre-commit hooks only on Python 3.7 Linux"
pre-commit run --all-files

echo "Running flake8 again for nitpick to check itself"
poetry install # This is needed to install nitpick itself, not only the dependencies
poetry run flake8
fi

echo "Running flake8 again for nitpick to check itself"
poetry install # This is needed to install nitpick itself, not only the dependencies
flake8
if [[ "$ARG_OS_NAME" == 'linux' ]]; then
echo "Running pytest with coverage report on Linux"
poetry run coverage run --branch --parallel-mode --source=nitpick -m pytest
else
# TODO Several commands don't work on the Windows build on Travis.
echo "Running pytest with coverage report on Windows"

# Build freezes with message:
# Spawning shell within C:\Users\travis\AppData\Local\pypoetry\Cache\virtualenvs\nitpick-py3.7
# poetry shell

export PYTEST_DEBUG=1
# Build shows debug messages and freezes on this line:
# early skip of rewriting module: text_unidecode [assertion]

echo "Running coverage report"
coverage run --branch --parallel-mode --source=nitpick -m pytest
# Build fails with message:
# No module named 'pytest'
# /c/Users/travis/AppData/Local/pypoetry/Cache/virtualenvs/nitpick-py3.7/activate.bat

# Build freezes with no message:
# poetry run flake8 --help
# poetry run flake8

coverage run --branch --parallel-mode --source=nitpick -m pytest
# Build freezes on test collection:
# ============================= test session starts =============================
# platform win32 -- Python 3.7.4, pytest-5.2.2, py-1.8.0, pluggy-0.13.0 -- c:\users\travis\appdata\local\pypoetry\cache\virtualenvs\nitpick-py3.7\scripts\python.exe
# cachedir: .pytest_cache
# rootdir: C:\Users\travis\build\andreoliwa\nitpick, inifile: setup.cfg
# plugins: repeat-0.8.0, runfailed-0.6
# collecting ...

# All builds fail after 10 minutes with this message:
# No output has been received in the last 10m0s, this potentially indicates
# a stalled build or something wrong with the build itself.
# Check the details on how to adjust your build configuration on:
# https://docs.travis-ci.com/user/common-build-problems/#build-times-out-because-no-output-was-received
# The build has been terminated
fi
10 changes: 5 additions & 5 deletions docs/defaults.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ Content of `styles/black.toml <https://raw.githubusercontent.com/andreoliwa/nitp
[["pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/python/black
rev: 19.3b0
rev: 19.10b0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.3.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.3b0]
additional_dependencies: [black==19.10b0]
"""
# TODO The toml library has issues loading arrays with multiline strings:
# https://github.com/uiri/toml/issues/123
Expand Down Expand Up @@ -86,7 +86,7 @@ Content of `styles/flake8.toml <https://raw.githubusercontent.com/andreoliwa/nit
[["pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v2.4.0
hooks:
- id: flake8
additional_dependencies: [flake8-blind-except, flake8-bugbear, flake8-comprehensions,
Expand Down Expand Up @@ -260,13 +260,13 @@ Content of `styles/pre-commit/general.toml <https://raw.githubusercontent.com/an
[["pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v2.4.0
hooks:
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v1.25.0
rev: v1.25.1
hooks:
- id: pyupgrade
"""
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NOTE: generated by the Makefile
# This will be installed by Read the Docs, from the root folder
Pygments==2.4.2
Sphinx==2.2.0
Sphinx==2.2.1
sphinx-rtd-theme==0.4.3
sphinxcontrib-applehelp==1.0.1
sphinxcontrib-devhelp==1.0.1
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/nitpick/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def climb_directory_tree(starting_path: PathOrStr, file_patterns: Iterable[str])
if current_dir.is_file():
current_dir = current_dir.parent

while current_dir.root != str(current_dir):
while current_dir.anchor != str(current_dir):
for root_file in file_patterns:
found_files = list(current_dir.glob(root_file))
if found_files:
Expand Down
4 changes: 2 additions & 2 deletions styles/black.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ line-length = 120
[["pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/python/black
rev: 19.3b0
rev: 19.10b0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.3.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.3b0]
additional_dependencies: [black==19.10b0]
"""
# TODO The toml library has issues loading arrays with multiline strings:
# https://github.com/uiri/toml/issues/123
Expand Down
2 changes: 1 addition & 1 deletion styles/flake8.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = ".tox,build"
[["pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v2.4.0
hooks:
- id: flake8
additional_dependencies: [flake8-blind-except, flake8-bugbear, flake8-comprehensions,
Expand Down
4 changes: 2 additions & 2 deletions styles/pre-commit/general.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[["pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v2.4.0
hooks:
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v1.25.0
rev: v1.25.1
hooks:
- id: pyupgrade
"""
4 changes: 2 additions & 2 deletions tests/test_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def test_suggest_initial_contents(request):
hooks:
- id: isort
- repo: https://github.com/python/black
rev: 19.3b0
rev: 19.10b0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.3.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.3b0]\x1b[0m
additional_dependencies: [black==19.10b0]\x1b[0m
"""
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,15 @@ def test_merge_styles_into_single_file(request):
[["pre-commit-config.yaml".repos]]
yaml = """
- repo: https://github.com/python/black
rev: 19.3b0
rev: 19.10b0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.3.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.3b0]
additional_dependencies: [black==19.10b0]
"""
[["pre-commit-config.yaml".repos]]
Expand Down

0 comments on commit 9915c74

Please sign in to comment.