Skip to content

Commit

Permalink
adding command line option to install config files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Aug 22, 2018
1 parent fc7460f commit e83129b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
19 changes: 19 additions & 0 deletions karr_lab_build_utils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ def _default(self):
buildHelper.create_documentation_template(dirname=args.dirname)


class DownloadInstallPackageConfigFilesController(cement.Controller):
""" Download and install configuration files from GitHub configuration repository """

class Meta:
label = 'download-install-package-config-files'
description = 'Download and install configuration files from GitHub configuration repository'
stacked_on = 'base'
stacked_type = 'nested'
arguments = []

@cement.ex(hide=True)
def _default(self):
args = self.app.pargs
buildHelper = BuildHelper()
buildHelper.download_package_config_files()
buildHelper.install_package_config_files()


class RunTestsController(cement.Controller):
""" cement.Controller for run_tests.
Expand Down Expand Up @@ -942,6 +960,7 @@ class Meta:
CreateRepositoryController,
SetupRepositoryController,
CreateDocumentationTemplateController,
DownloadInstallPackageConfigFilesController,
RunTestsController,
DockerController,
DockerCreateContainerController,
Expand Down
8 changes: 4 additions & 4 deletions karr_lab_build_utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ def __init__(self):
self.configs_repo_password = config['configs_repo_password']
self.configs_repo_path = os.path.expanduser(config['configs_repo_path'])

self.download_package_configs()
self.set_third_party_configs()
self.download_package_config_files()
self.install_package_config_files()
config = karr_lab_build_utils.config.core.get_config()['karr_lab_build_utils']
self.configs_repo_url = config['configs_repo_url']
self.configs_repo_username = config['configs_repo_username']
Expand Down Expand Up @@ -2469,7 +2469,7 @@ def get_build_config(self):
with open('.karr_lab_build_utils.yml', 'r') as file:
return yaml.load(file)

def download_package_configs(self):
def download_package_config_files(self):
""" Download the configuration repository
Args:
Expand All @@ -2487,7 +2487,7 @@ def download_package_configs(self):
self.configs_repo_username, self.configs_repo_password))
git.Repo.clone_from(url, self.configs_repo_path)

def set_third_party_configs(self, overwrite=False):
def install_package_config_files(self, overwrite=False):
""" Copy third party configs to their appropriate paths from the configs repository
Args:
Expand Down
17 changes: 11 additions & 6 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2367,13 +2367,13 @@ def test_upload_package_to_pypi(self):
self.assertRegexpMatches(captured.stdout.get_text(), 'Uploading distributions to https://test\.pypi\.org/legacy/')
self.assertEqual(captured.stderr.get_text().strip(), '')

def test_download_package_configs(self):
def test_download_package_config_files(self):
build_helper = self.construct_build_helper()
build_helper.configs_repo_path = tempfile.mkdtemp()
shutil.rmtree(build_helper.configs_repo_path)

# download package configs
build_helper.download_package_configs()
build_helper.download_package_config_files()
self.assertTrue(os.path.isdir(build_helper.configs_repo_path))

shutil.rmtree(build_helper.configs_repo_path)
Expand All @@ -2387,16 +2387,16 @@ def side_effect(src, dest):
else:
default_func(src, dest)
with mock.patch('git.Repo.clone_from', side_effect=side_effect):
build_helper.download_package_configs()
build_helper.download_package_config_files()
self.assertTrue(os.path.isdir(build_helper.configs_repo_path))

# update package configs
build_helper.download_package_configs()
build_helper.download_package_config_files()

# cleanup
shutil.rmtree(build_helper.configs_repo_path)

def test_set_third_party_configs(self):
def test_install_package_config_files(self):
build_helper = self.construct_build_helper()
tmp_dir = build_helper.configs_repo_path = tempfile.mkdtemp()
os.mkdir(os.path.join(tmp_dir, 'third_party'))
Expand All @@ -2409,7 +2409,7 @@ def test_set_third_party_configs(self):

# update package configs
with EnvironmentVarGuard() as env:
build_helper.set_third_party_configs()
build_helper.install_package_config_files()

# test
with open(dest, 'r') as file:
Expand All @@ -2418,6 +2418,11 @@ def test_set_third_party_configs(self):
# cleanup
shutil.rmtree(build_helper.configs_repo_path)

def test_download_install_package_config_files(self):
with self.construct_environment():
with __main__.App(argv=['download-install-package-config-files']) as app:
app.run()

def test_get_version(self):
self.assertIsInstance(karr_lab_build_utils.__init__.__version__, str)

Expand Down

0 comments on commit e83129b

Please sign in to comment.