Commit graph

60 commits

Author SHA1 Message Date
Jouke Witteveen
efc15cf4f1 Automatically create output directories 2021-05-10 16:41:01 +02:00
Anthony Sottile
456e98486e short circuit on ast error before tokenization error 2021-04-18 10:08:11 -07:00
Anthony Sottile
af1668bf04 extend black formatting to tests as well 2021-04-18 09:23:48 -07:00
Anthony Sottile
3f10c04fd0 fix mypy errors 2021-04-07 08:28:11 -07:00
Anthony Sottile
3b57778160 fix links in code 2021-04-03 18:21:02 -07:00
Anthony Sottile
358ae85120 automatic: pyupgrade --py36-plus 2021-03-30 17:37:13 -07:00
Anthony Sottile
40aba49d0d upgrade pycodestyle to 2.7.0 2021-03-14 11:58:03 -07:00
Anthony Sottile
0efbb5dbcb Merge branch 'no_show_source' into 'master'
Add option to disable show-source for calling tools

See merge request pycqa/flake8!441
2020-10-02 23:40:04 +00:00
Anthony Sottile
ee9c2874a9 fix skipping of physical checks when file does not end in newline 2020-09-12 12:03:23 -07:00
Nekokatt
e6a5f6a663 Support linting when missing sem_open syscall
Platforms such as Termux on Android, and other exotic devices
do not provide a sem_open implementation on the OS level. This
is problematic, as the error resulting from this occurs when
calling multiprocessing.Pool, throwing an unhandled ImportError.

The issue itself is outlined in https://bugs.python.org/issue3770.

This change allows devices missing this system call to respond
to the missing feature by falling back to synchronous execution,
which appears to be the default behaviour if the multiprocessing
module is not found.

This change also adds a potential fix for developers working
on platforms where multiprocessing itself cannot be imported.
The existing code would set the name referencing the import to
None, but there are no clear checks to ensure this does not
result in an AttributeError later when multiprocessing.Pool
has accession attempts.

Existing users should see no difference in functionality, as they
will assumably already be able to use flake8, so will not be
missing this sem_open call.

Users on devices without the sem_open call will now be able
to use flake8 where they would be unable to before due to
unhandled ImportErrors.
2020-08-27 15:41:25 -07:00
Miro Hrončok
91b09d5b37 Tests: Add a value to mocked entry_points, so pytest 6+ can log it
Pytest 6.0.0rc1 attempts to log a repr of our mocked entry_point,
but it fails, becasue the repr metohod expects a valua attribute:

Reproducer:

    $ tox -e py38 --force-dep 'pytest==6.0.0rc1'
    ...
    Traceback (most recent call last):
      File "/usr/lib/python3.8/logging/__init__.py", line 1081, in emit
        msg = self.format(record)
      File "/usr/lib/python3.8/logging/__init__.py", line 925, in format
        return fmt.format(record)
      File "/usr/lib/python3.8/logging/__init__.py", line 664, in format
        record.message = record.getMessage()
      File "/usr/lib/python3.8/logging/__init__.py", line 369, in getMessage
        msg = msg % self.args
      File "/tmp/flake8/.tox/py38/lib/python3.8/site-packages/flake8/plugins/manager.py", line 44, in __repr__
        self.name, self.entry_point.value
      File "/tmp/flake8/.tox/py38/lib/python3.8/site-packages/mock/mock.py", line 632, in __getattr__
        raise AttributeError("Mock object has no attribute %r" % name)
    AttributeError: Mock object has no attribute 'value'
2020-07-20 17:49:12 +02:00
Anthony Sottile
b40af6737e Add option to disable show-source for calling tools 2020-06-19 10:01:04 -07:00
Eric N. Vander Weele
a68d4d0172 processor: Catch SyntaxError also when generating tokens for a file
`tokenize.generate_tokens()` can also raise `SyntaxError` in addition to
`tokenize.TokenError`.
2020-06-02 11:38:44 -07:00
Anthony Sottile
31c2f9f366 treat --extend-exclude as a file list 2020-05-21 16:41:02 -07:00
Eric N. Vander Weele
e6d8a90e5d options: Forward --output-file to be reparsed for BaseFormatter
This fixes a regression introduced in daca2c8 and b14d47b.

