Commit 1287eebd authored by Michael Droettboom's avatar Michael Droettboom Committed by GitHub

Merge pull request #249 from mdboom/bytecode

Improve handling of bytecode files
parents 14a52f00 f0ff58e7
...@@ -13,7 +13,7 @@ requirements: ...@@ -13,7 +13,7 @@ requirements:
run: run:
- atomicwrites - atomicwrites
- attrs - attrs
- more-itertools - more-itertools
- pluggy - pluggy
- py - py
- setuptools - setuptools
......
...@@ -133,7 +133,7 @@ def package_files(buildpath, srcpath, pkg, args): ...@@ -133,7 +133,7 @@ def package_files(buildpath, srcpath, pkg, args):
'--js-output={}'.format(name + '.js'), '--js-output={}'.format(name + '.js'),
'--export-name=pyodide._module', '--export-name=pyodide._module',
'--exclude', '*.wasm.pre', '--exclude', '*.wasm.pre',
'--exclude', '__pycache__', '--exclude', '*__pycache__*',
'--use-preload-plugins'], '--use-preload-plugins'],
cwd=buildpath, check=True) cwd=buildpath, check=True)
subprocess.run([ subprocess.run([
......
...@@ -41,11 +41,24 @@ main(int argc, char** argv) ...@@ -41,11 +41,24 @@ main(int argc, char** argv)
{ {
hiwire_setup(); hiwire_setup();
setenv("PYTHONDONTWRITEBYTECODE", "1", 0);
setenv("PYTHONHOME", "/", 0); setenv("PYTHONHOME", "/", 0);
Py_InitializeEx(0); Py_InitializeEx(0);
// This doesn't seem to work anymore, but I'm keeping it for good measure
// anyway The effective way to turn this off is below: setting
// sys.done_write_bytecode = True
setenv("PYTHONDONTWRITEBYTECODE", "1", 0);
PyObject* sys = PyImport_ImportModule("sys");
if (sys == NULL) {
return 1;
}
if (PyObject_SetAttrString(sys, "dont_write_bytecode", Py_True)) {
return 1;
}
Py_DECREF(sys);
if (js2python_init() || JsImport_init() || JsProxy_init() || if (js2python_init() || JsImport_init() || JsProxy_init() ||
pyimport_init() || pyproxy_init() || python2js_init() || pyimport_init() || pyproxy_init() || python2js_init() ||
runpython_init_js() || runpython_init_py() || runpython_finalize_js()) { runpython_init_js() || runpython_init_py() || runpython_finalize_js()) {
......
...@@ -49,10 +49,43 @@ def test_import(name, selenium_standalone): ...@@ -49,10 +49,43 @@ def test_import(name, selenium_standalone):
'{} fails to load and is not supported on {}.' '{} fails to load and is not supported on {}.'
.format(name, selenium_standalone.browser)) .format(name, selenium_standalone.browser))
selenium_standalone.run("import glob, os")
baseline_pyc = selenium_standalone.run(
"""
len(list(glob.glob(
'/lib/python3.7/site-packages/**/*.pyc',
recursive=True)
))
"""
)
selenium_standalone.load_package(name)
# Make sure there are no additional .pyc file
assert selenium_standalone.run(
"""
len(list(glob.glob(
'/lib/python3.7/site-packages/**/*.pyc',
recursive=True)
))
"""
) == baseline_pyc
for import_name in meta.get('test', {}).get('imports', []): for import_name in meta.get('test', {}).get('imports', []):
selenium_standalone.load_package(name)
try: try:
selenium_standalone.run('import %s' % import_name) selenium_standalone.run('import %s' % import_name)
except Exception as e: except Exception as e:
print(selenium_standalone.logs) print(selenium_standalone.logs)
raise raise
# Make sure that even after importing, there are no additional .pyc
# files
assert selenium_standalone.run(
"""
len(list(glob.glob(
'/lib/python3.7/site-packages/**/*.pyc',
recursive=True)
))
"""
) == baseline_pyc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment