From 660690a6ada98d5636d31b5b8e1fb45b3666d3cc Mon Sep 17 00:00:00 2001 From: Rob Dennis Date: Tue, 2 Oct 2018 15:55:26 -0400 Subject: [PATCH] taking external patch for extra_files --- ship_it/manifest.py | 20 +++++++++++++++++++- tests/test_manifest.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/ship_it/manifest.py b/ship_it/manifest.py index 25d8a82..cb6c69a 100644 --- a/ship_it/manifest.py +++ b/ship_it/manifest.py @@ -61,6 +61,8 @@ def get_args_and_flags(self): cfg_args, cfg_flags = self.get_config_args_and_flags() args.extend(cfg_args) flags.extend(cfg_flags) + extra_args = self.get_extra_files_args() + args.extend(extra_args) flags.extend(self.get_dependency_flags()) flags.extend(self.get_exclude_flags()) @@ -87,6 +89,23 @@ def get_config_args_and_flags(self): return args, flags + def get_extra_files_args(self): + args = [] + if not self.contents.get('extra_files'): + return args + + for remote_path, local_path in self.contents['extra_files'].items(): + remote_file = path.normpath(path.join(self.remote_virtualenv_path, + remote_path)) + assert path.isabs(remote_file) + local_file = path.normpath(path.join(self.manifest_dir, local_path)) + # We'll rely on fpm to error if it's a nonexistent path. + assert path.isabs(local_file) + args.append('{}={}/'.format(pipes.quote(local_file), + pipes.quote(path.dirname(remote_file)))) + return args + + def get_single_flags(self): flags = { @@ -180,4 +199,3 @@ def local_virtualenv_path(self): @property def remote_virtualenv_path(self): return path.join(self.remote_package_path, self.virtualenv_name) - diff --git a/tests/test_manifest.py b/tests/test_manifest.py index 717a94a..3a6e6fd 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -291,6 +291,35 @@ def test_config(self, manifest, test_cfg, expected_args, expected_flags): assert sorted(actual_args) == sorted(expected_args) assert sorted(actual_flags) == sorted(expected_flags) + @pytest.mark.parametrize('test_extra_files, expected_args', [ + # we don't have to have extra files + ({}, []), + # relative path files + ({'content/important.txt': 'src/important.txt'}, + ['/test_dir/src/important.txt=/opt/ship_it/content/']), + # relative path directories + ({'content': 'content/'}, + ['/test_dir/content=/opt/ship_it/']), + # absolute path files + ({'/etc/ship_it/important.txt': 'external/important.txt'}, + ['/test_dir/external/important.txt=/etc/ship_it/']), + # absolute path directores + ({'/etc/ship_it/content': 'external/content/'}, + ['/test_dir/external/content=/etc/ship_it/']), + # more than one extra file + ({'/etc/ship_it/important.txt': 'external/important.txt', + 'content/important.txt': 'src/important.txt'}, + ['/test_dir/external/important.txt=/etc/ship_it/', + '/test_dir/src/important.txt=/opt/ship_it/content/']), + ]) + def test_extra_files(self, manifest, test_extra_files, expected_args): + """ + Test getting the right arguments from extra files/ + """ + manifest.contents.update({'extra_files': test_extra_files}) + actual_args = manifest.get_extra_files_args() + assert sorted(actual_args) == sorted(expected_args) + @pytest.mark.parametrize('dependency_type,value,expected', [ # you can specify nothing, and it's fine ('depends', [], []), @@ -372,20 +401,23 @@ def test_remote_pkg_path_arg(self, mock_remote_pkg_path, manifest): 'group': 'root'}, 'root', 'root'), ]) @mock.patch('ship_it.manifest.Manifest.get_config_args_and_flags') + @mock.patch('ship_it.manifest.Manifest.get_extra_files_args') @mock.patch('ship_it.manifest.Manifest.get_single_flags') @mock.patch('ship_it.manifest.Manifest.get_dependency_flags') @mock.patch('ship_it.manifest.Manifest.get_exclude_flags') def test_get_overall_args(self, mock_excludes, mock_depends, mock_single, - mock_cfg, manifest, cfg_update, expected_user, expected_group): + mock_extra, mock_cfg, manifest, cfg_update, expected_user, expected_group): # Return values must be set here, rather than in the decorator, # to reset their state for each iteration. mock_excludes.return_value = [('exclude', '**.pyc'), ('exclude', '**.pyo')] mock_depends.return_value = [('depends', 'weird-dependency == 0.1')] mock_single.return_value = [('single', 'flag')] mock_cfg.return_value = (['cfg arg'], [('cfg', 'flag')]) + mock_extra.return_value = ['extra=arg'] expected_args = [ 'cfg arg', + 'extra=arg', '/test_dir/build/ship_it=/opt' ] expected_flags = [