Skip to content

Commit 2f01e33

Browse files
authored
Blacken (#441)
Applies back formatting at 120 cols. Most of the changes are 2->4 space tabs and adding linebreaks. Drops the oldest mypy from the test suite and adds blacken.
1 parent 279f944 commit 2f01e33

File tree

444 files changed

+49025
-42646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

444 files changed

+49025
-42646
lines changed

.github/workflows/pr-python.yml

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ jobs:
3131
"examples/**.py"
3232
]'
3333

34+
black_latest_3_11:
35+
needs: pre_job
36+
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v1
40+
- uses: actions/setup-python@v1
41+
with:
42+
python-version: '3.11'
43+
44+
- name: install mypy
45+
run: |
46+
pip install -r requirements.txt
47+
pip install black
48+
- name: black
49+
run: black --check .
50+
3451
mypy_latest_3_11:
3552
needs: pre_job
3653
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
@@ -49,21 +66,6 @@ jobs:
4966
- name: mypy
5067
run: mypy --install-types .
5168

52-
unittest_latest_3_11:
53-
needs: pre_job
54-
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
55-
runs-on: ubuntu-latest
56-
steps:
57-
- uses: actions/checkout@v1
58-
- uses: actions/setup-python@v1
59-
with:
60-
python-version: '3.11'
61-
62-
- name: install dependencies
63-
run: pip install -r requirements.txt
64-
- name: unittest
65-
run: python -m unittest discover
66-
6769
packagetest_latest_3_11:
6870
needs: pre_job
6971
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
@@ -83,23 +85,20 @@ jobs:
8385
- name: toptest
8486
run: cd examples && python test_blinky.py
8587

86-
mypy_latest_3_9:
88+
unittest_latest_3_11:
8789
needs: pre_job
8890
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
8991
runs-on: ubuntu-latest
9092
steps:
91-
- uses: actions/checkout@v1
92-
- uses: actions/setup-python@v1
93-
with:
94-
python-version: '3.9'
93+
- uses: actions/checkout@v1
94+
- uses: actions/setup-python@v1
95+
with:
96+
python-version: '3.11'
9597

96-
- name: install mypy
97-
run: |
98-
pip install -r requirements.txt
99-
pip install mypy mypy-protobuf
100-
mypy --version
101-
- name: mypy
102-
run: mypy --install-types .
98+
- name: install dependencies
99+
run: pip install -r requirements.txt
100+
- name: unittest
101+
run: python -m unittest discover
103102

104103
unittest_latest_3_9:
105104
needs: pre_job

blinky_skeleton.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55

66
class BlinkyExample(SimpleBoardTop):
7-
@override
8-
def contents(self) -> None:
9-
super().contents()
10-
# your implementation here
7+
@override
8+
def contents(self) -> None:
9+
super().contents()
10+
# your implementation here
1111

1212

1313
if __name__ == "__main__":
14-
compile_board_inplace(BlinkyExample)
14+
compile_board_inplace(BlinkyExample)

edg/BoardCompiler.py

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,65 @@
1111

1212

1313
def compile_board(design: Type[Block], target_dir_name: Optional[Tuple[str, str]]) -> CompiledDesign:
14-
if target_dir_name is not None:
15-
(target_dir, target_name) = target_dir_name
16-
if not os.path.exists(target_dir):
17-
os.makedirs(target_dir)
18-
assert os.path.isdir(target_dir), f"target_dir {target_dir} to compile_board must be directory"
14+
if target_dir_name is not None:
15+
(target_dir, target_name) = target_dir_name
16+
if not os.path.exists(target_dir):
17+
os.makedirs(target_dir)
18+
assert os.path.isdir(target_dir), f"target_dir {target_dir} to compile_board must be directory"
1919

20-
design_filename = os.path.join(target_dir, f'{target_name}.edg')
21-
netlist_filename = os.path.join(target_dir, f'{target_name}.net')
22-
bom_filename = os.path.join(target_dir, f'{target_name}.csv')
23-
svgpcb_filename = os.path.join(target_dir, f'{target_name}.svgpcb.js')
20+
design_filename = os.path.join(target_dir, f"{target_name}.edg")
21+
netlist_filename = os.path.join(target_dir, f"{target_name}.net")
22+
bom_filename = os.path.join(target_dir, f"{target_name}.csv")
23+
svgpcb_filename = os.path.join(target_dir, f"{target_name}.svgpcb.js")
2424

