Skip to content

Commit 813fdec

Browse files
authored
Merge branch 'main' into fix/issue-1105-low-rank-spin-exchange
2 parents 37eac9f + 379f63a commit 813fdec

12 files changed

Lines changed: 50 additions & 40 deletions

CONTRIBUTING.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,21 @@ make Mypy run in parallel for a substantial speed increase.
249249
250250
Code should meet common style standards for Python and be free of error-prone constructs. We use
251251
[Pylint](https://www.pylint.org/) to check for code lint and [Black](https://github.com/psf/black)
252-
for formatting code.
252+
for formatting code, and provide scripts to run them.
253253
254254
* To check that code is formatted properly after editing Python files:
255255
256256
```shell
257257
check/format-incremental
258258
```
259259
260+
If formatting issues are reported, you can fix them automatically by running the script with
261+
the `--apply` option:
262+
263+
```shell
264+
check/format-incremental --apply
265+
```
266+
260267
* To run the linter:
261268
262269
```shell
@@ -289,8 +296,8 @@ We use [pytest](https://docs.pytest.org) to run our tests and
289296
`pytest -m "not slow" PATH`, where `PATH` is a directory or pytest file to test.
290297
291298
* After finishing a task, run `check/pytest` to test all of the OpenFermion code. If your system
292-
has multiple processor cores, you can add the option `-n auto` to make it run in parallel for a
293-
substantial speed increase. (Beware, though, that this is resource-intensive.)
299+
has multiple processor cores, you can add the option `-n auto` to make pytest use multiple
300+
parallel processes for a speed increase. (Beware, though, that this is resource-intensive.)
294301
295302
We don't require 100% coverage, but coverage should be very high, and any uncovered code must be
296303
annotated with `# pragma: no cover`. To ignore coverage of a single line, place `# pragma: no cover`
@@ -301,7 +308,7 @@ cover` comment on its own line. Note, however, that these annotations should be
301308

302309
After a task is finished, run each of the following to make sure everything passes all the tests:
303310

304-
* `check/format-incremental`
311+
* `check/format-incremental` (and `check/format-incremental --apply` to auto-fix format problems)
305312
* `check/pylint -j 0`
306313
* `check/mypy`
307314
* `check/pytest -n auto`

dev_tools/check_incremental_coverage_annotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from dev_tools.incremental_coverage import check_for_uncovered_lines
2323

2424

25-
def main():
25+
def main() -> None:
2626
if len(sys.argv) < 2:
2727
print(
2828
shell_tools.highlight(

dev_tools/docs/build_api_docs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Tool to generate external api_docs for OF (Shameless copy from TFQ)."""
1616

1717
import os
18+
from typing import Any
1819

1920
from absl import app
2021
from absl import flags
@@ -39,7 +40,7 @@
3940
FLAGS = flags.FLAGS
4041

4142

42-
def main(unused_argv):
43+
def main(unused_argv: Any) -> None:
4344

4445
doc_generator = generate_lib.DocGenerator(
4546
root_title="OpenFermion",

dev_tools/env_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def prepare_temporary_test_environment(
6868
verbose: bool,
6969
env_name: str = '.test_virtualenv',
7070
python_path: str = sys.executable,
71-
commit_ids_known_callback: Callable[[PreparedEnv], None] = None,
71+
commit_ids_known_callback: Optional[Callable[[PreparedEnv], None]] = None,
7272
) -> PreparedEnv:
7373
"""Prepares a temporary test environment at the (existing empty) directory.
7474

dev_tools/incremental_coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def diff_to_new_interesting_lines(unified_diff_lines: List[str]) -> Dict[int, st
109109
return interesting_lines
110110

111111

112-
def fix_line_from_coverage_file(line):
112+
def fix_line_from_coverage_file(line: str) -> str:
113113
line = line.rstrip()
114114
if line.startswith('!'):
115115
line = line[1:]

dev_tools/incremental_coverage_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from dev_tools import incremental_coverage
1616

1717

18-
def test_determine_ignored_lines():
18+
def test_determine_ignored_lines() -> None:
1919
f = incremental_coverage.determine_ignored_lines
2020

2121
assert f("a = 0 # coverage: ignore") == {1}

dev_tools/prepared_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def bin(self, program: str) -> str:
6565

6666
def report_status_to_github(
6767
self, state: str, description: str, context: str, target_url: Optional[str] = None
68-
):
68+
) -> None:
6969
"""Sets a commit status indicator on github.
7070
7171
If not running from a pull request (i.e. repository is None), then this

dev_tools/prepared_env_security_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import unittest
2+
from typing import Any
23
from unittest.mock import patch, MagicMock
34
from dev_tools.prepared_env import PreparedEnv
45
from dev_tools.github_repository import GithubRepository
56

67

78
class TestPreparedEnvSecurity(unittest.TestCase):
89
@patch('requests.post')
9-
def test_report_status_to_github_token_in_header(self, mock_post):
10+
def test_report_status_to_github_token_in_header(self, mock_post: Any) -> None:
1011
# Setup
1112
mock_response = MagicMock()
1213
mock_response.status_code = 201

dev_tools/requirements/run-pip-compiles.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import subprocess
4141
from argparse import ArgumentParser
4242
from dataclasses import dataclass, field
43-
from typing import *
43+
from typing import Any, Dict, Set
4444

4545

4646
@dataclass
@@ -83,12 +83,14 @@ class PlatformRecipe:
8383
}
8484

8585

86-
def run(*args):
86+
def run(*args: Any) -> subprocess.CompletedProcess:
8787
"""Run a command using `subprocess`."""
8888
return subprocess.run(*args, check=True)
8989

9090

91-
def pip_compile(env_name: str, env_recipe: EnvRecipe, env_out_dir: str, constrain=True):
91+
def pip_compile(
92+
env_name: str, env_recipe: EnvRecipe, env_out_dir: str, constrain: bool = True
93+
) -> None:
9294
"""Run `pip-compile` to create the named environment."""
9395
dep_args = [f"deps/{dep_name}.txt" for dep_name in env_recipe.deps]
9496
dep_args += [f"--constraint=deps/{cons_name}.txt" for cons_name in env_recipe.addtl_constraints]
@@ -115,7 +117,7 @@ def get_dev_env_recipe(pr: PlatformRecipe) -> EnvRecipe:
115117
return EnvRecipe(all_deps, all_addtl_constraints)
116118

117119

118-
def make_platform_envs(pr: PlatformRecipe):
120+
def make_platform_envs(pr: PlatformRecipe) -> None:
119121
os.makedirs(pr.env_out_dir, exist_ok=True)
120122

121123
# Pip compile the full dev environment
@@ -126,7 +128,7 @@ def make_platform_envs(pr: PlatformRecipe):
126128
pip_compile(env_name, env_recipe, pr.env_out_dir)
127129

128130

129-
def parse():
131+
def parse() -> None:
130132
"""Parse command line arguments."""
131133
parser = ArgumentParser()
132134
parser.add_argument("--platform", default="default")
@@ -136,7 +138,7 @@ def parse():
136138
except KeyError:
137139
raise ValueError(f"Unknown platform {args.platform}")
138140

139-
return make_platform_envs(platform)
141+
make_platform_envs(platform)
140142

141143

142144
if __name__ == "__main__":

dev_tools/shell_tools.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def run_cmd(
124124
raise_on_fail: bool = True,
125125
log_run_to_stderr: bool = True,
126126
abbreviate_non_option_arguments: bool = False,
127-
**kwargs,
127+
**kwargs: Any,
128128
) -> CommandOutput:
129129
"""Invokes a subprocess and waits for it to finish.
130130
@@ -204,7 +204,7 @@ def run_shell(
204204
err: Optional[Union[TeeCapture, IO[str]]] = sys.stderr,
205205
raise_on_fail: bool = True,
206206
log_run_to_stderr: bool = True,
207-
**kwargs,
207+
**kwargs: Any,
208208
) -> CommandOutput:
209209
"""Invokes a shell command and waits for it to finish.
210210
@@ -267,7 +267,7 @@ def run_shell(
267267
return result
268268

269269

270-
def output_of(*cmd: Optional[str], **kwargs) -> str:
270+
def output_of(*cmd: Optional[str], **kwargs: Any) -> str:
271271
"""Invokes a subprocess and returns its output as a string.
272272
273273
Args:
@@ -276,9 +276,7 @@ def output_of(*cmd: Optional[str], **kwargs) -> str:
276276
a cwd (current working directory) argument.
277277
278278
Returns:
279-
A (captured output, captured error output, return code) triplet. The
280-
captured outputs will be None if the out or err parameters were not set
281-
to an instance of TeeCapture.
279+
The output of the command.
282280
283281
Raises:
284282
subprocess.CalledProcessError: The process returned a non-zero error

0 commit comments

Comments
 (0)