Skip to content

Commit

Permalink
Ignore non-YAML files
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusbaeck committed Jan 12, 2024
1 parent 1fa3211 commit 5263505
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
24 changes: 13 additions & 11 deletions test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ def test_latest_in_gitref(tmp_git):
create_files(
tmp_git.path,
"subdir_c/6.0.0.json",
"definitions/subdir_a/1.0.0.json",
"definitions/subdir_a/2.0.0.json",
"definitions/subdir_b/3.0.0.json",
"definitions/subdir_b/4.0.0.json",
"definitions/subdir_a/1.0.0.yml",
"definitions/subdir_a/2.0.0.yml",
"definitions/subdir_a/3.0.0.othersuffix",
"definitions/subdir_b/3.0.0.yml",
"definitions/subdir_b/4.0.0.yml",
)
tmp_git.command("add", "-A")
tmp_git.command("commit", "-m", "Initial set of files")
tmp_git.command("tag", "v1.0.0")

# Add an additional file and delete one of the original files.
(tmp_git.path / "definitions/subdir_b/5.0.0.json").touch()
tmp_git.command("rm", "definitions/subdir_a/2.0.0.json")
(tmp_git.path / "definitions/subdir_b/5.0.0.yml").touch()
tmp_git.command("rm", "definitions/subdir_a/2.0.0.yml")
tmp_git.command("add", "-A")
tmp_git.command("commit", "-m", "Make changes")

Expand All @@ -80,11 +81,12 @@ def test_latest_in_gitref(tmp_git):
def test_latest_in_dir(tmp_path):
create_files(
tmp_path,
"subdir_c/6.0.0.json",
"definitions/subdir_a/1.0.0.json",
"definitions/subdir_a/2.0.0.json",
"definitions/subdir_b/3.0.0.json",
"definitions/subdir_b/4.0.0.json",
"subdir_c/6.0.0.yml",
"definitions/subdir_a/1.0.0.yml",
"definitions/subdir_a/2.0.0.yml",
"definitions/subdir_a/3.0.0.othersuffix",
"definitions/subdir_b/3.0.0.yml",
"definitions/subdir_b/4.0.0.yml",
)

assert versions.latest_in_dir(tmp_path / "definitions") == {
Expand Down
6 changes: 5 additions & 1 deletion versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def latest_in_gitref(
.decode("utf-8")
.splitlines()
)
if Path(line).suffix == ".yml"
)


Expand All @@ -51,7 +52,10 @@ def latest_in_dir(path: Path) -> Dict[str, semver.version.Version]:
its latest version found.
"""
return _latest_versions(
Path(current) / f for current, _, files in os.walk(path) for f in files
Path(current) / f
for current, _, files in os.walk(path)
for f in files
if Path(f).suffix == ".yml"
)


Expand Down

0 comments on commit 5263505

Please sign in to comment.