The --output-file` option was consumed by the preliminary option parser.
However, the `BaseFormatter` class needs the option for setting the
output filename.  This special cases this option to ensure it gets
re-parsed and respected when specified on the CLI.
2020-05-11 22:17:52 -07:00
Anthony Sottile
609010ce7a Fix logical checks which report position out of bounds 2020-05-07 11:16:00 -07:00
Anthony Sottile
93a17a806d instrument coverage on tests and require 100% coverage there 2020-03-23 12:15:29 -07:00
Anthony Sottile
28797a57d8 Allow noqa to apply to lines due to continuation 2020-03-17 22:12:56 -07:00
Anthony Sottile
d583f051ed Merge branch 'file_not_found_error' into 'master'
Ensure that a not-found file produces an error

Closes #600

See merge request pycqa/flake8!404
2020-01-16 22:59:38 +00:00
Anthony Sottile
32c7ebcd7b split lines the same when read from stdin 2020-01-16 14:10:33 -08:00
Anthony Sottile
bfb79b46c8 Ensure that a not-found file produces an error
- this restores a flake8 2.x behaviour that was lost in the refactor
2020-01-16 12:53:37 -08:00
Eric N. Vander Weele
eb6698c420 config: Make ConfigFileFinder 'extra_config_files' parameter optional
This simplifies the number of required parameters needed for the
`ConfigFileFinder` object throughout the various tests.
2020-01-12 23:28:52 -05:00
Eric N. Vander Weele
1e3bad20dd Remove unused 'cli_config' parameter
Now that `ConfigFileFinder.config_file` attribute is used everywhere and
is constructed from the `--config` CLI option, the now unused
`cli_config` parameters can be safely removed.
2020-01-12 23:19:26 -05:00
Eric N. Vander Weele
77b2506071 config: Switch code paths to use 'ConfigFileFinder.config_file'
Now that the `ConfigFileFinder` has the `.config_file` attribute, switch
the relevant code paths to utilize this public attribute.

Tests have been updated to either construct `ConfigFileFinder` or mock
the object appropriately.
2020-01-12 23:19:26 -05:00
Eric N. Vander Weele
c918e72496 Remove unused 'isolated' parameter
Now that `ConfigFileFinder.ignore_config_files` attribute is used
everywhere and is constructed from the `--isolated` CLI option, the now
unused `isolated` parameters can be safely removed.
2020-01-07 13:14:34 -05:00
Eric N. Vander Weele
3d546d448a config: Switch code paths to use 'ConfigFileFinder.ignore_config_files'
Now that the `ConfigFileFinder` has the `.ignore_config_files`
attribute, switch the relevant code paths to utilize this public
attribute.

Tests have been updated to either construct `ConfigFileFinder` or mock
the object appropriately.
2020-01-07 13:03:34 -05:00
Eric N. Vander Weele
738c8490ec tests: Add integration tests for --config and --isolated
Prevent regressions by adding integration tests to ensure that these
options are passed through to `aggregator.aggregate_options()`.
2019-12-29 19:17:31 -05:00
Eric N. Vander Weele
7f9f70064c aggregator: Forward --config and --isolated options during aggregation
This fixes a regression introduced in !346 to ensure that `--config` and
`--isolated` are recognized in `aggregate_options()`.

The regression manifested because `aggregate_options()` was relying on
re-parsing `argv` to obtain the option values.  However, !346 changed
the preliminary parsing logic to only parse and "eat" what is necessary
and forward along the options needed before all the configuration was
loaded.  This code path was overlooked because the tests in
`test_aggregator()` were passing but the call from the `Application`
object would never have these options in the remaining `argv` list to be
passed long.
2019-12-29 18:07:51 -05:00
Anthony Sottile
d3c95f00d0 Switch from entrypoints to importlib_metadata 2019-11-28 17:30:52 -08:00
Anthony Sottile
b14d47b356 Merge branch 'separate-prelim-options' into 'master'
Separate pre-configuration CLI parsing

See merge request pycqa/flake8!364
2019-10-31 21:05:07 +00:00
Anthony Sottile
7441c63de8 Merge branch 'specific_noqa_pycodestyle' into 'master'
Do not pass `noqa` to plugins, have flake8 decide whether to report

Closes #552

See merge request pycqa/flake8!331
2019-10-28 16:51:09 +00:00
Eric N. Vander Weele
a90200353e application: Register preliminary options on a separate argument parser
We introduce a new `ArgumentParser` for registering the preliminary
options to be inherited by the `Application.option_manager`.  The next
step will be to use the `Application.prelim_arg_parser` for parsing and
handling preliminary options and arguments.

Note that we prevent the preliminary parser from handling `-h/--help`
and defer to that to the primary parser.
2019-10-25 17:07:43 -04:00
Eric N. Vander Weele
2a5c2bb696 options: Split-out registration of preliminary options
This is in preparation for having separate `ArgumentParser`s for
preliminary and the remaining options.
2019-10-25 17:07:43 -04:00
Eric N. Vander Weele
584402fa1c config: Remove args parameter from ConfigFileFinder.__init__
Now that `args` parameters is not being used, it is safe to remove from
the constructor signature.

Further work is required to evaluate and clean-up tearing out the
threading-through of `args` from various callers and tests.
2019-10-13 13:37:19 -04:00
Anthony Sottile
fdcec2803a Don't reset indent_char when we encounter E101 2019-09-24 13:54:32 -07:00
Anthony Sottile
5144196abd Do not pass noqa to plugins, have flake8 decide whether to report 2019-08-29 13:14:12 -07:00
Eric N. Vander Weele
cf4bc53c12 Hoist passing through sys.argv at the CLI layer
`flake8.main.cli.main()` is the primary entry point for the command-line
implementation of flake8 (invoked via `__main__` or `console_scripts`).
Therefore, it is reasonable for the entry point to be responsible for
obtaining command line arguments from `sys.argv` there.

Note that `sys.argv[1:]` is necessary in order to strip off the script
name.  Formerly, this was not needed in
`Application.parse_preliminary_options_and_args()`, which was using
`sys.argv[:]` because the result of the argument parsing was just for
determining additional configuration to be loaded.  Then, the *real* CLI
argument parsing was forwarding the original `None` value to
`argparse.ArgumentParser.parse_args()`, which internally was obtaining
arguments as `sys.argv[1:]`.

Additionally, the contract for various argument parsing methods to be
guaranteed a `List[str]`.
2019-08-29 16:06:02 -04:00
Anthony Sottile
b66ebd7034 move from optparse to argparse 2019-08-17 20:09:45 -07:00
Anthony Sottile
d4b0073167 Fix / improve recently merged patches + CI 2019-07-08 14:22:51 -07:00
Thomas Grainger
9ba6677c4a support extend-exclude Fixes #535 2019-07-08 20:12:47 +00:00
Anthony Sottile
fb7e9338cd mypy now passes 2019-05-19 17:31:04 -07:00
Anthony Sottile
38ab47702a Fix crash when file fails to tokenize but parses 2019-04-07 07:42:00 -07:00
Anthony Sottile
f955a98b71 Improve error message for malformed per-file-ignores 2019-01-30 19:33:54 -08:00
Anthony Sottile
b0ecf3d28f Fix flake8 --statistics 2019-01-30 14:39:24 -08:00
Anthony Sottile
137b45ac2f Fix legacy api invocation of make_notifier 2019-01-30 11:00:36 -08:00
Anthony Sottile
915184a1e9 Add integration test for flake8 --diff 2019-01-30 09:54:13 -08:00
Tom Milligan
2803d0a810
checker: allow physical checks to return multiple results, add tests 2018-12-10 17:42:53 +00:00
Anthony Sottile
ff15ba0865 Replace setuptools with entrypoints 2018-11-05 11:08:37 -08:00
Carl Meyer
423980164b Add paths option in local-plugins config file. 2017-10-24 19:58:18 -07:00
Carl Meyer
4e58068657 Add support for local (in-repo, non-setuptools) plugins.
Closes #357
2017-08-03 00:25:37 -07:00