Skip to content

Commit

Permalink
extra
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Nov 9, 2023
1 parent 987d8da commit dd9998a
Showing 1 changed file with 42 additions and 22 deletions.
64 changes: 42 additions & 22 deletions check_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def _get_as_list(mapping, key):
return names


def _difference(list1, list2):
return (
list1,
sorted(x for x in list1 if x not in list2),
sorted(x for x in list2 if x not in list1),
)


_kind_to_label = {
"mkdocs_plugin": "plugin",
"mkdocs_theme": "theme",
Expand Down Expand Up @@ -55,27 +63,39 @@ def check_install_project(project, install_name, errors=None):
pass
entry_points = {sect: list(entry_points[sect]) for sect in entry_points.sections()}

for item in _get_as_list(project, "mkdocs_plugin"):
if item not in entry_points.get("mkdocs.plugins", ()):
errors.append(f"Missing entry point [mkdocs.plugins] '{item}'.\nInstead got {entry_points}")

for item in _get_as_list(project, "mkdocs_theme"):
if item not in entry_points.get("mkdocs.themes", ()):
errors.append(f"Missing entry point [mkdocs.themes] '{item}'.\nInstead got {entry_points}")

for item in _get_as_list(project, "markdown_extension"):
if item not in entry_points.get("markdown.extensions", ()):
base_path = item.replace(".", "/")
for pattern in base_path + ".py", base_path + "/__init__.py":
path = Path(directory, pattern)
if path.is_file() and "makeExtension" in path.read_text():
break
else:
errors.append(
f"Missing entry point [markdown.extensions] '{item}'.\n"
f"Instead got {entry_points}.\n"
f"Also not found as a direct import."
)
actual, missing, extra = _difference(
_get_as_list(project, "mkdocs_plugin"), entry_points.get("mkdocs.plugins", ())
)
for item in missing:
errors.append(f"Missing entry point [mkdocs.plugins] '{item}'.\nInstead got {actual}")
if extra:
errors.append(f"*Note: the package also has extra mkdocs.plugins: {extra}")

actual, missing, extra = _difference(
_get_as_list(project, "mkdocs_theme"), entry_points.get("mkdocs.themes", ())
)
for item in missing:
errors.append(f"Missing entry point [mkdocs.themes] '{item}'.\nInstead got {actual}")
if extra:
errors.append(f"*Note: the package also has extra mkdocs.themes: {extra}")

actual, missing, extra = _difference(
_get_as_list(project, "markdown_extension"), entry_points.get("markdown.extensions", ())
)
for item in missing:
base_path = item.replace(".", "/")
for pattern in base_path + ".py", base_path + "/__init__.py":
path = Path(directory, pattern)
if path.is_file() and "makeExtension" in path.read_text():
break
else:
errors.append(
f"Missing entry point [markdown.extensions] '{item}'.\n"
f"Instead got {actual}.\n"
f"Also not found as a direct import."
)
if extra:
errors.append(f"*Note: the package also has extra markdown.extensions: {extra}")

return errors

Expand Down Expand Up @@ -149,7 +169,7 @@ def check_install_project(project, install_name, errors=None):
for project_name, fut in futures:
result = fut.result()
if result:
error_count += len(result)
error_count += sum(not error.startswith("*") for error in result)
print()
print(f"{project_name}:")
for error in result:
Expand Down

0 comments on commit dd9998a

Please sign in to comment.