Commit graph

336 commits

Author SHA1 Message Date
Anthony Sottile
d34581b83f test using python3.10 2021-08-15 19:00:43 -04:00
Ian Stapleton Cordasco
85c2be3b52 Handle new SyntaxError tuple on 3.10
Closes #1372
2021-08-15 18:26:27 -04:00
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
Ian Stapleton Cordasco
2bb0308363
Fix bug for plugins using extend_default_ignore
Since Flake8 3.0 we've had the ability for plugins to use
`extend_default_ignore` to register codes they want disabled by default.
This, however, was a permanent disabling unfortunately. Our code didn't
have a way of understanding that this new set of `ignore` codes was
actually the 'default' set for that run. Much like the
extended_select_list, we now attach extended_ignore_list to be able to
confidently determine if the ignore we get in the DecisionEngine is
actually the Default Ignore list and what plugins what us to ignore by
default.

Refs https://github.com/PyCQA/pep8-naming/pull/157
2021-04-15 13:26:08 -05:00
Frank Winklmeier
f98afbf7d9 Add --extend-select command line argument
Implement `--extend-select` command line argument following what was
done for `--extend-ignore` in !233. This option can be used to
selectively add individual codes without overriding the default list
entirely.

Addresses the remaining item of issue #1061.
2021-04-11 20:40:53 +02:00
Anthony Sottile
737e0492d0 improve code coverage in a few places 2021-04-07 08:52:26 -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
edadccd8dc audit + string joining 2021-03-30 17:37:13 -07:00
Anthony Sottile
5d43462c9d clean up version_info references 2021-03-30 17:37:13 -07:00
Anthony Sottile
358ae85120 automatic: pyupgrade --py36-plus 2021-03-30 17:37:13 -07:00
Anthony Sottile
55f29c636f introduce pyupgrade, run it in python2-compatible mode 2021-03-29 20:21:36 -07:00
Anthony Sottile
83fc824ca1 remove flake8 setuptools command 2021-03-29 20:15:45 -07:00
Anthony Sottile
1a1d850e99 remove vcs integration 2021-03-29 19:01:59 -07:00
Anthony Sottile
40aba49d0d upgrade pycodestyle to 2.7.0 2021-03-14 11:58:03 -07:00
Anthony Sottile
0bf8d2a885 ensure crlf line endings of stdin are handled properly 2021-01-07 09:15:46 -08:00
Anthony Sottile
14857c98e0 fix test which was not testing anything 2021-01-07 08:57:13 -08: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
2fe70dda6b fix a few small spelling issues
found via `pre-commit try-repo https://github.com/codespell-project/codespell --all-files`
2020-09-20 19:16:10 -07: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
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