Commit Graph

65 Commits

Author SHA1 Message Date
Ran Benita e847b2a5a9 pre-commit: replace `debug-statements` hook with ruff
Ruff supports this functionality so we can use it.
2024-04-28 17:06:07 +03:00
Ran Benita 58136c5376 hookspec: deprecate hookimpls requesting py.path parameters 2024-04-21 11:37:56 +03:00
Pierre Sassoulas 1125296b53 Small performance/readability improvments when iterating dictionnary with ``keys()``
Based on pylint's message ``consider-iterating-dictionary`` suggestion.
Surprisingly using a dict or set comprehension instead of a new temp var is
actually consistently slower here, which was not intuitive for me.

```python
from timeit import timeit

families = {1: {"testcase": [1, 2, 3, 5, 8]}}
attrs = {1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h"}

class Old:
    def old(self):
        self.attrs = attrs
        temp_attrs = {}
        for key in self.attrs.keys():
            if key in families[1]["testcase"]:
                temp_attrs[key] = self.attrs[key]
        self.attrs = temp_attrs

class OldBis:
    def old(self):
        self.attrs = attrs
        temp_attrs = {}
        for key in self.attrs:
            if key in families[1]["testcase"]:
                temp_attrs[key] = self.attrs[key]
        self.attrs = temp_attrs

class New:
    def new(self):
        self.attrs = attrs
        self.attrs = { # Even worse with k: v for k in self.attrs.items()
            k: self.attrs[k] for k in self.attrs if k in families[1]["testcase"]
        }

if __name__ == "__main__":
    n = 1000000
    print(f"Old: {timeit(Old().old, number=n)}")
    print(f"Just removing the keys(): {timeit(OldBis().old, number=n)}")
    print(f"List comp, no temp var: {timeit(New().new, number=n)}")
```

Result:
Old: 0.9493889989680611
Just removing the keys(): 0.9042672360083088
List comp, no temp var: 0.9916125109884888

