Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
91b65a3b
Commit
91b65a3b
authored
Sep 10, 2016
by
Kevin Modzelewski
Committed by
GitHub
Sep 10, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1357 from kmod/unmodified_venv
Be able to run an unmodified virtualenv
parents
3a41df7f
de4d0a39
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
65 additions
and
56 deletions
+65
-56
from_cpython/Lib/compileall.py
from_cpython/Lib/compileall.py
+4
-1
from_cpython/Lib/distutils/core.py
from_cpython/Lib/distutils/core.py
+4
-0
from_cpython/Lib/py_compile.py
from_cpython/Lib/py_compile.py
+8
-30
from_cpython/Lib/test/test_py_compile.py
from_cpython/Lib/test/test_py_compile.py
+0
-1
from_cpython/Lib/test/test_sundry.py
from_cpython/Lib/test/test_sundry.py
+0
-1
from_cpython/Python/import.c
from_cpython/Python/import.c
+5
-5
src/codegen/parser.cpp
src/codegen/parser.cpp
+2
-1
src/codegen/parser.h
src/codegen/parser.h
+3
-1
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+1
-1
src/runtime/builtin_modules/pyston.cpp
src/runtime/builtin_modules/pyston.cpp
+16
-0
src/runtime/builtin_modules/sys.cpp
src/runtime/builtin_modules/sys.cpp
+6
-3
test/CPYTHON_TEST_NOTES.md
test/CPYTHON_TEST_NOTES.md
+1
-3
test/extra/numpy_fulltest.py
test/extra/numpy_fulltest.py
+4
-0
test/integration/virtualenv_test.py
test/integration/virtualenv_test.py
+10
-8
test/lib/virtualenv
test/lib/virtualenv
+1
-1
No files found.
from_cpython/Lib/compileall.py
View file @
91b65a3b
...
...
@@ -82,6 +82,8 @@ def compile_file(fullname, ddir=None, force=0, rx=None, quiet=0):
if
os
.
path
.
isfile
(
fullname
):
head
,
tail
=
name
[:
-
3
],
name
[
-
3
:]
if
tail
==
'.py'
:
# Pyston change: leave this to the parser
'''
if not force:
try:
mtime = int(os.stat(fullname).st_mtime)
...
...
@@ -93,10 +95,11 @@ def compile_file(fullname, ddir=None, force=0, rx=None, quiet=0):
return success
except IOError:
pass
'''
if
not
quiet
:
print
'Compiling'
,
fullname
,
'...'
try
:
ok
=
py_compile
.
compile
(
fullname
,
None
,
dfile
,
True
)
ok
=
py_compile
.
compile
(
fullname
,
None
,
dfile
,
True
,
force
=
force
)
except
py_compile
.
PyCompileError
,
err
:
if
quiet
:
print
'Compiling'
,
fullname
,
'...'
...
...
from_cpython/Lib/distutils/core.py
View file @
91b65a3b
...
...
@@ -100,6 +100,10 @@ def setup(**attrs):
else
:
klass
=
Distribution
# Pyston change:
if
"zip_safe"
not
in
attrs
:
attrs
[
'zip_safe'
]
=
False
if
'script_name'
not
in
attrs
:
attrs
[
'script_name'
]
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
if
'script_args'
not
in
attrs
:
...
...
from_cpython/Lib/py_compile.py
View file @
91b65a3b
...
...
@@ -3,15 +3,10 @@
This module has intimate knowledge of the format of .pyc files.
"""
import
__builtin__
import
imp
import
marshal
import
os
import
__pyston__
import
sys
import
traceback
MAGIC
=
imp
.
get_magic
()
__all__
=
[
"compile"
,
"main"
,
"PyCompileError"
]
...
...
@@ -61,14 +56,7 @@ class PyCompileError(Exception):
return
self
.
msg
def
wr_long
(
f
,
x
):
"""Internal; write a 32-bit int to a file in little-endian order."""
f
.
write
(
chr
(
x
&
0xff
))
f
.
write
(
chr
((
x
>>
8
)
&
0xff
))
f
.
write
(
chr
((
x
>>
16
)
&
0xff
))
f
.
write
(
chr
((
x
>>
24
)
&
0xff
))
def
compile
(
file
,
cfile
=
None
,
dfile
=
None
,
doraise
=
False
):
def
compile
(
file
,
cfile
=
None
,
dfile
=
None
,
doraise
=
False
,
force
=
False
):
"""Byte-compile one Python source file to Python bytecode.
Arguments:
...
...
@@ -103,14 +91,13 @@ def compile(file, cfile=None, dfile=None, doraise=False):
directories).
"""
with
open
(
file
,
'U'
)
as
f
:
try
:
timestamp
=
long
(
os
.
fstat
(
f
.
fileno
()).
st_mtime
)
except
AttributeError
:
timestamp
=
long
(
os
.
stat
(
file
).
st_mtime
)
codestring
=
f
.
read
()
# Pyston restrictions for things that we don't yet support
assert
cfile
is
None
or
cfile
==
file
+
"c"
assert
dfile
is
None
or
dfile
==
file
try
:
codeobject
=
__builtin__
.
compile
(
codestring
,
dfile
or
file
,
'exec'
)
__pyston__
.
py_compile
(
file
,
force
)
except
Exception
,
err
:
py_exc
=
PyCompileError
(
err
.
__class__
,
err
,
dfile
or
file
)
if
doraise
:
...
...
@@ -118,15 +105,6 @@ def compile(file, cfile=None, dfile=None, doraise=False):
else
:
sys
.
stderr
.
write
(
py_exc
.
msg
+
'
\
n
'
)
return
if
cfile
is
None
:
cfile
=
file
+
(
__debug__
and
'c'
or
'o'
)
with
open
(
cfile
,
'wb'
)
as
fc
:
fc
.
write
(
'
\
0
\
0
\
0
\
0
'
)
wr_long
(
fc
,
timestamp
)
marshal
.
dump
(
codeobject
,
fc
)
fc
.
flush
()
fc
.
seek
(
0
,
0
)
fc
.
write
(
MAGIC
)
def
main
(
args
=
None
):
"""Compile several source files.
...
...
from_cpython/Lib/test/test_py_compile.py
View file @
91b65a3b
# expected: fail
import
imp
import
os
import
py_compile
...
...
from_cpython/Lib/test/test_sundry.py
View file @
91b65a3b
# expected: fail
"""Do a minimal test of all the modules that aren't otherwise tested."""
from
test
import
test_support
...
...
from_cpython/Python/import.c
View file @
91b65a3b
...
...
@@ -2949,15 +2949,13 @@ PyImport_Import(PyObject *module_name)
importing modules.
*/
// Pyston change: we don't support get_magic
#if 0
static PyObject *
imp_get_magic(PyObject *self, PyObject *noargs)
{
char buf[4];
// Pyston change: we have different pyc
assert
(
0
);
abort
();
buf[0] = (char) ((pyc_magic >> 0) & 0xff);
buf[1] = (char) ((pyc_magic >> 8) & 0xff);
buf[2] = (char) ((pyc_magic >> 16) & 0xff);
...
...
@@ -2965,6 +2963,7 @@ imp_get_magic(PyObject *self, PyObject *noargs)
return PyString_FromStringAndSize(buf, 4);
}
#endif
static
PyObject
*
imp_get_suffixes
(
PyObject
*
self
,
PyObject
*
noargs
)
...
...
@@ -3330,7 +3329,8 @@ On platforms without threads, this function does nothing.");
static
PyMethodDef
imp_methods
[]
=
{
{
"reload"
,
imp_reload
,
METH_O
,
doc_reload
},
{
"find_module"
,
imp_find_module
,
METH_VARARGS
,
doc_find_module
},
{
"get_magic"
,
imp_get_magic
,
METH_NOARGS
,
doc_get_magic
},
// Pyston change: we don't support this function
// {"get_magic", imp_get_magic, METH_NOARGS, doc_get_magic},
{
"get_suffixes"
,
imp_get_suffixes
,
METH_NOARGS
,
doc_get_suffixes
},
{
"load_module"
,
imp_load_module
,
METH_VARARGS
,
doc_load_module
},
{
"new_module"
,
imp_new_module
,
METH_VARARGS
,
doc_new_module
},
...
...
src/codegen/parser.cpp
View file @
91b65a3b
...
...
@@ -1104,7 +1104,8 @@ static std::vector<char> _reparse(const char* fn, const std::string& cache_fn, A
// Parsing the file is somewhat expensive since we have to shell out to cpython;
// it's not a huge deal right now, but this caching version can significantly cut down
// on the startup time (40ms -> 10ms).
std
::
pair
<
AST_Module
*
,
std
::
unique_ptr
<
ASTAllocator
>>
caching_parse_file
(
const
char
*
fn
,
FutureFlags
inherited_flags
)
{
std
::
pair
<
AST_Module
*
,
std
::
unique_ptr
<
ASTAllocator
>>
caching_parse_file
(
const
char
*
fn
,
FutureFlags
inherited_flags
,
bool
force_reparse
)
{
std
::
ostringstream
oss
;
UNAVOIDABLE_STAT_TIMER
(
t0
,
"us_timer_caching_parse_file"
);
...
...
src/codegen/parser.h
View file @
91b65a3b
...
...
@@ -15,6 +15,7 @@
#ifndef PYSTON_CODEGEN_PARSER_H
#define PYSTON_CODEGEN_PARSER_H
#include "core/ast.h"
#include "core/types.h"
namespace
pyston
{
...
...
@@ -24,7 +25,8 @@ class ASTAllocator;
std
::
pair
<
AST_Module
*
,
std
::
unique_ptr
<
ASTAllocator
>>
parse_string
(
const
char
*
code
,
FutureFlags
inherited_flags
);
std
::
pair
<
AST_Module
*
,
std
::
unique_ptr
<
ASTAllocator
>>
parse_file
(
const
char
*
fn
,
FutureFlags
inherited_flags
);
std
::
pair
<
AST_Module
*
,
std
::
unique_ptr
<
ASTAllocator
>>
caching_parse_file
(
const
char
*
fn
,
FutureFlags
inherited_flags
);
std
::
pair
<
AST_Module
*
,
std
::
unique_ptr
<
ASTAllocator
>>
caching_parse_file
(
const
char
*
fn
,
FutureFlags
inherited_flags
,
bool
force_reparse
=
false
);
}
#endif
src/runtime/builtin_modules/builtins.cpp
View file @
91b65a3b
...
...
@@ -2388,7 +2388,7 @@ void setupBuiltins() {
builtins_module
->
giveAttrBorrowed
(
"Ellipsis"
,
Ellipsis
);
builtins_module
->
giveAttrBorrowed
(
"None"
,
Py_None
);
builtins_module
->
giveAttrBorrowed
(
"__debug__"
,
Py_
Fals
e
);
builtins_module
->
giveAttrBorrowed
(
"__debug__"
,
Py_
Tru
e
);
notimplemented_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
Box
),
false
,
"NotImplementedType"
,
false
,
NULL
,
NULL
,
false
);
...
...
src/runtime/builtin_modules/pyston.cpp
View file @
91b65a3b
...
...
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "codegen/parser.h"
#include "core/types.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
...
...
@@ -63,6 +64,18 @@ static Box* dumpStats(Box* includeZeros) {
Py_RETURN_NONE
;
}
static
Box
*
pyCompile
(
Box
*
fname
,
Box
*
force
)
{
if
(
fname
->
cls
!=
str_cls
)
raiseExcHelper
(
TypeError
,
"py_compile takes a string for the filename"
);
if
(
force
->
cls
!=
bool_cls
)
raiseExcHelper
(
TypeError
,
"py_compile takes a bool for 'force' argument"
);
caching_parse_file
(
static_cast
<
BoxedString
*>
(
fname
)
->
c_str
(),
/* future flags */
0
,
force
==
Py_True
);
Py_RETURN_NONE
;
}
void
setupPyston
()
{
pyston_module
=
createModule
(
autoDecref
(
boxString
(
"__pyston__"
)));
...
...
@@ -74,5 +87,8 @@ void setupPyston() {
pyston_module
->
giveAttr
(
"dumpStats"
,
new
BoxedBuiltinFunctionOrMethod
(
BoxedCode
::
create
((
void
*
)
dumpStats
,
NONE
,
1
,
false
,
false
,
"dumpStats"
),
{
Py_False
}));
pyston_module
->
giveAttr
(
"py_compile"
,
new
BoxedBuiltinFunctionOrMethod
(
BoxedCode
::
create
((
void
*
)
pyCompile
,
UNKNOWN
,
2
,
"pyCompile"
)));
}
}
src/runtime/builtin_modules/sys.cpp
View file @
91b65a3b
...
...
@@ -44,7 +44,11 @@ int Py_DivisionWarningFlag = 0;
int
Py_HashRandomizationFlag
=
0
;
int
Py_DebugFlag
=
0
;
int
_Py_QnewFlag
=
0
;
int
Py_DontWriteBytecodeFlag
=
0
;
// Pyston change: set this by default to True
// We can support many cases of users wanting to write bytecode, but there are some
// that are much harder to support (py.test wants to write its own pyc files), and
// this flag is one of the few levers we have to avoid hitting those paths.
int
Py_DontWriteBytecodeFlag
=
1
;
int
Py_NoUserSiteDirectory
=
0
;
}
...
...
@@ -847,8 +851,7 @@ void setupSys() {
new
BoxedBuiltinFunctionOrMethod
(
BoxedCode
::
create
(
(
void
*
)
sysGetRecursionLimit
,
UNKNOWN
,
0
,
"getrecursionlimit"
,
getrecursionlimit_doc
)));
// As we don't support compile() etc yet force 'dont_write_bytecode' to true.
sys_module
->
giveAttrBorrowed
(
"dont_write_bytecode"
,
Py_True
);
sys_module
->
giveAttr
(
"dont_write_bytecode"
,
boxBool
(
Py_DontWriteBytecodeFlag
));
sys_module
->
giveAttr
(
"prefix"
,
boxString
(
Py_GetPrefix
()));
sys_module
->
giveAttr
(
"exec_prefix"
,
boxString
(
Py_GetExecPrefix
()));
...
...
test/CPYTHON_TEST_NOTES.md
View file @
91b65a3b
...
...
@@ -50,7 +50,7 @@ test_codeop [unknown]
test_code [unknown]
test_coding works when run from inside the from_cpython dir
test_coercion 1**1L, divmod(1, 1L); some unknown bug
test_compileall
[unknown]
test_compileall
Not sure if this test makes sense for us (wants to check the details of pyc files)
test_compiler [unknown]
test_compile [unknown]
test_cprofile [unknown]
...
...
@@ -129,7 +129,6 @@ test_pprint [unknown]
test_profile [unknown]
test_py3kwarn [unknown]
test_pyclbr This test passes but takes a very long time in debug mode (60s vs 5s for release mode).
test_py_compile [unknown]
test_pydoc [unknown]
test_random long("invalid number")
test_repr complex.__hash__; some unknown issues
...
...
@@ -145,7 +144,6 @@ test_structmembers [unknown]
test_subprocess exit code 141 [sigpipe?], no error message
test_sunaudiodev [unknown]
test_sunau [unknown]
test_sundry [unknown]
test_support [unknown]
test_symtable [unknown]
test_syntax [unknown]
...
...
test/extra/numpy_fulltest.py
View file @
91b65a3b
...
...
@@ -42,6 +42,7 @@ if not os.path.exists(CYTHON_DIR):
subprocess
.
check_call
([
PYTHON_EXE
,
"-c"
,
"import Cython"
],
cwd
=
CYTHON_DIR
)
except
:
subprocess
.
check_call
([
"rm"
,
"-rf"
,
CYTHON_DIR
])
raise
else
:
print
">>> Cython already installed."
...
...
@@ -62,6 +63,9 @@ try:
# but they end up naming f2py "f2py_release"/"f2py_dbg"
print_progress_header
(
"Setting up NumPy..."
)
os
.
environ
[
"CC"
]
=
"ccache gcc"
print
"
\
n
doing 'build'
\
n
"
subprocess
.
check_call
([
PYTHON_EXE
,
"setup.py"
,
"build"
],
cwd
=
NUMPY_DIR
,
env
=
env
)
print_progress_header
(
"Installing NumPy..."
)
...
...
test/integration/virtualenv_test.py
View file @
91b65a3b
...
...
@@ -5,19 +5,21 @@ import shutil
VIRTUALENV_SCRIPT
=
os
.
path
.
dirname
(
__file__
)
+
"/../lib/virtualenv/virtualenv.py"
if
os
.
path
.
exists
(
"test_env"
):
print
"Removing the existing 'test_env/' directory"
subprocess
.
check_call
([
"rm"
,
"-rf"
,
"test_env"
])
ENV_NAME
=
"test_env_"
+
os
.
path
.
basename
(
sys
.
executable
)
if
os
.
path
.
exists
(
ENV_NAME
):
print
"Removing the existing '%s/' directory"
%
ENV_NAME
subprocess
.
check_call
([
"rm"
,
"-rf"
,
ENV_NAME
])
# shutil follows symlinks to directories, and deletes whatever those contain.
# shutil.rmtree(
"test_env"
)
# shutil.rmtree(
ENV_NAME
)
args
=
[
sys
.
executable
,
VIRTUALENV_SCRIPT
,
"-p"
,
sys
.
executable
,
"test_env"
]
args
=
[
sys
.
executable
,
VIRTUALENV_SCRIPT
,
"-p"
,
sys
.
executable
,
ENV_NAME
]
print
"Running"
,
args
subprocess
.
check_call
(
args
)
sh_script
=
"""
sh_script
=
(
"""
set -e
.
test_env
/bin/activate
.
%s
/bin/activate
set -ux
python -c 'import __future__'
python -c 'import sys; print sys.executable'
...
...
@@ -36,7 +38,7 @@ python -c 'import sqlalchemy; print "sqlalchemy imports"'
python -c 'from PIL import Image; print "Pillow imports"'
python -c 'import decorator; print "decorator imports"'
python -c 'import oauth2client; print "oauth2client imports"'
"""
.
strip
()
"""
%
ENV_NAME
)
.
strip
()
# print sh_script
subprocess
.
check_call
([
"sh"
,
"-c"
,
sh_script
],
stdout
=
sys
.
stderr
)
...
...
virtualenv
@
b112626d
Subproject commit
db70fc5084483b636b4bbf05519f4d69a2c741fa
Subproject commit
b112626df31a8788c7986c0bc7c2b470ac36ff49
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment