Skip to content

Commit

Permalink
Support excluding pinned files (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
simontoens authored Apr 17, 2024
1 parent cbd34b8 commit 2a79826
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions common/maveninstallinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ def get_maven_install_names_and_paths(self, repository_root):
"""
Returns a list of tuples (mvn install name, mvn install path)
"""
# paths that start with '-' are excluded if found in glob expansions
excluded_paths = [p[1:].strip() for p in self.maven_install_paths if self._is_excluded_path(p)]
names_and_paths = []
for rel_path in self.maven_install_paths:
if self._is_excluded_path(rel_path):
# excluded paths are handled below
continue
path = os.path.join(repository_root, rel_path)
name_and_path = self._process_path(path)
if name_and_path is None:
globbed_names_and_paths = []
if "*" in path:
for path in glob.glob(path):
if path[len(repository_root)+1:] in excluded_paths:
continue
name_and_path = self._process_path(path)
if name_and_path is not None:
globbed_names_and_paths.append(name_and_path)
Expand All @@ -36,6 +43,9 @@ def get_maven_install_names_and_paths(self, repository_root):
names_and_paths.append(name_and_path)
return names_and_paths

def _is_excluded_path(self, path):
return path.startswith("-")

def _process_path(self, path):
"""
Returns a tuple (mvn install name, mvn install path) or None
Expand Down
15 changes: 15 additions & 0 deletions tests/maveninstallinfotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ def test_path_with_glob(self):
self.assertEquals("my_rules", files[1][0])
self.assertEquals(os.path.join(repo_root, "tools", "my_rules_install.json"), files[1][1])

def test_path_with_glob_and_exclusions(self):
repo_root = tempfile.mkdtemp("monorepo")
self._touch_file_at_path(repo_root, "tools/my_rules_install.json")
self._touch_file_at_path(repo_root, "tools/maven_install.json")
self._touch_file_at_path(repo_root, "tools/maven_blah_install.json")
m = maveninstallinfo.MavenInstallInfo(("tools/*", "-tools/maven_install.json",))

files = m.get_maven_install_names_and_paths(repo_root)

self.assertEquals(2, len(files))
self.assertEquals("maven_blah", files[0][0])
self.assertEquals(os.path.join(repo_root, "tools", "maven_blah_install.json"), files[0][1])
self.assertEquals("my_rules", files[1][0])
self.assertEquals(os.path.join(repo_root, "tools", "my_rules_install.json"), files[1][1])

def _touch_file_at_path(self, repo_root_path, file_path):
path = os.path.join(repo_root_path, file_path)
parent_dir = os.path.dirname(path)
Expand Down

0 comments on commit 2a79826

Please sign in to comment.