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

Generate run time hook to monkeypatch entry_points #116

Merged
merged 1 commit into from
Sep 29, 2023
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ tmpenv
whl
package
kolibrisrc
hooks/kolibri_plugins_entrypoints_hook.py
44 changes: 43 additions & 1 deletion kolibri.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import sys

from datetime import datetime
from glob import glob
from importlib.metadata import entry_points


block_cipher = None
Expand All @@ -24,14 +25,55 @@ locale_datas = [
for mo_file in glob('src/kolibri_app/locales/**/LC_MESSAGES/*.mo')
]

entry_point_packages = dict()

# List of packages that should have there Distutils entrypoints included.
ep_packages = ["kolibri.plugins"]

for ep_package in ep_packages:
packages = []
for ep in entry_points(group=ep_package):
packages.append((ep.name, ep.value, ep.group))
if packages:
entry_point_packages[ep_package] = packages

try:
os.mkdir('./generated')
except FileExistsError:
pass

with open("./hooks/kolibri_plugins_entrypoints_hook.py", "w") as f:
f.write("""# Runtime hook generated from spec file to support importlib.metadata entry_points.
from importlib import metadata

ep_packages = {}

default_entry_points = metadata.entry_points

def _generate_entry_points_object_for_group(group):
return metadata.EntryPoints(metadata.EntryPoint(*ep) for ep in ep_packages[group])

def monkey_patched_entry_points(**params):
value = default_entry_points(**params)
group = params.get("group")
if group is not None and group in ep_packages:
value[group] = _generate_entry_points_object_for_group(group)
if not params:
for group in ep_packages:
value[group] = _generate_entry_points_object_for_group(group)
return value

metadata.entry_points = monkey_patched_entry_points
""".format(entry_point_packages))

a = Analysis(
[os.path.join('src', 'kolibri_app', '__main__.py')],
pathex=['kolibrisrc', os.path.join('kolibrisrc', 'kolibri', 'dist')],
binaries=[],
datas=[('src/kolibri_app/assets', 'kolibri_app/assets')] + locale_datas,
hiddenimports=[],
hookspath=['hooks'],
runtime_hooks=['hooks/pyi_rth_kolibri.py'],
runtime_hooks=['hooks/pyi_rth_kolibri.py', 'hooks/kolibri_plugins_entrypoints_hook.py'],
excludes=['numpy', 'six.moves.urllib.parse', 'PIL'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
Expand Down
Loading