Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support excluding pinned files #180

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading