This commit is contained in:
Jeremy Zafran 2017-05-16 19:53:15 +00:00 committed by GitHub
commit d6f470299d
2 changed files with 43 additions and 1 deletions

View file

@ -73,10 +73,28 @@ def install_environment(
else:
venv_cmd.extend(['-p', os.path.realpath(sys.executable)])
repo_cmd_runner.run(venv_cmd, cwd='/')
# Determine if items in additional_dependencies are pip requirements
# files or package names
packages = []
requirements_files = []
for dependency in additional_dependencies:
if dependency.startswith('file:'):
requirements_files.append(dependency.split('file:', 1)[1])
else:
packages.append(dependency)
with in_env(repo_cmd_runner, version):
if requirements_files:
helpers.run_setup_cmd(
repo_cmd_runner,
('pip', 'install') +
tuple('-r{}'.format(req_file)
for req_file in requirements_files),
)
helpers.run_setup_cmd(
repo_cmd_runner,
('pip', 'install', '.') + additional_dependencies,
('pip', 'install', '.') + tuple(packages),
)

View file

@ -480,6 +480,30 @@ def test_additional_python_dependencies_installed(tempdir_factory, store):
assert 'mccabe' in output
@pytest.mark.integration
def test_additional_python_dependencies_requirements_files(
tempdir_factory,
store
):
path = make_repo(tempdir_factory, 'python_hooks_repo')
config = make_config_from_repo(path)
# write pip requirements file
req_file_path = os.path.join(path, 'requirements.txt')
with io.open(req_file_path, 'w') as fp:
fp.write('pep8')
config['hooks'][0]['additional_dependencies'] = \
['mccabe', 'file:{}'.format(req_file_path)]
repo = Repository.create(config, store)
repo.require_installed()
with python.in_env(repo._cmd_runner, 'default'):
output = cmd_output('pip', 'freeze', '-l')[1]
assert 'mccabe' in output
assert 'pep8' in output
@pytest.mark.integration
def test_additional_dependencies_roll_forward(tempdir_factory, store):
path = make_repo(tempdir_factory, 'python_hooks_repo')