Add Ruff formatter to pre-commit for Python#1852
Add Ruff formatter to pre-commit for Python#1852franzpoeschel wants to merge 2 commits intoopenPMD:devfrom
Conversation
| if file_ending not in ["bp", "bp4", "bp5"]: | ||
| self.assertTrue( | ||
| dc256.dtype == np.dtype('clongdouble')) | ||
| self.assertTrue(dc256.dtype == np.dtype("clongdouble")) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| self.assertTrue(dc64.dtype == np.dtype('complex64')) | ||
| self.assertTrue(dc128.dtype == np.dtype('complex128')) | ||
| self.assertTrue(dc64.dtype == np.dtype("complex64")) | ||
| self.assertTrue(dc128.dtype == np.dtype("complex128")) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| self.assertTrue( | ||
| ms["int64"][SCALAR].load_chunk(o, e).dtype == np.dtype("int64") | ||
| ) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| self.assertTrue( | ||
| ms["int32"][SCALAR].load_chunk(o, e).dtype == np.dtype("int32") | ||
| ) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| self.assertTrue( | ||
| ms["int16"][SCALAR].load_chunk(o, e).dtype == np.dtype("int16") | ||
| ) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| print( | ||
| """ | ||
| openPMD-api was built with support for MPI, | ||
| but mpi4py Python package was not found. | ||
| Will continue in serial mode.""", | ||
| file=sys.stderr) | ||
| file=sys.stderr, | ||
| ) |
Check notice
Code scanning / CodeQL
Use of a print statement at module level Note
| E_z_m0 = E_z_modes[0:1, 0:shape[1], 0:shape[2]] | ||
| E_z_m0 = E_z_modes[0:1, 0 : shape[1], 0 : shape[2]] | ||
| # read E_z in mode_1 (two fields; skip mode_0 with one scalar field) | ||
| E_z_m1 = E_z_modes[1:3, 0:shape[1], 0:shape[2]] |
Check notice
Code scanning / CodeQL
Unused global variable Note
4819566 to
0f90c55
Compare
| == np.dtype("complex128") | ||
| ) | ||
| if file_ending not in ["bp", "bp4", "bp5"]: | ||
| self.assertTrue(ms["clongdouble"][SCALAR].load_chunk(o, e) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| == np.dtype("longdouble") | ||
| ) | ||
| self.assertTrue( | ||
| ms["complex64"][SCALAR].load_chunk(o, e).dtype |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| == np.dtype("double") | ||
| ) | ||
| self.assertTrue( | ||
| ms["longdouble"][SCALAR].load_chunk(o, e).dtype |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| == np.dtype("single") | ||
| ) | ||
| self.assertTrue( | ||
| ms["double"][SCALAR].load_chunk(o, e).dtype |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| == np.dtype("uint64") | ||
| ) | ||
| self.assertTrue( | ||
| ms["single"][SCALAR].load_chunk(o, e).dtype |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| == np.dtype("uint32") | ||
| ) | ||
| self.assertTrue( | ||
| ms["uint64"][SCALAR].load_chunk(o, e).dtype |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| rev: v0.15.1 | ||
| hooks: | ||
| - id: isort | ||
| name: isort (python) | ||
| - id: ruff-check | ||
| args: [ --line-length, "79", --fix ] | ||
| - id: ruff-format |
There was a problem hiding this comment.
We could add a few more flags for the linter:
https://github.com/AMReX-Codes/pyamrex/blob/789dc8c4f1bca202219072e6a9801f060fc4ba3a/.pre-commit-config.yaml#L74-L83
Then move options like --line-length 79 to a toml config file
https://github.com/AMReX-Codes/pyamrex/blob/development/pyproject.toml
That way, local runs of ruff linter (outside of pre-commit) will have the same configs.
There was a problem hiding this comment.
Ruff apparently also looks for configuration directly inside pyproject.yaml, so that would keep things simple. I moved the line length flags there for now.
EDIT: Ah, I just saw that this is the style you linked to. Then let's go with that, yeah. Should we just copy the config from there or should we adapt some things?
| # - repo: https://github.com/pycqa/isort | ||
| # rev: 7.0.0 | ||
| # hooks: | ||
| # - id: isort |
There was a problem hiding this comment.
Yes this one we remove, replaced by ruff
d7739fa to
3d8ba99
Compare
Ruff line length Remove Python isort conflicts with ruff Try fixing the line length nicer ruff syntax in pyproject.toml Remove E203 from checking Remove explicit cmd line args from pre-commit config
3d8ba99 to
c851a9e
Compare
for more information, see https://pre-commit.ci
TODO: