Skip to content

Commit

Permalink
opt into ruff docstring-code-format = true
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed May 10, 2024
1 parent 6c696cd commit 2e1c301
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pymatgen/io/abinit/abitimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def alternate(*iterables):
"""
[a[0], b[0], ... , a[1], b[1], ..., a[n], b[n] ...]
>>> alternate([1,4], [2,5], [3,6])
>>> alternate([1, 4], [2, 5], [3, 6])
[1, 2, 3, 4, 5, 6].
"""
items = []
Expand Down
27 changes: 11 additions & 16 deletions pymatgen/io/lammps/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LammpsInputFile(InputFile):
```
stages = [
{"stage_name": "Stage 1", "commands": [(cmd1, args1), (cmd2, args2)]},
{"stage_name": "Stage 2", "commands": [(cmd3, args3)]}
{"stage_name": "Stage 2", "commands": [(cmd3, args3)]},
]
```
where cmd's are the LAMMPS command names (e.g., "units", or "pair_coeff")
Expand Down Expand Up @@ -206,7 +206,7 @@ def add_stage(
```
your_input_file.add_stage(
commands=["pair_coeff 1 1 morse 0.0580 3.987 3.404", "pair_coeff 1 4 morse 0.0408 1.399 3.204"],
stage_name="Definition of the force field"
stage_name="Definition of the force field",
)
```
or
Expand All @@ -216,7 +216,7 @@ def add_stage(
"stage_name": "Definition of the force field",
"commands": [
("pair_coeff", "1 1 morse 0.0580 3.987 3.404"),
("pair_coeff", "1 4 morse 0.0408 1.399 3.204")
("pair_coeff", "1 4 morse 0.0408 1.399 3.204"),
],
}
)
Expand All @@ -230,7 +230,7 @@ def add_stage(
"min_style cg",
"fix 1 all box/relax iso 0.0 vmax 0.001",
"minimize 1.0e-16 1.0e-16 5000 10000",
"write_data run.data"
"write_data run.data",
]
```
or a dictionary such as `{"thermo": 1, ...}`, or a string with a single command (e.g., "units atomic").
Expand Down Expand Up @@ -367,19 +367,18 @@ def add_commands(self, stage_name: str, commands: str | list[str] | dict) -> Non
to the stage "Definition of the potential", simply use
```
your_input_file.add_commands(
stage_name="Definition of the potential",
commands="pair_coeff 1 1 morse 0.0580 3.987 3.404"
stage_name="Definition of the potential", commands="pair_coeff 1 1 morse 0.0580 3.987 3.404"
)
```
To add multiple commands, use a dict or a list, e.g.
```
your_input_file.add_commands(
stage_name="Definition of the potential",
commands=["pair_coeff 1 1 morse 0.0580 3.987 3.404", "units atomic"]
commands=["pair_coeff 1 1 morse 0.0580 3.987 3.404", "units atomic"],
)
your_input_file.add_commands(
stage_name="Definition of the potential",
commands={"pair_coeff": "1 1 morse 0.0580 3.987 3.404", "units": "atomic"}
commands={"pair_coeff": "1 1 morse 0.0580 3.987 3.404", "units": "atomic"},
)
```
Expand Down Expand Up @@ -694,16 +693,13 @@ def _add_command(self, stage_name: str, command: str, args: str | float | None =
to the stage "Definition of the potential", simply use
```
your_input_file._add_command(
stage_name="Definition of the potential",
command="pair_coeff 1 1 morse 0.0580 3.987 3.404"
stage_name="Definition of the potential", command="pair_coeff 1 1 morse 0.0580 3.987 3.404"
)
```
or
```
your_input_file._add_command(
stage_name="Definition of the potential",
command="pair_coeff",
args="1 1 morse 0.0580 3.987 3.404"
stage_name="Definition of the potential", command="pair_coeff", args="1 1 morse 0.0580 3.987 3.404"
)
```
Expand Down Expand Up @@ -1027,10 +1023,9 @@ def write_lammps_inputs(
... timestep 0.005
...
... run $nsteps'''
>>> write_lammps_inputs('.', eam_template, settings={'temperature': 1600.0, 'nsteps': 100})
>>> with open('in.lammps') as file:
>>> write_lammps_inputs(".", eam_template, settings={"temperature": 1600.0, "nsteps": 100})
>>> with open("in.lammps") as file:
... script = file.read()
...
>>> print(script)
units metal
atom_style atomic
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/util/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def to_unicode_string(self):

def str_delimited(results, header=None, delimiter="\t"):
r"""Given a tuple of tuples, generate a delimited string form.
>>> results = [["a","b","c"],["d","e","f"],[1,2,3]]
>>> print(str_delimited(results,delimiter=","))
>>> results = [["a", "b", "c"], ["d", "e", "f"], [1, 2, 3]]
>>> print(str_delimited(results, delimiter=","))
a,b,c
d,e,f
1,2,3.
Expand Down
15 changes: 10 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ repair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest
[tool.ruff]
target-version = "py39"
line-length = 120
lint.select = [

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"D", # pydocstyle
Expand Down Expand Up @@ -56,7 +58,7 @@ lint.select = [
"W", # pycodestyle warning
"YTT", # flake8-2020
]
lint.ignore = [
ignore = [
"B023", # Function definition does not bind loop variable
"B028", # No explicit stacklevel keyword argument found
"B904", # Within an except clause, raise exceptions with ...
Expand All @@ -73,9 +75,12 @@ lint.ignore = [
"PTH", # prefer pathlib to os.path
"SIM105", # Use contextlib.suppress() instead of try-except-pass
]
lint.pydocstyle.convention = "google"
lint.isort.required-imports = ["from __future__ import annotations"]
lint.isort.split-on-trailing-comma = false
pydocstyle.convention = "google"
isort.required-imports = ["from __future__ import annotations"]
isort.split-on-trailing-comma = false

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
Expand Down

0 comments on commit 2e1c301

Please sign in to comment.