Skip to content

Commit

Permalink
Merge pull request #239 from brandonaut/install-mixed-groups-and-sources
Browse files Browse the repository at this point in the history
Add ability to specify groups and sources together during install
  • Loading branch information
jacebrowning committed Dec 22, 2020
2 parents 922fe4a + 76fbb33 commit 1fe0741
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 22 deletions.
37 changes: 15 additions & 22 deletions gitman/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,33 +311,26 @@ def _get_sources(self, *, use_locked=None):

return sources + extras

def _get_default_group(self, names):
"""Get default group if names is empty."""
use_default = not names
default_groups = [
group
for group in self.groups
if group.name == self.default_group and use_default
]

return default_groups

def _get_sources_filter(self, *names, sources, skip_default_group):
"""Get filtered sublist of sources."""
sources_filter = None
names_list = list(names)

groups_filter = [group for group in self.groups if group.name in list(names)]
if not skip_default_group:
groups_filter += self._get_default_group(list(names))
if not names_list and not skip_default_group:
names_list.append(self.default_group)

if groups_filter:
sources_filter = [
members for group in groups_filter for members in group.members
]
else:
sources_filter = list(names) if names else [s.name for s in sources]
# Add sources from groups
groups_filter = [group for group in self.groups if group.name in names_list]
sources_filter = [member for group in groups_filter for member in group.members]

# Add independent sources
sources_filter.extend(
[source.name for source in sources if source.name in names_list]
)

if not sources_filter:
sources_filter = [source.name for source in sources]

return sources_filter
return list(set(sources_filter))


def load_config(start=None, *, search=True):
Expand Down
60 changes: 60 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,66 @@ def it_contains_only_the_sparse_paths(config):
expect(dir_listing).contains('src')
expect(len(dir_listing) == 1)

def describe_mixed_names():
@pytest.fixture
def config_with_group(config):
config.datafile.text = strip(
"""
location: deps
sources:
- name: gitman_1
type: git
repo: https://github.com/jacebrowning/gitman-demo
sparse_paths:
-
rev: example-branch
link:
scripts:
-
- name: gitman_2
type: git
repo: https://github.com/jacebrowning/gitman-demo
sparse_paths:
-
rev: example-tag
link:
scripts:
-
groups:
- name: main_group
members:
- gitman_1
- name: super_group
members:
- gitman_1
- gitman_2
"""
)
config.datafile.load()

return config

def install_with_group_and_source_is_successful(config_with_group):
expect(
gitman.install("main_group", "gitman_2", depth=1, force=True)
) == True
expect(
os.path.exists(os.path.join(config_with_group.location, 'gitman_1'))
) == True
expect(
os.path.exists(os.path.join(config_with_group.location, 'gitman_2'))
) == True

def groups_with_redundant_deps_install_successfully(config_with_group):
expect(
gitman.install("main_group", "super_group", depth=1, force=True)
) == True

def group_and_redundant_source_install_successfully(config_with_group):
expect(
gitman.install("main_group", "gitman_1", depth=1, force=True)
) == True

def describe_default_group():
@pytest.fixture
def config_with_default_group(config):
Expand Down

0 comments on commit 1fe0741

Please sign in to comment.