Skip to content

Commit

Permalink
Refactor methods names: "deps" => "dependencies"
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Jan 6, 2017
1 parent 99d17e5 commit 5c71cc2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ COVERAGE_SPACE := $(BIN)/coverage.space

RANDOM_SEED ?= $(shell date +%s)

PYTEST_CORE_OPTS := -r xXw -vv
PYTEST_CORE_OPTS := -ra -vv
PYTEST_COV_OPTS := --cov=$(PACKAGE) --no-cov-on-fail --cov-report=term-missing --cov-report=html
PYTEST_RANDOM_OPTS := --random --random-seed=$(RANDOM_SEED)

Expand All @@ -172,14 +172,14 @@ test-unit: install ## Run the unit tests

.PHONY: test-int
test-int: install ## Run the integration tests
@ if test -e $(FAILURES); then $(PYTEST) $(PYTEST_OPTS_FAILFAST) tests; fi
@ if test -e $(FAILURES); then TEST_INTEGRATION=true $(PYTEST) $(PYTEST_OPTS_FAILFAST) tests; fi
$(PYTEST) $(PYTEST_OPTS) tests --junitxml=$(REPORTS)/integration.xml
$(COVERAGE_SPACE) $(REPOSITORY) integration

.PHONY: test-all
test-all: install ## Run all the tests
@ if test -e $(FAILURES); then $(PYTEST) $(PYTEST_OPTS_FAILFAST) $(PACKAGES); fi
$(PYTEST) $(PYTEST_OPTS) $(PACKAGES) --junitxml=$(REPORTS)/overall.xml
@ if test -e $(FAILURES); then TEST_INTEGRATION=true $(PYTEST) $(PYTEST_OPTS_FAILFAST) $(PACKAGES); fi
TEST_INTEGRATION=true $(PYTEST) $(PYTEST_OPTS) $(PACKAGES) --junitxml=$(REPORTS)/overall.xml
$(COVERAGE_SPACE) $(REPOSITORY) overall

