Skip to content

Commit cbb52d5

Browse files
committed
Apply linting to example folder.
1 parent c37be94 commit cbb52d5

Some content is hidden

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

54 files changed

+185
-211
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Check code style
2626
run: black --check .
2727
- name: Static code analysis
28-
run: flake8 ppci test
28+
run: flake8 ppci test tools
2929
- name: Test with pytest
3030
run: pytest
3131

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# ppci documentation build configuration file, created by
54
# sphinx-quickstart on Fri Aug 15 09:45:38 2014.
@@ -13,8 +12,8 @@
1312
# All configuration values have a default; values that are commented out
1413
# serve to show the default.
1514

16-
import sys
1715
import os
16+
import sys
1817
from importlib.metadata import distribution
1918

2019
# If extensions (or modules to document with autodoc) are in another directory,

docs/exts/gen_programs.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import os
6-
import json
76

87
from ppci import programs
98

@@ -61,37 +60,29 @@ def write_programs_rst():
6160
programs.IntermediateProgram,
6261
programs.MachineProgram,
6362
):
64-
parts.append(
65-
".. autoclass:: ppci.programs.{}".format(program.__name__)
66-
)
63+
parts.append(f".. autoclass:: ppci.programs.{program.__name__}")
6764
parts.append(" :members:\n\n")
6865

6966
# Add concrete classes
7067
parts.append("Source code programs")
7168
parts.append("-" * len(parts[-1]))
7269
parts.append("")
7370
for program in programs1:
74-
parts.append(
75-
".. autoclass:: ppci.programs.{}".format(program.__name__)
76-
)
71+
parts.append(f".. autoclass:: ppci.programs.{program.__name__}")
7772
parts.append(" :members:\n\n")
7873

7974
parts.append("Intermediate programs")
8075
parts.append("-" * len(parts[-1]))
8176
parts.append("")
8277
for program in programs2:
83-
parts.append(
84-
".. autoclass:: ppci.programs.{}".format(program.__name__)
85-
)
78+
parts.append(f".. autoclass:: ppci.programs.{program.__name__}")
8679
parts.append(" :members:\n\n")
8780

8881
parts.append("Machine code programs")
8982
parts.append("-" * len(parts[-1]))
9083
parts.append("")
9184
for program in programs3:
92-
parts.append(
93-
".. autoclass:: ppci.programs.{}".format(program.__name__)
94-
)
85+
parts.append(f".. autoclass:: ppci.programs.{program.__name__}")
9586
parts.append(" :members:\n\n")
9687

9788
files_to_remove.append(os.path.join("reference", "programs.rst"))

docs/exts/uml.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import tempfile
2-
import subprocess
31
import os
2+
import subprocess
3+
import tempfile
4+
5+
import pylint # ensure that pyreverse is available # noqa: F401
46
from docutils.parsers.rst import Directive
57
from sphinx.ext.graphviz import graphviz
68

7-
import pylint # ensure that pyreverse is available
8-
99
__version__ = "0.1"
1010

1111

@@ -36,7 +36,7 @@ def run(self):
3636
cmd.extend(["-c", c])
3737
cmd.append(module)
3838
subprocess.check_call(cmd)
39-
with open("classes_{}.dot".format(basename)) as f:
39+
with open(f"classes_{basename}.dot") as f:
4040
dotcode = f.read()
4141
os.chdir(save_dir)
4242

examples/6502/christmas.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
"""Create a nice christmas card."""
22

3-
import sys
4-
import os
53
import io
6-
from ppci import api
7-
from ppci.lang.basic.c64 import write_basic_program, BasicLine
8-
from ppci.binutils.layout import Layout, Memory, Section
9-
from ppci.utils.reporting import HtmlReportGenerator
4+
import sys
5+
106
import qrcode
117
from PIL import Image
128

9+
from ppci import api
10+
from ppci.binutils.layout import Layout, Memory, Section
11+
from ppci.lang.basic.c64 import BasicLine, write_basic_program
1312

1413
# Mapping of 2x2 pixels to charcode:
1514
# Value order:

