afonasev / flake8-plugin-utils

The package provides base classes and utils for flake8 plugin writing
MIT License
18 stars 8 forks source link

Add support for flake8 getting input via stdin #47

Closed ddelange closed 3 years ago

ddelange commented 3 years ago
$ python -c "from packaging.markers import default_environment; print(default_environment())"
{'implementation_name': 'cpython', 'implementation_version': '3.7.9', 'os_name': 'posix', 'platform_machine': 'x86_64', 'platform_release': '19.6.0', 'platform_system': 'Darwin', 'platform_version': 'Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64', 'python_full_version': '3.7.9', 'platform_python_implementation': 'CPython', 'python_version': '3.7', 'sys_platform': 'darwin'}
$ pip list | grep flake
flake8                        3.8.4
flake8-absolute-import        1.0
flake8-blind-except           0.1.1
flake8-builtins               1.5.3
flake8-cognitive-complexity   0.1.0
flake8-comprehensions         3.2.3
flake8-docstrings             1.5.0
flake8-logging-format         0.6.0
flake8-mutable                1.2.0
flake8-plugin-utils           1.3.1
flake8-polyfill               1.0.2
flake8-print                  3.1.4
flake8-printf-formatting      1.1.0
flake8-pytest-style           1.2.3
flake8-quotes                 3.2.0
flake8-tuple                  0.4.1

Description

This plugin breaks my linting setup, and therefore had to uninstall it (plus its dependent flake8-pytest-style).

My editor is Sublime Text (latest). The linting system used is SublimeLinter (latest), which I point to the flake8 bin in my venv.

What I Did

SublimeLinter does something like

cat test.py | ~/.pyenv/versions/myvenv/bin/flake8 --format default --ignore=W503 --exclude=.git -

With a subsequent error:

SublimeLinter: #14 linter.py:61       ERROR: Traceback (most recent call last):
  File "~/vv/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "~/vv/lib/python3.7/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "~/vv/lib/python3.7/site-packages/flake8/main/application.py", line 363, in run
    self._run(argv)
  File "~/vv/lib/python3.7/site-packages/flake8/main/application.py", line 351, in _run
    self.run_checks()
  File "~/vv/lib/python3.7/site-packages/flake8/main/application.py", line 264, in run_checks
    self.file_checker_manager.run()
  File "~/vv/lib/python3.7/site-packages/flake8/checker.py", line 323, in run
    self.run_serial()
  File "~/vv/lib/python3.7/site-packages/flake8/checker.py", line 307, in run_serial
    checker.run_checks()
  File "~/vv/lib/python3.7/site-packages/flake8/checker.py", line 589, in run_checks
    self.run_ast_checks()
  File "~/vv/lib/python3.7/site-packages/flake8/checker.py", line 494, in run_ast_checks
    for (line_number, offset, text, _) in runner:
  File "~/vv/lib/python3.7/site-packages/flake8_plugin_utils/plugin.py", line 75, in run
    self._load_file()
  File "~/vv/lib/python3.7/site-packages/flake8_plugin_utils/plugin.py", line 87, in _load_file
    with open(self._filename, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'stdin'

When I uninstall this plugin and its dependent(s) from my venv, SublimeLinter starts annotating my files with flake8 warnings as expected.

cfcohen commented 3 years ago

For anyone looking to workaround this issue, see pull request https://github.com/afonasev/flake8-plugin-utils/pull/52.

m-burst commented 3 years ago

JFYI, this should probably be working after #56 was merged. I've released flake8-pytest-style v1.4.2 which depends on the new version of this library.

ddelange commented 3 years ago

JFYI, this should probably be working after #56 was merged. I've released flake8-pytest-style v1.4.2 which depends on the new version of this library.

Can confirm that this error does not occur anymore with flake8-plugin-utils-1.3.2 flake8-pytest-style-1.4.2 🎉