Make sure paths are treated correctly when building collection files manifest (#81619)

* Make sure paths are correct when building collection files manifest

This commit makes sure the path of the files part of
the collection build manifest are correct.

This commit uses os.path.commonprefix instead of
dealing with strings.

Signed-off-by: Carlos Camacho <ccamacho@redhat.com>

Bugfix Pull Request
Fixes: #81618

* Revert the change note type to `minor_changes`

* Clarify the change note with user-oriented details

---------

Signed-off-by: Carlos Camacho <ccamacho@redhat.com>
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
pull/81738/head
Carlos Camacho 2 years ago committed by GitHub
parent e4b9f9c6ae
commit 9244b2bff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,4 @@
minor_changes:
- >-
ansible-galaxy - Started normalizing build directory with a trailing separator when building collections, internally.
(https://github.com/ansible/ansible/pull/81619).

@ -1203,10 +1203,17 @@ def _build_files_manifest_walk(b_collection_path, namespace, name, ignore_patter
manifest = _make_manifest()
def _discover_relative_base_directory(b_path: bytes, b_top_level_dir: bytes) -> bytes:
if b_path == b_top_level_dir:
return b''
common_prefix = os.path.commonpath((b_top_level_dir, b_path))
b_rel_base_dir = os.path.relpath(b_path, common_prefix)
return b_rel_base_dir.lstrip(os.path.sep.encode())
def _walk(b_path, b_top_level_dir):
b_rel_base_dir = _discover_relative_base_directory(b_path, b_top_level_dir)
for b_item in os.listdir(b_path):
b_abs_path = os.path.join(b_path, b_item)
b_rel_base_dir = b'' if b_path == b_top_level_dir else b_path[len(b_top_level_dir) + 1:]
b_rel_path = os.path.join(b_rel_base_dir, b_item)
rel_path = to_text(b_rel_path, errors='surrogate_or_strict')

@ -39,10 +39,17 @@ def reset_cli_args():
co.GlobalCLIArgs._Singleton__instance = None
@pytest.fixture()
def collection_input(tmp_path_factory):
''' Creates a collection skeleton directory for build tests '''
test_dir = to_text(tmp_path_factory.mktemp('test-ÅÑŚÌβŁÈ Collections Input'))
@pytest.fixture
def collection_path_suffix(request):
"""Return test collection path suffix or the default."""
return getattr(request, 'param', 'test-ÅÑŚÌβŁÈ Collections Input')
@pytest.fixture
def collection_input(tmp_path_factory, collection_path_suffix):
"""Create a collection skeleton directory for build tests."""
test_dir = to_text(tmp_path_factory.mktemp(collection_path_suffix))
namespace = 'ansible_namespace'
collection = 'collection'
skeleton = os.path.join(os.path.dirname(os.path.split(__file__)[0]), 'cli', 'test_data', 'collection_skeleton')
@ -467,6 +474,14 @@ def test_build_existing_output_without_force(collection_input):
collection.build_collection(to_text(input_dir, errors='surrogate_or_strict'), to_text(output_dir, errors='surrogate_or_strict'), False)
@pytest.mark.parametrize(
'collection_path_suffix',
(
'test-ÅÑŚÌβŁÈ Collections Input 1 with_slash/',
'test-ÅÑŚÌβŁÈ Collections Input 2 no slash',
),
indirect=('collection_path_suffix', ),
)
def test_build_existing_output_with_force(collection_input):
input_dir, output_dir = collection_input

Loading…
Cancel
Save