Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

g.extension: fix getting addon directories names without Py/C source code #4900

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions scripts/g.extension/g.extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,27 +1447,38 @@ def install_extension_xml(edict):


def get_multi_addon_addons_which_install_only_html_man_page():
"""Get multi-addon addons which install only manual html page
"""Get multi-addon addons which installs only manual HTML page

:return list addons: list of multi-addon addons which install
only manual html page
:return list addon_dirs: list of addon directories which does
not contain any Python or C source code
files
"""
all_addon_dirs = []
addon_dirs = []
escape_dot = "\\."
addon_paths = re.findall(
rf".*{options['extension']}*.",
rf".*{options['extension'].replace('.', escape_dot)}.*",
get_addons_paths(gg_addons_base_dir=options["prefix"]),
)
addon_dir_paths = {os.path.dirname(i) for i in addon_paths}
for addon_dir in addon_dir_paths:
addon_src_files = list(
re.finditer(rf"{addon_dir}/(.*py)|(.*c)\n", "\n".join(addon_paths)),
re.finditer(
rf"{addon_dir.replace('.', escape_dot)}/(.*.py)|(.*.c)\n",
"\n".join(addon_paths),
),
)
if not addon_src_files:
all_addon_dirs.append(os.path.basename(addon_dir))
if addon_dir not in {os.path.dirname(i.group(0)) for i in addon_src_files}:
addon_dirs.append(os.path.basename(addon_dir))
else:
for addon_src_file in addon_src_files:
addon_paths.pop(addon_paths.index(addon_src_file.group(0)))
return all_addon_dirs
addon_paths.pop(
addon_paths.index(addon_src_file.group(0).replace("\n", ""))
)
gs.debug(
f"Addon directory names <{', '.join(addon_dirs)}> which "
" does not contain any Python or C source code files."
)
return addon_dirs


def filter_multi_addon_addons(mlist):
Expand All @@ -1491,6 +1502,7 @@ def filter_multi_addon_addons(mlist):
# to check if metadata is available if there is no executable module.
for addon in get_multi_addon_addons_which_install_only_html_man_page():
if addon in mlist:
gs.debug(f"Addon name <{addon}> which installs only HTML man page.")
mlist.pop(mlist.index(addon))
return mlist

Expand Down Expand Up @@ -2420,7 +2432,7 @@ def update_manual_page(module):
# Multi-addon
if len(addons) > 1:
for a in get_multi_addon_addons_which_install_only_html_man_page():
# Add multi-addon addons which install only manual html page
# Add multi-addon addons which installs only manual HTML page
addons.append(a)

for match in re.finditer(pattern, shtml):
Expand Down
8 changes: 8 additions & 0 deletions scripts/g.extension/testsuite/test_addons_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class TestModuleDownloadFromDifferentSources(TestCase):

def setUp(self):
"""Make sure we are not dealing with some old files"""
g_gisenv = SimpleModule("g.gisenv", set="DEBUG=1")
self.assertModule(g_gisenv)
if self.install_prefix.exists():
files = [path.name for path in self.install_prefix.iterdir()]
if files:
Expand All @@ -58,6 +60,8 @@ def setUp(self):

def tearDown(self):
"""Remove created files"""
g_gisenv = SimpleModule("g.gisenv", set="DEBUG=0")
self.assertModule(g_gisenv)
silent_rmtree(str(self.install_prefix))

@unittest.skipIf(ms_windows, "currently not supported on MS Windows")
Expand Down Expand Up @@ -232,6 +236,10 @@ def test_github_install_official_multimodule_and_check_metadata(self):
_("No metadata available for module '{}':").format(extension),
gextension.outputs.stderr,
)
self.assertIn(
f"Addon name <{extension}> which installs only HTML man page.",
gextension.outputs.stderr,
)


if __name__ == "__main__":
Expand Down
Loading