Commit graph

413 commits

Author SHA1 Message Date
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
1d7558f7da optmanager: Inherit options from parent argument parsers
Allow for including options from parent `argparse.ArgumentParser`
objects in preparation of splitting out the handling of preliminary
options from the `OptionManager`.
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
66f832d291 application: Remove forwarding unused preliminary arguments
The `ConfigFileFinder` doesn't utilize the preliminary arguments (i.e.,
the file names) anymore for computing the starting path for the
configuration file search.
2019-10-13 13:37:19 -04:00
Eric N. Vander Weele
3f1bdc74a9 tests: Verify ConfigFileFinder behavior based on getcwd()
Update the tests now that `ConfigFileFinder` searches relative to the current working directory.
2019-10-13 13:37:19 -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
Eric N. Vander Weele
6017022942 options: Remove parsing --verbose from the configuration file
The `--verbose` option is only used by `flake8`, itself,` when parsing
and handling preliminary options.  After parsing and merging options
from the configuration file, there is no other behavioral impact to the
core of `flake8`.  In other words, setting `verbose = ...` in a
configuration file doesn't change the logging verbosity.

While the `FileProcessor` does expose a `verbose` attribute, obtained
from the parsed options, the verbosity of the core of `flake8` should be
consistent with how a plugin may respond to the attribute's value.
2019-10-12 14:25:50 +01:00
Eric N. Vander Weele
b54164f916 application: Remove preliminary argument parsing state
The preliminary options and arguments returned from
`.parse_preliminary_options_and_args()` are now all threaded through to
the appropriate methods during initialization.
2019-10-01 08:48:18 +02:00
Eric N. Vander Weele
95a88e3fcd application: Pass prelim opts to .find_plugins()
The configuration file and boolean to ignore configuration files can be
threaded through now that `.parse_preliminary_options_and_args()`
returns options and arguments.
2019-10-01 08:48:18 +02:00
Eric N. Vander Weele
32ebb4fa55 application: Pass prelim opts and args to .make_config_finder()
Now that `.parse_preliminary_options_and_args()` returns options and
arguments, the boolean for appending configuration and the arguments can
be threaded through to the creation of the `ConfigFileFinder`.
2019-10-01 08:48:18 +02:00
Eric N. Vander Weele
55ef2c6f5e application: Pass returned prelim options to .configure_logging()
The verbosity and output file options can be obtained from options
returned by `.parse_preliminary_options_and_args()`, instead of state
from the `Application` object.
2019-10-01 08:48:18 +02:00
Eric N. Vander Weele
6043e90855 application: Return namespace and args from preliminary arg parsing
This is the initial step towards removing state from the `Application`
object during argument parsing and handling.  The goal is to remove
`Application.prelim_opts` and `Application.prelim_args`.
2019-10-01 08:48:18 +02:00
Anthony Sottile
fdcec2803a Don't reset indent_char when we encounter E101 2019-09-24 13:54:32 -07:00
Anthony Sottile
92fbdda253 Add type annotations for flake8.processor 2019-09-07 23:31:43 -07:00
Anthony Sottile
8c4e42afaa Type annotate flake8.options.manager 2019-09-07 14:37:50 -07:00
Eric N. Vander Weele
aadd09dd8b Set configuration file-provided values via ArgumentParser.set_defaults()
When calling `ArgumentParser.parse_args()` with the `namespace`
argument, command-line options are just added to the  namespace without
going through any of the argument parsing and type conversion logic
(e.g., the `type` keyword argument of `ArgumentParser.add_argument()`).
In other words, it is assumed that a namespace is well-formed from a
previous invocation of `ArgumentParser.parse_args()`.

The `values` parameter is intended to be values already-provided from
configuration files.  To take advantage of the logic defined by
`ArgumentParser.add_argument()`,  utilize
`ArgumentParser.set_defaults()` instead.
2019-08-31 00:10:46 -04:00
Eric N. Vander Weele
b231c10016 Test default provided options are forwarded
Ensure options provided external to the command-line (i.e.,
configuration files) are present in the final result of options.
2019-08-31 00:10:46 -04:00
Eric N. Vander Weele
c2216c0ddf Add typings to ConfigFileFinder constructor
`OptionManager.parse_known_args()` is guaranteed to return a list of
remaining argument strings.
2019-08-29 16:36:47 -04: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
8fd36ba15b Put plugin options into separate argparse groups 2019-08-19 15:58:34 -07:00
Anthony Sottile
b66ebd7034 move from optparse to argparse 2019-08-17 20:09:45 -07:00
Anthony Sottile
e8c79dcd33 Fix --show-source when indented with tabs 2019-08-10 11:37:01 -07:00
Eric N. Vander Weele
1757bce321 utils: Tighten parse_comma_separated_list() contract further
Now that callers are ensuring that `value` is not `None`, we can further
tighten the contract and remove the conditional to account when `None`
is passed-in for `value`.

Additionally, add a new test vector to account for when an empty string
is passed in, which would fail `if no value`.
2019-07-28 10:43:06 -04:00
Eric N. Vander Weele
1ba56b9056 utils: Change normalize_paths() contract
The `normalize_paths()` utility was doing too much — parsing
unstructured configuration path data and dispatching the scrubbed paths
to be normalized.

Towards moving the parsing of unstructured configuration path data
closer towards were configuration occurs, have the utility accept only
structured input for normalizing paths.
2019-07-28 10:43:06 -04:00
Eric N. Vander Weele
9283f2f03f utils: Change parse_comma_separated_list() contract
This is the initial incision point to only accept `str` (or `None`) for
parsing out comma/whitespace/regexp separated values.
2019-07-28 10:43:02 -04: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
0d7247082e Merge branch 'master' into 'master'
Remove filter by filename in utils.filenames_from

Closes #382

See merge request pycqa/flake8!311
2019-07-08 20:11:25 +00:00
Markus Piotrowski
37964dbd84 Update test_violation.py
Added tests to check if long error codes are correctly identified.
2019-06-16 17:02:54 +00:00
Anthony Sottile
fb7e9338cd mypy now passes 2019-05-19 17:31:04 -07:00
Anthony Sottile
dcd37ec3d4 whitelist a bandit false positive and improve type annotation 2019-05-19 09:39:14 -07:00
Anthony Sottile
38ab47702a Fix crash when file fails to tokenize but parses 2019-04-07 07:42:00 -07:00
Yevhen Amelin
6fb49b2e80 Remove filter by filename in utils.filenames_from 2019-03-19 09:59:12 +02:00
Charles Frye
e9b9ebb58e makes prelim_args test more explicit 2019-03-11 14:05:34 -07:00
Charles Frye
16ca17388a Fixes handling of empty lists by Application
`Application.parse_preliminary_options_and_args` was previously, against
expectations, treating empty lists passed as the `argv` argument the
same way it treated `None`s.

This has been addressed and the correct behavior tested for in a unit
test of the `Application` class.

See issue #518 for details.
2019-03-07 20:27:59 -08:00
Anthony Sottile
e8de066f94 Ensure exceptions are pickleable 2019-02-19 08:38:37 -08:00
Anthony Sottile
e8f43e1243 Speed up flake8 when only 1 filename is passed
~40% improvement over status quo (perf measurements are best-of-5)

### before

```console
$ time flake8 /dev/null

