Commit graph

337 commits

Author SHA1 Message Date
Byeonghoon Yoo
9a45593aae
Add disable_noqa attribute to FileProcessor 2019-11-05 21:54:24 +09:00
Eric N. Vander Weele
6c117cedd7 aggregator: Simplify 'aggregate_options' function definition
The `values` parameter is safe to remove since it is not provided as an
argument by any callers and the remaining arguments are guaranteed to
always be provided by all callers.
2019-11-03 01:11:43 +00:00
Anthony Sottile
ff871fe656 Merge branch 'application-argv-required-for-parsing' into 'master'
application: Make 'parse_configuration_and_cli' parameter required

See merge request pycqa/flake8!375
2019-11-03 01:10:34 +00:00
Anthony Sottile
f7f9c61108 Merge branch 'application-parse-prelim-opts' into 'master'
application: Rename prelim parsing method to 'parse_preliminary_options'

See merge request pycqa/flake8!374
2019-11-03 01:09:51 +00:00
Eric N. Vander Weele
f8960020d0 application: Make 'parse_configuration_and_cli' parameter required
The remaining CLI arguments is now always provided as an argument this
method.
2019-11-03 01:35:25 +08:00
Eric N. Vander Weele
1abe1d42c2 application: Rename prelim parsing method to 'parse_preliminary_options'
Positional arguments are not used nor parsed for pre-configuration
loading.  Thus, renaming the method and updating the docstrings
appropriately.
2019-11-03 01:34:38 +08:00
Eric N. Vander Weele
3ac3349ef3 application: Simplify creation of configuration file finder
This commit simplifies and updates the method for handling the creation
of the configuration file finder.  The main takeaways are:

- Renaming the parameter (i.e., `extra_config_files`) to be a noun to
  better describe the input versus what the option name was called.
- Refreshed the docstring to align with changes from previous commits
  and this one.
- Remove the check to see if it a configuration file finder was already
  created.  This is not necessary as each entire run of a `flake8` calls
  this method once.  When the programmatic API is provided,
  configuration would be provided 'in-code' and not rely upon external
  files/resources.
- Use directly the program name from the `Application`, itself since
  this is the authoritative source for defining it.
2019-11-03 01:32:38 +08:00
Eric N. Vander Weele
80e05866fc Reformat with black >= 19.10b0
This resets the `black` formatting baseline so it doesn't get picked up
in future commits.
2019-11-01 21:26:12 -04: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
87acf9e5fc Merge branch '3.7-maintenance' into 'master'
Merge 3.7.9 tag and release notes

See merge request pycqa/flake8!369
2019-10-28 17:54:40 +00:00
Anthony Sottile
ee2920d775 Release 3.7.9 2019-10-28 10:34:54 -07:00
Anthony Sottile
04f49a7a77 Only use multiprocessing when the method is fork
In python3.8 on macos and in all versions on windows the multiprocessing
method is `spawn` which does not preserve class state.
2019-10-28 10:00:18 -07: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
Anthony Sottile
51f32bbe93 Only use multiprocessing when the method is fork
In python3.8 on macos and in all versions on windows the multiprocessing
method is `spawn` which does not preserve class state.
2019-10-28 09:43:30 -07:00
Eric N. Vander Weele
b42e758ac7 linters: Add flake8-bugbear for finding bugs and design problems
Also, make appropriate changes to satisfy issues flagged by
`flake8-bugbear`.
2019-10-25 17:11:30 -04:00
Eric N. Vander Weele
964b3a9c21 application: Forward remaining unknown arguments to final CLI parsing
Now that `parse_preliminary_options_and_args()` ignores unknown options
and arguments, forward the remaining unknown arguments to the main CLI
and configuration method to be consumed.  This prevents re-parsing the
entire `argv` list again by forwarding the remaining arguments left to
be consumed.
2019-10-25 17:07:43 -04:00
Eric N. Vander Weele
4151ae0e53 application: Ensure --version is unknown during preliminary parsing
Now that the preliminary parser is being used, we can remove needing to
prune out `--version` and copying the original `argv` list.
2019-10-25 17:07:43 -04:00
Eric N. Vander Weele
b9c8c3e118 application: Ensure -h/--help is unknown during preliminary parsing
Now that the preliminary parser is being used, we can remove needing to
prune out `-h` and `--help` from the copied `args` list.
2019-10-25 17:07:43 -04:00
Eric N. Vander Weele
2260f5362e application: Keep unknown options in the unknown argument list
Positional arguments aren't necessary for determining where to
load configuration anymore and is safe to keep both options and
arguments to be forwarded for later parsing after configuration is
loaded.
2019-10-25 17:07:43 -04:00
Eric N. Vander Weele
7f46990f4b application: Change to argparse.ArgumentParser for preliminary parsing
Now that preliminary options are registered with the preliminary parser
on the `Application`, leverage that for parsing known options.

This important change removes the `Application.option_manager` from
being responsible for pre-configuration parsing and the workarounds
needed in the `Application.parse_preliminary_options_and_args()` to
account for the fact that `Application.option_manager` was aware of
*all* options, not just the options necessary for pre-configuration
loading.  A following commit will address removing these workarounds.
2019-10-25 17:07:43 -04: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
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
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
b3a31496b7 config: Search for configuration relative to current working directory
This is the initial incision to only search for configuration relative
to the current working directory where `flake8` is invoked.  This brings
configuration file detection closer to other CLI-like programs.
2019-10-13 13:37:19 -04:00
Eric N. Vander Weele
5fc1d3def0 Reformat files via black
This was missed in bb12b83.
2019-10-13 13:35:56 -04:00
Anthony Sottile
daca2c80db Merge branch 'remove-output-file-config' into 'master'
options: Remove parsing `--output-file` from the configuration file

See merge request pycqa/flake8!361
2019-10-13 03:48:44 +00:00
Eric N. Vander Weele
bb12b83cc0 options: Remove parsing --output-file from the configuration file
The `--output-file` option is used when parsing and handling preliminary
options for logging.  It is also used to set `BaseFormatter.filename`.
Towards ensuring that the option is respected consistently for both
logging and formatting plugins, only observe the value from the CLI.
2019-10-12 15:36:17 +01: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
5cce7c2cc3 Merge branch 'type_more' into 'master'
Add more type annotations

See merge request pycqa/flake8!353
2019-09-08 06:45:41 +00:00
Anthony Sottile
f0cd1537ac Simplify bandit config and allow assert 2019-09-07 23:42:33 -07:00
Anthony Sottile
92fbdda253 Add type annotations for flake8.processor 2019-09-07 23:31:43 -07:00
Anthony Sottile
ae2f38fbeb Add type annotations to flake8.styleguide 2019-09-07 23:10:28 -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
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
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
76515bbb8e Apply suggestion to src/flake8/formatting/base.py 2019-08-18 22:05:00 +00:00