-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the freezing function from genscript.py to a new module freeze_s…
…upport.py
- Loading branch information
1 parent
bba09f8
commit 05aba8b
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Provides a function to report all internal modules for using freezing tools | ||
pytest | ||
""" | ||
|
||
def pytest_namespace(): | ||
return {'freeze_includes': freeze_includes} | ||
|
||
|
||
def freeze_includes(): | ||
""" | ||
Returns a list of module names used by py.test that should be | ||
included by cx_freeze. | ||
""" | ||
import py | ||
import _pytest | ||
result = list(_iter_all_modules(py)) | ||
result += list(_iter_all_modules(_pytest)) | ||
return result | ||
|
||
|
||
def _iter_all_modules(package, prefix=''): | ||
""" | ||
Iterates over the names of all modules that can be found in the given | ||
package, recursively. | ||
Example: | ||
_iter_all_modules(_pytest) -> | ||
['_pytest.assertion.newinterpret', | ||
'_pytest.capture', | ||
'_pytest.core', | ||
... | ||
] | ||
""" | ||
import os | ||
import pkgutil | ||
if type(package) is not str: | ||
path, prefix = package.__path__[0], package.__name__ + '.' | ||
else: | ||
path = package | ||
for _, name, is_package in pkgutil.iter_modules([path]): | ||
if is_package: | ||
for m in _iter_all_modules(os.path.join(path, name), prefix=name + '.'): | ||
yield prefix + m | ||
else: | ||
yield prefix + name |