real    0m0.337s
user    0m0.212s
sys     0m0.028s
```

### after

```console
$ time flake8 /dev/null

real    0m0.197s
user    0m0.182s
sys     0m0.012s
```
2019-02-17 00:15:00 -08:00
Илья Лебедев
8e99b531cf FIX 507: allow multiple letters in codes 2019-02-11 17:00:34 +03:00
Anthony Sottile
8df38c92b9 Fix reporting of UndefinedLocal pyflakes error 2019-01-31 21:55:10 -08: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
941b120819 Merge branch 'is/490' into 'master'
Fix bug flake8 --diff

Closes #490

See merge request pycqa/flake8!292
2019-01-30 18:09:54 +00:00
Anthony Sottile
915184a1e9 Add integration test for flake8 --diff 2019-01-30 09:54:13 -08:00
Anthony Sottile
3579e4e198 Fix linters 2019-01-30 08:58:59 -08:00
Tomer Keren
a4f5447fc8 Refactor file processor tests to use fixture 2019-01-30 08:57:25 -08:00
Tomer Keren
92a037684f Fix python2 unicode test error
I guess that if you don't have something python2 compliant to say. might as well say nothing at all
Also fix linter errors
2019-01-30 08:55:57 -08:00
Tomer Keren
bdf3ce9135 Fix dogfood 2019-01-30 08:55:57 -08:00
Tomer Keren
b64421c5e8 Write a test checking plugin failure exception handling 2019-01-30 08:55:57 -08:00