Commit d2067f70 authored by Michael Droettboom's avatar Michael Droettboom

Fix handling of bytecode files

parent ff5b9e61
......@@ -8,12 +8,13 @@ source:
patches:
- patches/named-tmp-and-rm-dup2.patch
- patches/workaround_get_tag.patch
requirements:
run:
- atomicwrites
- attrs
- more-itertools
- more-itertools
- pluggy
- py
- setuptools
......
diff -ur pytest-3.6.3-bak/src/_pytest/assertion/rewrite.py pytest-3.6.3/src/_pytest/assertion/rewrite.py
--- pytest-3.6.3-bak/src/_pytest/assertion/rewrite.py 2018-11-08 14:58:43.984236991 -0500
+++ pytest-3.6.3/src/_pytest/assertion/rewrite.py 2018-11-08 14:59:59.881455735 -0500
@@ -19,7 +19,7 @@
# pytest caches rewritten pycs in __pycache__.
-if hasattr(imp, "get_tag"):
+if hasattr(imp, "get_tag") and imp.get_tag() is not None:
PYTEST_TAG = imp.get_tag() + "-PYTEST"
else:
if hasattr(sys, "pypy_version_info"):
......@@ -133,7 +133,7 @@ def package_files(buildpath, srcpath, pkg, args):
'--js-output={}'.format(name + '.js'),
'--export-name=pyodide._module',
'--exclude', '*.wasm.pre',
'--exclude', '__pycache__',
'--exclude', '*__pycache__*',
'--use-preload-plugins'],
cwd=buildpath, check=True)
subprocess.run([
......
......@@ -41,11 +41,40 @@ main(int argc, char** argv)
{
hiwire_setup();
setenv("PYTHONDONTWRITEBYTECODE", "1", 0);
setenv("PYTHONHOME", "/", 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)) {
Py_DECREF(sys);
return 1;
}
// By disabling the cache_tag, Python won't look for cached bytecode files when
// importing modules, which saves on filesystem I/O time
PyObject *implementation = PyObject_GetAttrString(sys, "implementation");
if (implementation == NULL) {
Py_DECREF(sys);
return 1;
}
if (PyObject_SetAttrString(implementation, "cache_tag", Py_None)) {
Py_DECREF(implementation);
Py_DECREF(sys);
return 1;
}
Py_DECREF(implementation);
Py_DECREF(sys);
if (js2python_init() || JsImport_init() || JsProxy_init() ||
pyimport_init() || pyproxy_init() || python2js_init() ||
runpython_init_js() || runpython_init_py() || runpython_finalize_js()) {
......
......@@ -49,10 +49,42 @@ def test_import(name, selenium_standalone):
'{} fails to load and is not supported on {}.'
.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', []):
selenium_standalone.load_package(name)
try:
selenium_standalone.run('import %s' % import_name)
except Exception as e:
print(selenium_standalone.logs)
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