Files
nuitka-mirror/tests/standalone/PkgutilIterModulesUsing.py
Kay Hayen 0c66d03327 Optimization: Added hard import node for "pkgutil.iter_modules"
* Replace compiled-package "pkgutil.iter_modules" calls with a loader
  helper that enumerates package children directly and falls back to
  "pkgutil" for regular paths.

* Keep internal loader modules out of the "sys.path" hook, and add
  standalone coverage for package child enumeration.
2026-11-22 11:53:40 +01:00

44 lines
1.4 KiB
Python

# Copyright 2026, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
# nuitka-project: --mode=standalone
# nuitka-project: --python-flag=isolated
# nuitka-project: --include-package=pkgutil_iter_modules_package
import pkgutil
import pkgutil_iter_modules_package
path = iter(pkgutil_iter_modules_package.__path__)
prefix = pkgutil_iter_modules_package.__name__ + "."
names = sorted(
name
for _finder, name, is_package in pkgutil.iter_modules(path, prefix)
if not is_package
)
print(names)
assert names == [
"pkgutil_iter_modules_package.first_child",
"pkgutil_iter_modules_package.second_child",
]
# Python test originally created or extracted from other peoples work. The
# parts from me are licensed as below. It is at least Free Software where
# it's copied from other people. In these cases, that will normally be
# indicated.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.