Skip to content

Commit 3f44586

Browse files
committed
When updating examples/requirements/all.txt only care about *.txt files
Signed-off-by: Pedro Algarvio <[email protected]>
1 parent 1303621 commit 3f44586

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

changelog/68.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Several trivial/internal updates to the project:
22

33
* Allow the `nox -e build` target to also build the examples package
4+
* When updating `examples/requirements/all.txt` only care about `*.txt` files

tools/pre_commit.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
log = logging.getLogger(__name__)
1717

18+
REPO_ROOT = pathlib.Path(__file__).parent.parent
19+
1820
# Define the command group
1921
cgroup = command_group(name="pre-commit", help="Pre-Commit Related Commands", description=__doc__)
2022

@@ -33,11 +35,9 @@ def examples_requirements(ctx: Context, files: list[pathlib.Path]):
3335
Include all individual examples requirements files in `all.txt`.
3436
"""
3537
if files:
36-
examples_requirements_dir = (
37-
pathlib.Path(__file__).resolve().parent.parent / "examples" / "requirements"
38-
)
38+
examples_requirements_dir = REPO_ROOT / "examples" / "requirements"
3939
includes = []
40-
for file in examples_requirements_dir.iterdir():
40+
for file in examples_requirements_dir.glob("*.txt"):
4141
if file.name != "all.txt":
4242
includes.append(f"-r {file.name}")
4343

@@ -47,9 +47,8 @@ def examples_requirements(ctx: Context, files: list[pathlib.Path]):
4747
original_contents = [line.strip() for line in rfh.readlines()]
4848

4949
if set(original_contents) != set(includes):
50-
includes.append("")
51-
all_file.write_text("\n".join(includes))
52-
ctx.error(f"Modified {all_file}")
50+
all_file.write_text("\n".join(sorted(includes)) + "\n")
51+
ctx.error(f"Modified {all_file.relative_to(REPO_ROOT)}")
5352

5453

5554
@cgroup.command(

0 commit comments

Comments
 (0)