Commit graph

295 commits

Author SHA1 Message Date
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
ec8fcfc8f8 Add typing to OptionManager.parse_args()
Note that the `assert` is necessary to "cast" `self.parser` since it is
specified as a `Union`.
2019-08-31 00:10:40 -04:00
Eric N. Vander Weele
8ea3c6321d Add typing to OptionManager.parse_known_args()
Note that type casting is necessary given that `self.parser` is
annotated as a `Union`.
2019-08-30 14:17:20 -04:00
Eric N. Vander Weele
220a9287f5 Remove unused parameter from OptionManager.parse_known_args()
The `values` parameter is not utilized anywhere and can be safely
removed.
2019-08-30 12:30:33 -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
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
76515bbb8e Apply suggestion to src/flake8/formatting/base.py 2019-08-18 22:05:00 +00: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
Anthony Sottile
4b7208936a Merge branch 'deprecate_setuptools_command' into 'master'
Deprecate the flake8 setuptools integration

Closes #544

See merge request pycqa/flake8!330
2019-08-01 21:26:24 +00: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
f01011a403 Normalize option values additionally by type
Now that the contract has narrowed for `utils.normalize_paths()`
and `utils.parse_comma_separated_list()`, `Option.normalize()` must
handle when the option value is either a singular value or a sequence
(i.e., `list`) of values.

The paths where `Option.normalize()` is called are:

1. options/config.py: `MergedConfigParser.parse_*_config()`
    There are 3 paths wehre eventually `_normalize_value()` is called.
2. options/manager.py: `OptionManager.parse_args()`

For (1), values are coming from the `configparser` module.  For (2),
values are coming from `optparse.OptionParser`.

Rudimentary investigation seems to implicate that
`optparse.OptionParser.parse_args()` always returns values in a `list`
because it accumulates values.  However, for `configparser`, the values
are a string due to the key-value nature of the INI format.

Given that `Option.normalize()` is the convergence point where
normalization of an option occurs, it is acceptable for the method to
also handle the parsing comma-separated values and path normalization by
the option value's type.
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
a0cd55fd6d utils: Assert desired contract for normalize_paths()
This is a separate commit so it can be dropped during a rebase or revert
independently.
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
Eric N. Vander Weele
9fbaf2d2ea utils: Assert desired contract for parse_comma_separated_list()
This is a separate commit so it can be dropped during a rebase or
reverted independently.
2019-07-28 10:39:27 -04:00
Anthony Sottile
862b17d229 Merge branch 'extra-config-normalization' into 'master'
Push down extra config file path normalization into main config handling

See merge request pycqa/flake8!333
2019-07-23 04:29:28 +00:00
Eric N. Vander Weele
95f26d7fe9 Push down extra config file path normalization into main config handling
Move the path normalization for extra configuration file paths down into
the main `config` module where other path normalization occurs.

This also guarantees that the call to `utils.normalize_paths()` is given
a sequence, instead of a potential `None` value.
2019-07-22 21:29:24 -04:00
Anthony Sottile
77abc11a6f Deprecate the flake8 setuptools integration 2019-07-08 15:22:51 -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
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
Anthony Sottile
aa792d2930 Release 3.7.8 2019-07-08 11:21:04 -07:00
Eric N. Vander Weele
24e8b8163c pyflakes: Change to normalize_path() for filename normalization
It's unnecessary to call the `normalize_paths()` function because it is
intended for dealing with multiple paths to normalize.  Given that
`normalize_paths()` utilizes `normalize_path()`, just call
`normalize_path()` directly.
2019-07-08 09:58:24 -07:00
Anthony Sottile
7506847c9a fix CI build 2019-07-08 09:07:37 -07:00
Markus Piotrowski
0ac337608b This PR addresses issue #549 (noqa does only work as intended with single letter error codes). A single change in the regex NOQA_INLINE_REGEXP in defaults.py will allow to catch error codes which consist of more than one letter.
This will close #549.
2019-06-16 15:55:37 +00:00
Anthony Sottile
2f8bc64b1e Merge branch 'show_traceback' into 'master'
Show traceback on plugin exception

See merge request pycqa/flake8!317
2019-06-14 18:03:39 +00:00
Ivan Pozdeev
6813f159d7 Show traceback on plugin exception 2019-05-20 22:44:03 +03: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
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
88caf5ac48 Release 3.7.7 2019-02-25 08:36:58 -08:00
Anthony Sottile
e8de066f94 Ensure exceptions are pickleable 2019-02-19 08:38:37 -08:00
Anthony Sottile
9b770f590e Release 3.7.6 2019-02-18 11:58:12 -08:00
Ian Stapleton Cordasco
59c2f093de Merge branch 'mypy_improvements' into 'master'
Improve a few mypy type annotations

See merge request pycqa/flake8!307
2019-02-17 15:23:30 +00:00
Ian Stapleton Cordasco
a21d74152b Merge branch 'perf_only_one_proc' into 'master'
Speed up flake8 when only 1 filename is passed

See merge request pycqa/flake8!305
2019-02-17 15:23:12 +00:00
Anthony Sottile
c71fadb18c Improve a few mypy type annotations 2019-02-17 00:16:19 -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
Anthony Sottile
a252a0b138 Remove pyflakes monkeypatching 2019-02-16 18:05:00 -08:00
Илья Лебедев
8e99b531cf FIX 507: allow multiple letters in codes 2019-02-11 17:00:34 +03:00
Anthony Sottile
e7b8493b5d Release 3.7.5 2019-02-04 08:37:16 -08:00
Anthony Sottile
8df38c92b9 Fix reporting of UndefinedLocal pyflakes error 2019-01-31 21:55:10 -08:00
Anthony Sottile
3d54751236 Remove noqa comments now that 3.7 has been released 2019-01-31 20:12:23 -08:00
Anthony Sottile
afc57d471d Release 3.7.4 2019-01-31 19:53:02 -08:00
Anthony Sottile
c85b282b05 Fix performance regression with per-file-ignores
With a large number of errors, filenames, and per-file-ignores the style guide
selection would take a significant portion of execution time
(python3 70% / python2 99.9%).

Caching the styleguide lookup by filename eliminates this bottleneck.
2019-01-31 09:23:02 -08:00
Anthony Sottile
ee7081c8ce Release 3.7.3 2019-01-30 19:55:58 -08:00
Anthony Sottile
f955a98b71 Improve error message for malformed per-file-ignores 2019-01-30 19:33:54 -08:00