Skip to content

Commit cb5444f

Browse files
committed
Support plugins with sidecar documentation
1 parent 78633d6 commit cb5444f

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

galaxy_importer/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@
7575
LEGACY_NAMESPACE_REGEXP = re.compile("^([a-zA-Z0-9.]+[-_]?)+$")
7676

7777

78-
class ContentCategory(enum.Enum):
78+
class ContentCategory(str, enum.Enum):
7979
MODULE = "module"
8080
ROLE = "role"
8181
PLUGIN = "plugin"
8282
PLAYBOOK = "playbook"
8383
EXTENSION = "extension"
8484

8585

86-
class ContentType(enum.Enum):
86+
class ContentType(str, enum.Enum):
8787
PLAYBOOK = "playbook"
8888
ROLE = "role"
8989
MODULE = "module"

galaxy_importer/loaders/collection.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from ansible_builder._target_scripts import introspect
2929

3030
from galaxy_importer import exceptions as exc
31-
from galaxy_importer.finder import ContentFinder, FileWalker
31+
from galaxy_importer.finder import ContentFinder, FileWalker, Result
3232
from galaxy_importer import constants
3333
from galaxy_importer import loaders, file_parser, schema
3434
from galaxy_importer.utils import markup as markup_utils
@@ -370,8 +370,21 @@ def _check_filename_matches_manifest(self):
370370

371371
def _load_contents(self):
372372
"""Find and load data for each content inside the collection."""
373-
found_contents = ContentFinder().find_contents(self.path, self.log)
374-
for content_type, rel_path in found_contents:
373+
found_contents = set()
374+
if self.doc_strings:
375+
# This block adds paths found by ansible-doc, which does not currently
376+
# include extensions (eda) as of ansible-core 2.19
377+
for content_type, contents in self.doc_strings.items():
378+
content_type = constants.ContentType(content_type)
379+
for _, content in contents.items():
380+
rel_path = os.path.relpath(content["doc"]["filename"], self.path)
381+
found_contents.add(Result(content_type, rel_path))
382+
# This adds all .py and .ps1 paths in a collection. The effect is finding content
383+
# in collections such as extensions (eda). Once ansible-doc supports enumerating
384+
# extensions this could be made conditional
385+
found_contents.update(ContentFinder().find_contents(self.path, self.log))
386+
387+
for content_type, rel_path in sorted(found_contents):
375388
loader_cls = loaders.get_loader_cls(content_type)
376389
loader = loader_cls(
377390
content_type, rel_path, self.path, self.doc_strings, self.cfg, self.log

tests/integration/test_collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_collection_community_general_import(workdir, local_fast_config):
5050

5151
# make sure it found all the files
5252
contents = {(x["content_type"], x["name"]): x for x in results["contents"]}
53-
assert len(contents.keys()) == 831
53+
assert len(contents.keys()) == 842
5454

5555
# check a small sample
5656
assert ("test", "a_module") in contents
@@ -69,7 +69,7 @@ def test_collection_community_general_import(workdir, local_fast_config):
6969
docs_contents = {
7070
(x["content_type"], x["content_name"]): x for x in results["docs_blob"]["contents"]
7171
}
72-
assert len(docs_contents.keys()) == 831
72+
assert len(docs_contents.keys()) == 842
7373

7474
# check a small sample
7575
assert ("test", "a_module") in docs_contents

tests/integration/test_eda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ def test_eda_import(workdir, local_image_config):
5050

5151
# the data should have all the relevant bits
5252
assert results["contents"] == [
53-
{"content_type": "playbook", "description": None, "name": "hello.yml"},
54-
{"content_type": "role", "description": "your role description", "name": "test_role"},
5553
{
5654
"content_type": "module",
5755
"description": "Upper cases a passed in string",
5856
"name": "upcase",
5957
},
58+
{"content_type": "playbook", "description": None, "name": "hello.yml"},
59+
{"content_type": "role", "description": "your role description", "name": "test_role"},
6060
]
6161
assert results["docs_blob"]["contents"] != []
6262
assert results["docs_blob"]["collection_readme"]["name"] == "README.md"

0 commit comments

Comments
 (0)