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

Add new regex option to gh-release in order filter source binaries #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions nanolayer/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def install_gh_release_binary(
None, help="comma separated list of binary names"
),
version: str = "latest",
source_binaries_filter_regex: Optional[str] = None,
lib_name: Optional[str] = None,
asset_regex: Optional[str] = None,
bin_location: Optional[str] = None,
Expand All @@ -158,6 +159,7 @@ def install_gh_release_binary(
binary_names=binary_names.split(","),
lib_name=lib_name,
bin_location=bin_location,
source_binaries_filter_regex=source_binaries_filter_regex,
lib_location=lib_location,
version=version,
asset_regex=asset_regex,
Expand Down
3 changes: 2 additions & 1 deletion nanolayer/installers/gh_release/gh_release_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def install(
binary_names: List[str],
lib_name: Optional[str] = None,
bin_location: Optional[Union[str, Path]] = None,
source_binaries_filter_regex: Optional[str] = None,
lib_location: Optional[Union[str, Path]] = None,
asset_regex: Optional[str] = None,
version: str = "latest",
Expand Down Expand Up @@ -210,7 +211,7 @@ def install(
logger.warning("asset recognized as an archive file")

archive_member_names = BinaryResolver.resolve(
temp_asset_path, binary_names
temp_asset_path, binary_names, source_binaries_filter_regex
)
assert len(archive_member_names) == len(
binary_names
Expand Down
11 changes: 10 additions & 1 deletion nanolayer/installers/gh_release/resolvers/binary_resolver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import stat
from typing import List

Expand Down Expand Up @@ -33,10 +34,11 @@ class BinaryResolverError(Exception):
pass

@classmethod
def resolve(cls, archive_path: str, binary_names: List[str]) -> List[str]:
def resolve(cls, archive_path: str, binary_names: List[str], source_binaries_filter_regex: str = None) -> List[str]:
binary_members = []
with Archive(archive_path) as archive_file:
# resolve target member name
archive_file: Archive = archive_file
if len(archive_file.get_file_members()) == 1:
if len(binary_names) > 1:
raise cls.BinaryResolverError(
Expand All @@ -48,6 +50,13 @@ def resolve(cls, archive_path: str, binary_names: List[str]) -> List[str]:
else:
for binary_name in binary_names:
target_member_names = archive_file.names_by_filename(binary_name)

if source_binaries_filter_regex:
target_member_names = [
name for name in target_member_names
if re.match(source_binaries_filter_regex, name)
]

if len(target_member_names) > 1:
# try narrow it down to single binary using filters
filtered_target_member_names = list(
Expand Down