It's also true for the other example with similar benchmark, but the exact
code probably does not need to be in the commit message.
2024-03-31 14:43:07 +02:00
Pierre Sassoulas bd9b62161a [tooling] Add a manual step to run pylint in pre-commit 2024-03-31 14:43:07 +02:00
pre-commit-ci[bot] c0532dda18
[pre-commit.ci] pre-commit autoupdate (#12115)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Ran Benita <ran@unusedvar.com>
2024-03-13 15:30:18 +02:00
Bruno Oliveira 86945f9a1f
Rename 'testing' extra to 'dev' (#12052)
Minor, but seems `dev` is more standard for the development extras than `testing`, being the default for tools like `poetry`.
2024-03-07 19:12:19 -03:00
Pierre Sassoulas 7da04c963f [ruff] Add unwanted pylint message to the ignore list 2024-02-10 23:42:36 +01:00
Pierre Sassoulas 1180348303 [ruff] Add 'consider-using-in' from pylint
See https://pylint.readthedocs.io/en/latest/user_guide/messages/refactor/consider-using-in.html
An automated fix from ruff is available (but it's unsafe for now).
2024-02-10 15:47:44 +01:00
Ran Benita a182e10b06 Enable lint PGH004 - Use specific rule codes when using noqa 2024-02-09 11:14:36 +02:00
Ran Benita d1ee6d154f Enable flake8-pie 2024-02-09 11:08:33 +02:00
Ran Benita d02618d173 Fix ruff deprecation warning
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`:
  - 'ignore' -> 'lint.ignore'
  - 'select' -> 'lint.select'
2024-02-09 10:48:05 +02:00
Pierre Sassoulas d1095426c1 Update setuptools version to the one that support pyproject.toml 2024-02-06 14:40:31 +01:00
Pierre Sassoulas 757778f5f6 [pyproject-fmt] Add pre-commit hook and autofix existing 2024-02-06 14:40:31 +01:00
Pierre Sassoulas c76ea72331 [pyproject.toml] Moving 'package_data' (py.typed) from setup.cfg 2024-02-05 21:04:33 +01:00
Pierre Sassoulas 411c2cbf9d [pyproject.toml] Translate dynamic option to pyproject.toml 2024-02-05 21:03:28 +01:00
Pierre Sassoulas a1d99e4bdd [pyproject.toml] Move information from setup.cfg to pyproject.toml 2024-02-05 21:02:32 +01:00
Ran Benita 79de84941a setup.cfg: move mypy configuration from setup.cfg to pyproject.toml
TOML is a nicer format than the INI format setup.cfg uses.
2024-02-05 11:59:27 +02:00
Pierre Sassoulas 3101c026b9 [flake8-bugbear] Remove hidden global state to import only once 2024-02-04 23:08:38 +01:00
Pierre Sassoulas e193a263c7 [flake8-pyi] Add checks for flake8-pyi and fix existing 2024-02-04 19:27:23 +01:00
Pierre Sassoulas 4eb246d4e1 [flake8-bugbear] noqa B023 not bound by design 2024-02-04 19:27:23 +01:00
Pierre Sassoulas 41ff3584d7 [flake8-bugbear] Fixes a B017 we can actually fix and noqa the two others 2024-02-04 19:27:23 +01:00
Pierre Sassoulas b62d4b3527 [flake8-bugbear] Remove misleading multiple characters in lstrip
See https://pylint.readthedocs.io/en/stable/user_guide/messages/error/bad-str-strip-call.html
2024-02-04 19:27:23 +01:00
Pierre Sassoulas e7bab63537 [flake8-bugbear] noqa all the useless comparison that are justified 2024-02-04 19:27:23 +01:00
Pierre Sassoulas 52fba25ff9 [flake8-bugbear] Fix all the useless expressions that are justified 2024-02-04 19:27:23 +01:00
Pierre Sassoulas fcb818b73c [flake8-bugbear] Re-raise all exceptions with proper exception chaining 2024-02-04 19:27:23 +01:00
Pierre Sassoulas 7eef4619d5 [flake8-bugbear] Add checks from flake8 bugbear 2024-02-04 19:27:16 +01:00
Ran Benita cb5f738858 Ignore isort on _version.py
The file is generated. This makes `ruff src/` run cleanly (when not
running through pre-commit).
2024-02-02 21:29:30 +02:00
Pierre Sassoulas 233ab89f13 [ruff] Fix all consider [*cats, garfield] instead of cats + [garfield] 2024-02-02 15:18:38 +01:00
Pierre Sassoulas 8967c527ff [ruff] Activate use next(iter(x)) instead of list(x)[0] and fix issue 2024-02-02 15:18:38 +01:00
Pierre Sassoulas 180a16a344 [ruff] Fix ambiguous characters found in string and comment 2024-02-02 15:18:38 +01:00
Pierre Sassoulas 514376fe29 [ruff] Add ruff's check and autofix existing issues 2024-02-02 15:18:38 +01:00
Pierre Sassoulas 4588653b24 Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff
ruff is faster and handle everything we had prior.

isort configuration done based on the indication from
https://github.com/astral-sh/ruff/issues/4670, previousely based on
reorder-python-import (#11896)

flake8-docstrings was a wrapper around pydocstyle (now archived) that
explicitly asks to use ruff in https://github.com/PyCQA/pydocstyle/pull/658.

flake8-typing-import is useful mainly for project that support python 3.7
and the one useful check will be implemented in https://github.com/astral-sh/ruff/issues/2302

We need to keep blacken-doc because ruff does not handle detection
of python code inside .md and .rst. The direct link to the repo is
now used to avoid a redirection.

Manual fixes:
- Lines that became too long
- % formatting that was not done automatically
- type: ignore that were moved around
- noqa of hard to fix issues (UP031 generally)
- fmt: off and fmt: on that is not really identical
  between black and ruff
- autofix re-order in pre-commit from faster to slower

Co-authored-by: Ran Benita <ran@unusedvar.com>
2024-02-02 09:27:00 +01:00
Ran Benita b8118ab70d Remove `setup.py`
Fix #11667.
2023-12-04 22:45:59 +02:00
Ran Benita 3cb3cd1a08 testing: add `.*` to `norecursedirs`
Setting `norecursedirs` overrides the default, so we end up scanning
dot-directories and such which slows down collection unnecessarily
(150ms on my working directory).
2023-08-20 12:16:38 +03:00
Hugo van Kemenade 6baf9f2d31 Update docs and code after dropping EOL 3.7 2023-07-04 18:55:08 +03:00
Bruno Oliveira 27165cf8db
Use build-and-inspect-python-package action (#10722)
This uses https://github.com/hynek/build-and-inspect-python-package to ensure our package is correct, both during testing and deploy,
2023-02-12 21:37:40 -03:00
Ronny Pfannschmidt 0fdacb6db5 deprecate hook configuration via marks/attributes
fixes #4562
2022-09-20 16:22:26 +02:00
Ran Benita 56862c03cb pyproject.toml: remove `wheel` from `build-system.requires`
It's not required -- see
https://github.com/pypa/packaging.python.org/pull/1050
2022-08-15 19:41:57 +03:00
Hugo van Kemenade 1fd3601caa Drop support for EOL Python 3.6 2021-12-30 12:37:18 +02:00
Hasan Ramezani 0b7c3d1145
Remove Python 3.6 related warning from filterwarnings. 2021-12-28 17:09:27 +01:00
Ronny Pfannschmidt 0892c77bc6 fixes #8133: mitigate regendoc issues wrt PRETEND_VERSION
this issues is less likely to hit due to the recent regendoc release
which includes a wheel

* migrate to setuptools_scm 6.3.2
* use SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST
2021-10-02 20:22:18 +02:00
Florian Bruhin f1570dc038 Ignore various warnings from Python 3.10
https://github.com/benjaminp/six/issues/341
https://github.com/benjaminp/six/pull/352
https://github.com/pypa/setuptools/pull/2517
2021-05-04 17:24:50 +02:00
Bruno Oliveira 913cffa45f Add warnings filter for disutils deprecation
Deprecated in 3.10, scheduled for removal in 3.12
2021-03-27 11:13:16 -03:00
Ran Benita 361f9e20c3 testing: don't ignore "Module already imported so cannot be rewritten" warning
The test suite passes without it being ignored. The absence of this
warning cost me some head-scratching time, so enable it again.
2020-11-07 18:14:21 +02:00
Ran Benita 070f8e0f9d testing: silence deprecation warning from older pyparsing releases
This causes some tests to fail when using these older versions.
2020-11-05 16:08:54 +02:00
Hugo van Kemenade a642650e17 Drop support for EOL Python 3.5 2020-10-19 10:02:36 +03:00
Anthony Sottile f295b0267d py36+: update the target version of black to py36 2020-10-03 08:17:22 -07:00
Sorin Sbarnea b031a7cecf
Smoke tests for assorted plugins (#7721)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Co-authored-by: Kyle Altendorf <sda@fstab.net>
2020-09-19 15:56:52 -03:00
Anthony Sottile d5a49100cf
Try this maybe? 2020-07-31 21:44:44 -07:00
Bruno Oliveira 4f0793a462
Require setuptools >=42 2020-07-31 18:17:12 -03:00