examples/6502/make.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import sys
21
import os
2+
import sys
3+
34
from ppci import api
4-
from ppci.utils.reporting import html_reporter
55
from ppci.lang.basic.c64 import BasicLine, write_basic_program
6+
from ppci.utils.reporting import html_reporter
67

78
arch = api.get_arch("mcs6500")
89
print("Using arch", arch)
910

1011

1112
if len(sys.argv) > 1:
12-
with open(sys.argv[1], "r") as f:
13+
with open(sys.argv[1]) as f:
1314
text_message = f.read()
1415
else:
1516
text_message = "you can provide a text file to customize this message"

examples/c/cdecl.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
import argparse
1010
import io
11+
1112
from ppci.api import get_current_arch
12-
from ppci.lang.c import CLexer, CParser, COptions, CContext, CSemantics
13-
from ppci.lang.c.nodes import types, declarations
13+
from ppci.lang.c import CContext, CLexer, COptions, CParser, CSemantics
14+
from ppci.lang.c.nodes import declarations, types
1415
from ppci.lang.c.preprocessor import prepare_for_parsing
1516

1617
parser = argparse.ArgumentParser(
@@ -38,13 +39,13 @@
3839
# Explain:
3940
def explain(x):
4041
if isinstance(x, declarations.VariableDeclaration):
41-
return "{} is {}".format(x.name, explain(x.typ))
42+
return f"{x.name} is {explain(x.typ)}"
4243
elif isinstance(x, types.PointerType):
43-
return "a pointer to {}".format(explain(x.element_type))
44+
return f"a pointer to {explain(x.element_type)}"
4445
elif isinstance(x, types.ArrayType):
45-
return "an array of {}".format(explain(x.element_type))
46+
return f"an array of {explain(x.element_type)}"
4647
elif isinstance(x, types.BasicType):
47-
return "{}".format(x.type_id)
48+
return f"{x.type_id}"
4849
else:
4950
print("???", x)
5051

examples/c/demo_cparser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"""A demo showing the usage of the preprocessor and the parser"""
44

55
import argparse
6-
from ppci.common import CompilerError
7-
from ppci.lang.c import create_ast, CAstPrinter, CPrinter
8-
from ppci.api import get_current_arch
96

7+
from ppci.api import get_current_arch
8+
from ppci.common import CompilerError
9+
from ppci.lang.c import CAstPrinter, CPrinter, create_ast
1010

1111
if __name__ == "__main__":
1212
# Argument handling:
@@ -15,8 +15,8 @@
1515
args = arg_parser.parse_args()
1616
filename = args.source
1717

18-
print("============= [ {} ] ===============".format(args.source))
19-
with open(args.source, "r") as f:
18+
print(f"============= [ {args.source} ] ===============")
19+
with open(args.source) as f:
2020
for row, line in enumerate(f, 1):
2121
print(row, ":", line.rstrip())
2222
print("====================================")
@@ -25,7 +25,7 @@
2525
arch_info = get_current_arch().info
2626

2727
try:
28-
with open(filename, "r") as f:
28+
with open(filename) as f:
2929
ast = create_ast(f, arch_info, filename=filename)
3030
except CompilerError as ex:
3131
ex.print()

examples/c/demo_pycparser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import argparse
66
import io
7-
from ppci.api import preprocess
7+
88
from pycparser.c_parser import CParser
99

10+
from ppci.api import preprocess
1011

1112
if __name__ == "__main__":
1213
# Argument handling:
@@ -17,7 +18,7 @@
1718

1819
# Preprocessing:
1920
f2 = io.StringIO()
20-
with open(filename, "r") as f:
21+
with open(filename) as f:
2122
preprocess(f, f2)
2223
source = f2.getvalue()
2324

examples/c/hello/make.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import logging
2+
23
from ppci.api import cc
34

45
logging.basicConfig(level=logging.DEBUG)
5-
with open("main.c", "r") as f:
6+
with open("main.c") as f:
67
obj = cc(f, "x86_64", debug=True)
78

89
print("Object file created:", obj)

0 commit comments

Comments
 (0)