Skip to content
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
22 changes: 19 additions & 3 deletions src/py2app/bootstrap/setup_included_subpackages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import sys
import types

from importlib._bootstrap import _exec, _load
from importlib import machinery, util

_path_hooks: "list[str]"


Expand All @@ -19,9 +22,22 @@ def load_module(self, fullname: str) -> types.ModuleType:
pkg_dir = os.path.join(
os.environ["RESOURCEPATH"], "lib", "python%d.%d" % (sys.version_info[:2])
)
return imp.load_module(
fullname, None, os.path.join(pkg_dir, fullname), ("", "", imp.PKG_DIRECTORY)
)
path = os.path.join(pkg_dir, fullname)
if os.path.isdir(path):
extensions = (machinery.SOURCE_SUFFIXES[:] +
machinery.BYTECODE_SUFFIXES[:])
for extension in extensions:
init_path = os.path.join(path, '__init__' + extension)
if os.path.exists(init_path):
path = init_path
break
else:
raise ValueError('{!r} is not a package'.format(path))
spec = util.spec_from_file_location(fullname, path, submodule_search_locations=[])
if fullname in sys.modules:
return _exec(spec, sys.modules[fullname])
else:
return _load(spec)


class Finder:
Expand Down
6 changes: 2 additions & 4 deletions src/py2app/build_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# mypy: ignore-errors

import collections
import imp
import importlib.machinery
import io
import itertools
import os
Expand Down Expand Up @@ -1769,9 +1769,7 @@ def copy_package_data(
This is a bit of a hack, it would be better to identify python eggs
and copy those in whole.
"""
exts = [i[0] for i in imp.get_suffixes()]
exts.append(".py")
exts.append(".pyc")
exts = importlib.machinery.all_suffixes()
exts.append(".pyo")

def datafilter(item: str) -> bool:
Expand Down
7 changes: 3 additions & 4 deletions src/py2app/recipes/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
good model for other recipes!!!
"""

import imp
import os
import sys
import typing
Expand Down Expand Up @@ -50,7 +49,7 @@ def fmod(
]:
if path is None:
if name in sys.builtin_module_names:
return (None, None, ("", "", imp.C_BUILTIN))
return (None, None, ("", "", 6)) # imp.C_BUILTIN

path = mf.path

Expand All @@ -66,9 +65,9 @@ def fmod(
except ImportError:
return None

if stuff[-1] == imp.PKG_DIRECTORY:
if stuff[-1] == 5: # imp.PKG_DIRECTORY
m.__class__ = Package
elif stuff[-1] == imp.PY_SOURCE:
elif stuff[-1] == 1: # imp.PY_SOURCE
m.__class__ = SourceModule
else:
m.__class__ = CompiledModule
Expand Down
7 changes: 6 additions & 1 deletion src/py2app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import typing
from py_compile import compile # noqa: A004

from importlib._bootstrap import _load
import importlib.machinery

import macholib.util
from macholib.util import is_platform_file
from modulegraph import zipio
Expand Down Expand Up @@ -317,7 +320,9 @@ def __load():
continue
ext_path = os.path.join(path, ext)
if os.path.exists(ext_path):
mod = imp.load_dynamic(__name__, ext_path)
loader = importlib.machinery.ExtensionFileLoader(__name__, ext_path)
spec = importlib.machinery.ModuleSpec(name=__name__, loader=loader, origin=ext_path)
mod = _load(spec)
break
else:
raise ImportError(repr(ext) + " not found")
Expand Down