Skip to content

Commit

Permalink
Change: reuse method for splitting dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasHargarter committed Jan 28, 2025
1 parent 6bbdbd6 commit d8693a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
26 changes: 15 additions & 11 deletions troubadix/plugins/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
)


def split_dependencies(value: str) -> list[str]:
"""
Remove single and/or double quotes, spaces
and create a list by using the comma as a separator
additionally, check and filter for inline comments
"""
dependencies = []
for line in value.splitlines():
subject = line[: line.index("#")] if "#" in line else line
_dependencies = re.sub(r'[\'"\s]', "", subject).split(",")
dependencies += [dep for dep in _dependencies if dep != ""]
return dependencies


class CheckDependencies(FilePlugin):
name = "check_dependencies"

Expand Down Expand Up @@ -60,17 +74,7 @@ def run(

for match in matches:
if match:
# Remove single and/or double quotes, spaces
# and create a list by using the comma as a separator
# additionally, check and filter for inline comments
dependencies = []

for line in match.group("value").splitlines():
subject = line[: line.index("#")] if "#" in line else line
_dependencies = re.sub(r'[\'"\s]', "", subject).split(",")
dependencies += [dep for dep in _dependencies if dep != ""]

for dep in dependencies:
for dep in split_dependencies(match.group("value")):
if not any(
(root / vers / dep).exists() for vers in FEED_VERSIONS
):
Expand Down
16 changes: 1 addition & 15 deletions troubadix/standalone_plugins/dependency_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
get_script_tag_pattern,
get_special_script_tag_pattern,
)
from troubadix.plugins.dependencies import split_dependencies
from troubadix.plugins.dependency_category_order import (
VTCategory,
)
Expand Down Expand Up @@ -193,21 +194,6 @@ def determine_feed(script_relative_path: Path) -> str:
return "community"


def split_dependencies(value: str) -> list[str]:
"""
removes blank lines, strips comments, cleans dependencies,
splits them by commas, and excludes empty strings.
"""
return [
dep
for line in value.splitlines()
if line.strip() # Ignore blank or whitespace-only lines
# ignore comment, clean line of unwanted chars, split by ','
for dep in re.sub(r'[\'"\s]', "", line.split("#", 1)[0]).split(",")
if dep # Include only non-empty
]


def extract_dependencies(content: str) -> list[Dependency]:
dependencies = []

Expand Down

0 comments on commit d8693a6

Please sign in to comment.