Skip to content

Commit 0c93c33

Browse files
committed
Move CI to a separate directory
We tidy up the root directory and move everything related to continous integration to a separate directory.
1 parent 1edaa51 commit 0c93c33

File tree

13 files changed

+138
-108
lines changed

13 files changed

+138
-108
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
3434
- name: Run checks
3535
run: |
36-
python3 precommit.py
36+
python3 continuous_integration/precommit.py
3737
3838
- name: Upload Coverage
3939
run: coveralls --service=github

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Development
100100

101101
.. code-block:: bash
102102
103-
python precommit.py
103+
python continuous_integration/precommit.py
104104
105105
Versioning
106106
==========

continuous_integration/__init__.py

Whitespace-only changes.

check_help_in_readme.py renamed to continuous_integration/check_help_in_readme.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ def parse_readme(lines: List[str]) -> Tuple[List[Block], List[str]]:
5050
mtch = HELP_STARTS_RE.match(lines[i])
5151
if mtch:
5252
command = mtch.group("command")
53-
help_ends = ".. Help ends: {}".format(command)
53+
help_ends = f".. Help ends: {command}"
5454
try:
5555
end_index = lines.index(help_ends, i)
5656
except ValueError:
5757
end_index = -1
5858

5959
if end_index == -1:
60-
return [], ["Could not find the end marker {!r}".format(help_ends)]
60+
return [], [f"Could not find the end marker {help_ends!r}"]
6161

6262
blocks.append(
6363
Block(command=command, start_line_idx=i + 1, end_line_idx=end_index)
@@ -84,18 +84,18 @@ def capture_output_lines(command: str) -> List[str]:
8484
f"The python interpreter could not be found: {command_parts[0]}"
8585
)
8686

87-
proc = subprocess.Popen(
87+
with subprocess.Popen(
8888
command_parts,
8989
stdout=subprocess.PIPE,
9090
stderr=subprocess.PIPE,
9191
encoding="utf-8",
92-
)
93-
output, err = proc.communicate()
94-
if err:
95-
raise RuntimeError(
96-
f"The command {command!r} failed with exit code {proc.returncode} and "
97-
f"stderr:\n{err}"
98-
)
92+
) as proc:
93+
output, err = proc.communicate()
94+
if err:
95+
raise RuntimeError(
96+
f"The command {command!r} failed with exit code {proc.returncode} and "
97+
f"stderr:\n{err}"
98+
)
9999

100100
return output.splitlines()
101101

@@ -126,16 +126,16 @@ def diff(got_lines: List[str], expected_lines: List[str]) -> Optional[str]:
126126
result.append("Expected:")
127127
for i, line in enumerate(expected_lines):
128128
if i >= len(got_lines) or line != got_lines[i]:
129-
print("DIFF: {:2d}: {!r}".format(i, line))
129+
print(f"DIFF: {i:2d}: {line!r}")
130130
else:
131-
print("OK : {:2d}: {!r}".format(i, line))
131+
print(f"OK : {i:2d}: {line!r}")
132132

133133
result.append("Got:")
134134
for i, line in enumerate(got_lines):
135135
if i >= len(expected_lines) or line != expected_lines[i]:
136-
print("DIFF: {:2d}: {!r}".format(i, line))
136+
print(f"DIFF: {i:2d}: {line!r}")
137137
else:
138-
print("OK : {:2d}: {!r}".format(i, line))
138+
print(f"OK : {i:2d}: {line!r}")
139139

140140
return "\n".join(result)
141141

@@ -152,20 +152,22 @@ def main() -> int:
152152
args = parser.parse_args()
153153
overwrite = bool(args.overwrite)
154154

155-
this_dir = pathlib.Path(os.path.realpath(__file__)).parent
156-
pth = this_dir / "README.rst"
155+
repo_root = pathlib.Path(os.path.realpath(__file__)).parent.parent
156+
pth = repo_root / "README.rst"
157157

158158
text = pth.read_text(encoding="utf-8")
159159
lines = text.splitlines()
160160

161161
blocks, errors = parse_readme(lines=lines)
162162
if errors:
163-
print("One or more errors in {}:".format(pth), file=sys.stderr)
163+
print(f"One or more errors in {pth}:", file=sys.stderr)
164164
for error in errors:
165165
print(error, file=sys.stderr)
166166

167167
return -1
168168

169+
assert blocks is not None
170+
169171
if len(blocks) == 0:
170172
return 0
171173

@@ -185,6 +187,7 @@ def main() -> int:
185187
result.extend(code_block_lines)
186188
previous_block = block
187189

190+
assert previous_block is not None
188191
result.extend(lines[previous_block.end_line_idx :])
189192
result.append("") # new line at the end of file
190193

@@ -198,9 +201,11 @@ def main() -> int:
198201
expected_lines = lines[block.start_line_idx : block.end_line_idx]
199202
expected_lines = [line.rstrip() for line in expected_lines]
200203

201-
error = diff(got_lines=code_block_lines, expected_lines=expected_lines)
202-
if error:
203-
print(error, file=sys.stderr)
204+
maybe_error = diff(
205+
got_lines=code_block_lines, expected_lines=expected_lines
206+
)
207+
if maybe_error:
208+
print(maybe_error, file=sys.stderr)
204209
return -1
205210

206211
return 0

check_version_consistent.py renamed to continuous_integration/check_version_consistent.py

File renamed without changes.

precommit.py renamed to continuous_integration/precommit.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import subprocess
88
import sys
99

10+
# pylint: disable=missing-docstring
11+
1012

1113
class Step(enum.Enum):
1214
BLACK = "black"
@@ -60,21 +62,20 @@ def main() -> int:
6062
selects = (
6163
[Step(value) for value in args.select]
6264
if args.select is not None
63-
else [value for value in Step]
65+
else [value for value in Step] # pylint: disable=unnecessary-comprehension
6466
)
6567
skips = [Step(value) for value in args.skip] if args.skip is not None else []
6668

67-
repo_root = pathlib.Path(__file__).parent
69+
repo_root = pathlib.Path(__file__).parent.parent
6870

6971
if Step.BLACK in selects and Step.BLACK not in skips:
7072
print("Black'ing...")
7173
# fmt: off
7274
black_targets = [
7375
"abnf_to_regexp",
74-
"precommit.py",
75-
"check_version_consistent.py",
76-
"check_help_in_readme.py",
77-
"dev_scripts"
76+
"continuous_integration",
77+
"dev_scripts",
78+
"tests"
7879
]
7980
# fmt: on
8081

@@ -93,7 +94,12 @@ def main() -> int:
9394
if Step.MYPY in selects and Step.MYPY not in skips:
9495
print("Mypy'ing...")
9596
# fmt: off
96-
mypy_targets = ["abnf_to_regexp", "tests", "dev_scripts"]
97+
mypy_targets = [
98+
"abnf_to_regexp",
99+
"tests",
100+
"dev_scripts",
101+
"continuous_integration"
102+
]
97103
subprocess.check_call(
98104
[
99105
sys.executable,
@@ -108,13 +114,17 @@ def main() -> int:
108114
if Step.PYLINT in selects and Step.PYLINT not in skips:
109115
# fmt: off
110116
print("Pylint'ing...")
111-
pylint_targets = ["abnf_to_regexp", "tests", "dev_scripts"]
117+
pylint_targets = [
118+
"abnf_to_regexp",
119+
"tests",
120+
"dev_scripts",
121+
"continuous_integration"
122+
]
112123
subprocess.check_call(
113124
[
114125
sys.executable,
115126
"-m",
116-
"pylint",
117-
"--rcfile=pylint.rc"
127+
"pylint"
118128
] + pylint_targets, cwd=str(repo_root)
119129
)
120130
# fmt: on
@@ -166,7 +176,9 @@ def main() -> int:
166176
"Checking that the version is consistent between "
167177
"abnf_to_regexp/__init__.py and pyproject.toml ..."
168178
)
169-
subprocess.check_call([sys.executable, "check_version_consistent.py"])
179+
subprocess.check_call(
180+
[sys.executable, "continuous_integration/check_version_consistent.py"]
181+
)
170182
else:
171183
print(
172184
"Skipped checking that the versions in abnf_to_regexp/__init__.py "
@@ -175,7 +187,7 @@ def main() -> int:
175187

176188
if Step.CHECK_HELP_IN_README in selects and Step.CHECK_HELP_IN_README not in skips:
177189
if sys.version_info < (3, 10):
178-
cmd = [sys.executable, "check_help_in_readme.py"]
190+
cmd = [sys.executable, "continuous_integration/check_help_in_readme.py"]
179191
if overwrite:
180192
cmd.append("--overwrite")
181193

mypy.ini

Lines changed: 0 additions & 10 deletions
This file was deleted.

pylint.rc

Lines changed: 0 additions & 11 deletions
This file was deleted.

pyproject.toml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,41 @@ packages = ["abnf_to_regexp"]
5454
abnf_to_regexp = ["py.typed"]
5555

5656
[tool.setuptools.exclude-package-data]
57-
"*" = ["tests*"]
57+
"*" = ["tests*"]
58+
59+
[tool.pylint.format]
60+
max-line-length = 120
61+
62+
[tool.pylint."messages control"]
63+
disable = [
64+
"too-few-public-methods",
65+
"len-as-condition",
66+
"duplicate-code",
67+
"no-else-raise",
68+
"no-else-return",
69+
"too-many-locals",
70+
"too-many-branches",
71+
"too-many-nested-blocks",
72+
"too-many-return-statements",
73+
"unsubscriptable-object",
74+
"not-an-iterable",
75+
"broad-except",
76+
"too-many-statements",
77+
"protected-access",
78+
"unnecessary-pass",
79+
"use-dict-literal",
80+
]
81+
82+
[tool.mypy]
83+
84+
[[tool.mypy.overrides]]
85+
module = "abnf"
86+
ignore_missing_imports = true
87+
88+
[[tool.mypy.overrides]]
89+
module = "regex"
90+
ignore_missing_imports = true
91+
92+
[[tool.mypy.overrides]]
93+
module = "sortedcontainers"
94+
ignore_missing_imports = true

requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)