Commit graph

413 commits

Author SHA1 Message Date
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
Ruairidh MacLeod
9b8f908314 fix JobsArgument --help output 2020-06-05 14:25:57 +01: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
563220b711 config: Normalize paths in CLI-specified config relative to config dir
Paths specified in configuration files should be relative to the
directory where the configuration file resides.  Formerly, paths were
normalized relative to the current working directory where `flake8` was
invoked.  The former behavior was not expected, especially for directory
structures with subprojects each having their own configuration.
2020-05-18 17:23:08 -04:00
Ruairidh MacLeod
45573570cf Parse --jobs as a custom argparse type. Fixes #567 2020-05-13 13:25:51 -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
03c7dd3a8d Merge branch 'exclude_dotfiles' into 'master'
Fix using --exclude=.* to not match `.` and `..`

Closes #632

See merge request pycqa/flake8!424
2020-05-07 19:38:30 +00:00
Anthony Sottile
9e67511c69 Fix using --exclude=.* to not match . and .. 2020-05-07 12:34:38 -07:00
Anthony Sottile
609010ce7a Fix logical checks which report position out of bounds 2020-05-07 11:16:00 -07:00
Anthony Sottile
3b490bb3c5 Fix type='str' optparse options 2020-04-24 10:43:54 -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
Eric N. Vander Weele
aab1f14375 config: Determine path to user configuration immediately
Preemptively determine the path of the user configuration file during
the construction of the `ConfigFileFinder` object.  The user
configuration path will always be the same, regardless of when it gets
obtained by a run of `flake8`.

This isolates the logic of determining the user configuration path into
a static helper method to be called to set the `.user_config_file`
attribute.  The helper method leverages `utils.is_windows()`, instead of
reimplementing the check, and decomposes clearly the directory name and
the base name to construct the path with a single `return` path.
Additionally, this avoids reconstructing the path on demand of obtaining
the user configuration file path.
2020-01-20 16:54:50 -05:00
Eric N. Vander Weele
716db1167e config: Remove checks for configs being previously parsed
Remove the checks to see if a configuration file has already been seen
and parsed.  These checks aren't necessary because the entire run of
`flake8` calls these methods *only* once per configuration provided.
2020-01-20 12:53:49 -05: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
153032f778 config: Add 'config_file' parameter to ConfigFileFinder
The `--config` flag is passed into `MergedConfigParser.parse()` and the
module-level function `config.get_local_plugins()`.  Since both of these
places utilize the `ConfigFileFinder` object and the configuration file
override pertains to how configuration behaves, this incremental change
directly associates the `ConfigFileFinder` and the configuration file
override.
2020-01-12 23:19:26 -05:00
Eric N. Vander Weele
e887ef3317 config: Remove ConfigFileFinder 'parent' and 'tail' attributes
These attributes are only needed within the
`.generate_possible_local_files()` method.  Therefore, just obtain the
current working directory at the beginning of the method and reduce the
lifetime state of the `ConfigFileFinder` object.
2020-01-12 23:13:11 -05:00
Eric N. Vander Weele
98d3d50295 tests: Ensure patched os.getcwd() is an absolute path
`os.getcwd()` returns an absolute path; thus, the patched paths should
be absolute as well.

This is an incremental change towards removing the `ConfigFileFinder`
attributes `.parent` and `.tail` to be localized to
`.generate_possible_local_files()`.  Without this, the tests fail when
moving the patching because `os.path.abspath()` calls `os.getcwd()`,
expecting `os.getcwd()` to be an absolute path.
2020-01-12 23:13:04 -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
a5c17c1a19 config: Add 'ignore_config_files' parameter to ConfigFileFinder
The `--isolated` flag is passed into `MergedConfigParser.parse()` and
the module-level function `config.get_local_plugins()`.  Since both of
these places utilize the `ConfigFileFinder` object and isolation
pertains to how the `ConfigFileFinder` should behave with respect to
isolation, this incremental change more directly associates the
`ConfigFileFinder` and configuration file isolate.
2020-01-07 12:54:47 -05:00
Eric N. Vander Weele
1a4060cd5f config: Change ConfigFileFinder._read_config() to accept variadic args
This simplifies `._read_config()` by removing a conditional branch in
the situation where it is called with one file to process.  Now the
contract accepts any number of arguments of the same type.

Where callers invoke `._read_config()` with a `Sequence`, the call site
has been changed to unpack arguments (i.e., `*`).

The tests in `test_merged_config_parser.py` needed to return a string
for the user configuration path instead of an empty list since
`ConfigFileFinder.user_config_file()` returns a string.
2020-01-06 22:23:12 -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
Eric N. Vander Weele
9fa5663986 application: Inline creation of config.ConfigFileFinder
Simplify the initialization code path by invoking
`config.ConfigFileFinder` directly instead of the extra hop by calling
the static class-level `Application.make_config_finder()` method.
2019-12-03 13:21:01 -05:00
Anthony Sottile
21d2adf21f Merge branch 'fix/disable_noqa' into 'master'
`--disable-noqa` does not override `# flake8: noqa`

Closes #590

See merge request pycqa/flake8!380
2019-12-03 17:45:45 +00:00
Anthony Sottile
1062be2643 Merge branch 'fix/exit-zero' into 'master'
Fix --exit-zero when --diff is empty

See merge request pycqa/flake8!391
2019-12-02 06:25:27 +00:00
Kinya TERASAKA
cc037338df Fixes --exit-zero when empty --diff
fixes pycqa/flake8/merge_requests!137
2019-12-02 13:47:15 +09:00
Anthony Sottile
d3c95f00d0 Switch from entrypoints to importlib_metadata 2019-11-28 17:30:52 -08:00
Eric N. Vander Weele
594c16abb4 application: Remove configuration finder state
This change removes the `.config_finder` object from the `Application`.
Since the configuration finder is only needed during initialization, we
constrain the finder to be returned and passed to other methods
necessary for initialization.
2019-11-22 11:04:40 -05:00
Isac Yoo
3b80b2e05a
Remove redundant sample data 2019-11-13 11:58:49 +09:00
Eric N. Vander Weele
d75088b199 application: Change make_config_finder to be a pure static method
This change makes `Application.make_config_finder` to be side-effect
free where it its return value is only determined by its input values.
2019-11-06 12:18:15 +08:00
Byeonghoon Yoo
705c16a268
Fix codes 2019-11-06 00:28:09 +09:00
Byeonghoon Yoo
29d8b11209
Add unit test for dd411e95 2019-11-05 22:00:05 +09: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
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
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
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