25-
with suppress(FileNotFoundError):
26-
os.remove(design_filename)
27-
with suppress(FileNotFoundError):
28-
os.remove(netlist_filename)
29-
with suppress(FileNotFoundError):
30-
os.remove(bom_filename)
31-
with suppress(FileNotFoundError):
32-
os.remove(svgpcb_filename)
25+
with suppress(FileNotFoundError):
26+
os.remove(design_filename)
27+
with suppress(FileNotFoundError):
28+
os.remove(netlist_filename)
29+
with suppress(FileNotFoundError):
30+
os.remove(bom_filename)
31+
with suppress(FileNotFoundError):
32+
os.remove(svgpcb_filename)
3333

34-
compiled = ScalaCompiler.compile(design, ignore_errors=True)
35-
compiled.append_values(RefdesRefinementPass().run(compiled))
34+
compiled = ScalaCompiler.compile(design, ignore_errors=True)
35+
compiled.append_values(RefdesRefinementPass().run(compiled))
3636

37-
if target_dir_name is not None: # always dump the proto even if there is an error
38-
with open(design_filename, 'wb') as raw_file:
39-
raw_file.write(compiled.design.SerializeToString())
37+
if target_dir_name is not None: # always dump the proto even if there is an error
38+
with open(design_filename, "wb") as raw_file:
39+
raw_file.write(compiled.design.SerializeToString())
4040

41-
if compiled.errors:
42-
from . import core
43-
raise core.ScalaCompilerInterface.CompilerCheckError(f"error during compilation:\n{compiled.errors_str()}")
41+
if compiled.errors:
42+
from . import core
4443

45-
netlist_all = NetlistBackend().run(compiled)
46-
bom_all = GenerateBom().run(compiled)
47-
svgpcb_all = SvgPcbBackend().run(compiled)
48-
assert len(netlist_all) == 1
44+
raise core.ScalaCompilerInterface.CompilerCheckError(f"error during compilation:\n{compiled.errors_str()}")
4945

50-
if target_dir_name is not None:
51-
with open(netlist_filename, 'w', encoding='utf-8') as net_file:
52-
net_file.write(netlist_all[0][1])
46+
netlist_all = NetlistBackend().run(compiled)
47+
bom_all = GenerateBom().run(compiled)
48+
svgpcb_all = SvgPcbBackend().run(compiled)
49+
assert len(netlist_all) == 1
5350

54-
with open(bom_filename, 'w', encoding='utf-8') as bom_file:
55-
bom_file.write(bom_all[0][1])
51+
if target_dir_name is not None:
52+
with open(netlist_filename, "w", encoding="utf-8") as net_file:
53+
net_file.write(netlist_all[0][1])
5654

57-
if svgpcb_all:
58-
with open(svgpcb_filename, 'w', encoding='utf-8') as bom_file:
59-
bom_file.write(svgpcb_all[0][1])
55+
with open(bom_filename, "w", encoding="utf-8") as bom_file:
56+
bom_file.write(bom_all[0][1])
6057

61-
return compiled
58+
if svgpcb_all:
59+
with open(svgpcb_filename, "w", encoding="utf-8") as bom_file:
60+
bom_file.write(svgpcb_all[0][1])
61+
62+
return compiled
6263

6364

6465
def compile_board_inplace(design: Type[Block], generate: bool = True) -> CompiledDesign:
65-
"""Compiles a board and writes the results in a sub-directory
66-
where the module containing the top-level is located"""
67-
designfile = inspect.getfile(design)
68-
if generate:
69-
target_dir_name = (os.path.join(os.path.dirname(designfile), design.__name__), design.__name__)
70-
else:
71-
target_dir_name = None
72-
compiled = compile_board(design, target_dir_name)
73-
74-
return compiled
66+
"""Compiles a board and writes the results in a sub-directory
67+
where the module containing the top-level is located"""
68+
designfile = inspect.getfile(design)
69+
if generate:
70+
target_dir_name = (os.path.join(os.path.dirname(designfile), design.__name__), design.__name__)
71+
else:
72+
target_dir_name = None
73+
compiled = compile_board(design, target_dir_name)
74+
75+
return compiled

0 commit comments

Comments
 (0)