diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index 1ad4e3b1a4..44c71aca1d 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -33,16 +33,16 @@ jobs: run: | python --version # just to check pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors - pip install --upgrade codecov chardet "setuptools!=47.2.0" docutils setuptools_scm[toml] + pip install --upgrade chardet "setuptools!=47.2.0" docutils setuptools_scm[toml] pip install aspell-python-py3 pip install -e ".[dev]" # install the codespell dev packages - run: codespell --help - run: codespell --version - run: make check + - uses: codecov/codecov-action@v3 - run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*" # this file has an error - run: "! codespell codespell_lib/tests/test_basic.py" - - run: codecov make-check-dictionaries: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 1b7db2d20b..c3704dda05 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ codespell.egg-info .mypy_cache/ .pytest_cache/ codespell_lib/_version.py +junit-results.xml +*.egg-info/ diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 598aa72aa5..df55894980 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -647,14 +647,22 @@ def parse_file(filename, colors, summary, misspellings, exclude_lines, if not os.path.isfile(filename): return bad_count - text = is_text_file(filename) + try: + text = is_text_file(filename) + except PermissionError as e: + print("WARNING: %s: %s" % (e.strerror, filename), + file=sys.stderr) + return bad_count + except OSError: + return bad_count + if not text: if not options.quiet_level & QuietLevels.BINARY_FILE: print("WARNING: Binary file: %s" % filename, file=sys.stderr) return bad_count try: lines, encoding = file_opener.open(filename) - except Exception: + except OSError: return bad_count for i, line in enumerate(lines): diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 8b73584a46..ffae8b64e7 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -122,6 +122,20 @@ def test_basic(tmpdir, capsys): assert cs.main(d) == 0 +@pytest.mark.skipif( + not sys.platform == 'linux', reason='Only supported on Linux') +def test_permission_error(tmp_path, capsys): + """Test permission error handling.""" + d = tmp_path + with open(d / 'unreadable.txt', 'w') as f: + f.write('abandonned\n') + code, _, stderr = cs.main(f.name, std=True) + assert 'WARNING:' not in stderr + os.chmod(f.name, 0o000) + code, _, stderr = cs.main(f.name, std=True) + assert 'WARNING:' in stderr + + def test_interactivity(tmpdir, capsys): """Test interaction""" # Windows can't read a currently-opened file, so here we use diff --git a/setup.cfg b/setup.cfg index 7074b31afd..9776335475 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [tool:pytest] -addopts = --cov=codespell_lib -rs --cov-report= --tb=short +addopts = --cov=codespell_lib -rs --cov-report= --tb=short --junit-xml=junit-results.xml [flake8] exclude = build, ci-helpers