.PHONY: read-coverage
Expand Down
22 changes: 13 additions & 9 deletions gitman/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ def install(*names, root=None, depth=None,
common.show()
common.show("Installing dependencies...", color='message', log=False)
common.show()
count = config.install_deps(*names, update=False, depth=depth,
force=force, fetch=fetch, clean=clean)
count = config.install_dependencies(
*names, update=False, depth=depth,
force=force, fetch=fetch, clean=clean,
)

return _display_result("install", "Installed", count)

Expand Down Expand Up @@ -83,15 +85,16 @@ def update(*names, root=None, depth=None,
common.show()
common.show("Updating dependencies...", color='message', log=False)
common.show()
count = config.install_deps(
count = config.install_dependencies(
*names, update=True, depth=depth,
recurse=recurse, force=force, fetch=True, clean=clean)
recurse=recurse, force=force, fetch=True, clean=clean,
)
common.dedent(level=0)
if count and lock is not False:
common.show("Recording installed versions...",
color='message', log=False)
common.show()
config.lock_deps(*names, obey_existing=lock is None)
config.lock_dependencies(*names, obey_existing=lock is None)

return _display_result("update", "Updated", count)

Expand Down Expand Up @@ -120,7 +123,8 @@ def display(*, root=None, depth=None, allow_dirty=True):
common.show()
config.log(datetime.datetime.now().strftime("%F %T"))
count = 0
for identity in config.get_deps(depth=depth, allow_dirty=allow_dirty):
for identity in config.get_dependencies(depth=depth,
allow_dirty=allow_dirty):
count += 1
config.log("{}: {} @ {}", *identity)
config.log()
Expand Down Expand Up @@ -148,7 +152,7 @@ def lock(*names, root=None):
common.show()
common.show("Locking dependencies...", color='message', log=False)
common.show()
count = config.lock_deps(*names, obey_existing=False)
count = config.lock_dependencies(*names, obey_existing=False)
common.dedent(level=0)

return _display_result("lock", "Locked", count)
Expand All @@ -175,11 +179,11 @@ def delete(*, root=None, force=False):
common.show("Checking for uncommitted changes...",
color='message', log=False)
common.show()
count = len(list(config.get_deps(allow_dirty=force)))
count = len(list(config.get_dependencies(allow_dirty=force)))
common.dedent(level=0)
common.show("Deleting all dependencies...", color='message', log=False)
common.show()
config.uninstall_deps()
config.uninstall_dependencies()

return _display_result("delete", "Deleted", count, allow_zero=True)

Expand Down
26 changes: 13 additions & 13 deletions gitman/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def log_path(self):

@property
def location_path(self):
"""Get the full path to the sources location."""
"""Get the full path to the dependency storage location."""
return os.path.join(self.root, self.location)

def get_path(self, name=None):
Expand All @@ -58,10 +58,10 @@ def get_path(self, name=None):
else:
return base

def install_deps(self, *names, depth=None,
update=True, recurse=False,
force=False, fetch=False, clean=True):
"""Get all sources."""
def install_dependencies(self, *names, depth=None,
update=True, recurse=False,
force=False, fetch=False, clean=True):
"""Download or update the specified dependencies."""
if depth == 0:
log.info("Skipped directory: %s", self.location_path)
return 0
Expand Down Expand Up @@ -92,7 +92,7 @@ def install_deps(self, *names, depth=None,
config = load_config()
if config:
common.indent()
count += config.install_deps(
count += config.install_dependencies(
depth=None if depth is None else max(0, depth - 1),
update=update and recurse,
recurse=recurse,
Expand All @@ -111,7 +111,7 @@ def install_deps(self, *names, depth=None,

return count

def lock_deps(self, *names, obey_existing=True):
def lock_dependencies(self, *names, obey_existing=True):
"""Lock down the immediate dependency versions."""
shell.cd(self.location_path)
common.show()
Expand Down Expand Up @@ -143,12 +143,12 @@ def lock_deps(self, *names, obey_existing=True):

return count

def uninstall_deps(self):
"""Remove the sources location."""
def uninstall_dependencies(self):
"""Delete the dependency storage location."""
shell.rm(self.location_path)
common.show()

def get_deps(self, depth=None, allow_dirty=True):
def get_dependencies(self, depth=None, allow_dirty=True):
"""Yield the path, repository URL, and hash of each dependency."""
if not os.path.exists(self.location_path):
return
Expand All @@ -169,7 +169,7 @@ def get_deps(self, depth=None, allow_dirty=True):
config = load_config()
if config:
common.indent()
yield from config.get_deps(
yield from config.get_dependencies(
depth=None if depth is None else max(0, depth - 1),
allow_dirty=allow_dirty,
)
Expand All @@ -185,7 +185,7 @@ def log(self, message="", *args):
outfile.write(message.format(*args) + '\n')

def _get_sources(self, *, use_locked=None):
"""Merge source lists using requested section as the base."""
"""Merge source lists using the requested section as the base."""
if use_locked is True:
if self.sources_locked:
return self.sources_locked
Expand All @@ -198,7 +198,7 @@ def _get_sources(self, *, use_locked=None):
sources = self.sources
else:
if self.sources_locked:
log.info("Defalting to locked sources...")
log.info("Defaulting to locked sources...")
sources = self.sources_locked
else:
log.info("No locked sources, using latest...")
Expand Down
24 changes: 12 additions & 12 deletions gitman/tests/test_models_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,61 @@ def test_install_and_list(self):
"""Verify the correct dependencies are installed."""
config = Config(FILES)

count = config.install_deps()
count = config.install_dependencies()
assert 7 == count

deps = list(config.get_deps())
deps = list(config.get_dependencies())
assert 7 == len(deps)
assert 'eb37743011a398b208dd9f9ef79a408c0fc10d48' == deps[0][2]
assert 'ddbe17ef173538d1fda29bd99a14bab3c5d86e78' == deps[1][2]
assert '1de84ca1d315f81b035cd7b0ecf87ca2025cdacd' == deps[0][2]
assert '050290bca3f14e13fd616604202b579853e7bfb0' == deps[1][2]
assert 'fb693447579235391a45ca170959b5583c5042d8' == deps[2][2]
# master branch always changes --------------------- deps[3][2]
# master branch always changes --------------------- deps[4][2]
assert '7bd138fe7359561a8c2ff9d195dff238794ccc04' == deps[5][2]
assert '2da24fca34af3748e3cab61db81a2ae8b35aec94' == deps[6][2]

assert 5 == len(list(config.get_deps(depth=2)))
assert 5 == len(list(config.get_dependencies(depth=2)))

assert 3 == len(list(config.get_deps(depth=1)))
assert 3 == len(list(config.get_dependencies(depth=1)))

assert 0 == len(list(config.get_deps(depth=0)))
assert 0 == len(list(config.get_dependencies(depth=0)))

@pytest.mark.integration
def test_install_with_dirs(self):
"""Verify the dependency list can be filtered."""
config = Config(FILES)

count = config.install_deps('gitman_2', 'gitman_3')
count = config.install_dependencies('gitman_2', 'gitman_3')
assert 2 == count

def test_install_with_dirs_unknown(self):
"""Verify zero dependencies are installed with an unknown dependency."""
config = Config(FILES)

count = config.install_deps('foobar')
count = config.install_dependencies('foobar')
assert 0 == count

def test_install_with_depth_0(self):
"""Verify an install depth of 0 installs nothing."""
config = Config(FILES)

count = config.install_deps(depth=0)
count = config.install_dependencies(depth=0)
assert 0 == count

@pytest.mark.integration
def test_install_with_depth_1(self):
"""Verify an install depth of 1 installs the direct dependencies."""
config = Config(FILES)

count = config.install_deps(depth=1)
count = config.install_dependencies(depth=1)
assert 3 == count

@pytest.mark.integration
def test_install_with_depth_2(self):
"""Verify an install depth of 2 installs 1 level of nesting."""
config = Config(FILES)

count = config.install_deps(depth=2)
count = config.install_dependencies(depth=2)
assert 5 == count


Expand Down

0 comments on commit 5c71cc2

Please sign in to comment.