Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
30 changes: 12 additions & 18 deletions gitman/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@ def __post_init__(self):
if self.root is None:
self.root = os.getcwd()

def _on_post_load(self):
for source in self.sources:
source._on_post_load() # pylint: disable=protected-access

for source in self.sources_locked:
source._on_post_load() # pylint: disable=protected-access

# check for conflicts between source names and group names
for source in self.sources:
for group in self.groups:
if source.name == group.name:
msg = (
"Name conflict detected between source name and "
"group name \"{}\""
).format(source.name)
raise exceptions.InvalidConfig(msg)

@property
def config_path(self):
"""Get the full path to the config file."""
Expand All @@ -61,6 +44,17 @@ def location_path(self):
assert self.root
return os.path.normpath(os.path.join(self.root, self.location))

def validate(self):
"""Check for conflicts between source names and group names."""
for source in self.sources:
for group in self.groups:
if source.name == group.name:
msg = (
"Name conflict detected between source name and "
"group name \"{}\""
).format(source.name)
raise exceptions.InvalidConfig(msg)

def get_path(self, name=None):
"""Get the full path to a dependency or internal file."""
base = self.location_path
Expand Down Expand Up @@ -340,7 +334,7 @@ def load_config(start=None, *, search=True):
for filename in os.listdir(path):
if _valid_filename(filename):
config = Config(path, filename)
config._on_post_load() # pylint: disable=protected-access
config.validate()
log.debug("Found config: %s", config.path)
return config

Expand Down
9 changes: 0 additions & 9 deletions gitman/models/group.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from dataclasses import dataclass
from typing import List

from .. import exceptions


@dataclass
class Group:
Expand All @@ -11,13 +9,6 @@ class Group:
name: str
members: List[str]

def __post_init__(self):
# TODO: Remove this?
for name in ['name', 'members']:
if not getattr(self, name):
msg = "'{}' required for {}".format(name, repr(self))
raise exceptions.InvalidConfig(msg)

def __repr__(self):
return "<group {}>".format(self)

Expand Down
9 changes: 0 additions & 9 deletions gitman/models/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ class Source:
def __post_init__(self):
if self.name is None:
self.name = self._infer_name(self.repo)

# TODO: Remove this?
for name in ['name', 'repo', 'rev']:
if not getattr(self, name):
msg = "'{}' required for {}".format(name, repr(self))
raise exceptions.InvalidConfig(msg)

def _on_post_load(self):
# TODO: Remove this?
self.type = self.type or 'git'

def __repr__(self):
Expand Down
9 changes: 0 additions & 9 deletions gitman/tests/test_models_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ def test_init_link(self):

assert 'mock/link' == source.link

def test_init_error(self):
"""Verify the repository, name, and rev are required."""
with pytest.raises(ValueError):
Source(type='git', repo='', name='mock_name', rev='master')
with pytest.raises(ValueError):
Source(type='git', repo='http://mock.git', name='', rev='master')
with pytest.raises(ValueError):
Source(type='git', repo='http://mock.git', name='mock_name', rev='')

def test_repr(self, source):
"""Verify sources can be represented."""
assert "<source ['git'] 'repo' @ 'rev' in 'name' <- 'link'>" == repr(source)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def git_changes(
monkeypatch.setattr('gitman.git.changes', git_changes)
# patch standard input function to return "y" for each call
# this is necessary to answer the force-interactive question
# with yes todo the force process
# with yes to invoke the force process
monkeypatch.setattr('builtins.input', lambda x: "y")

config.datafile.text = strip(
Expand Down