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
233ec44d
Commit
233ec44d
authored
Dec 09, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'import a.b' results in a module called 'a.b'
Previously we were calling it just 'b'.
parent
faa290b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
13 deletions
+36
-13
src/runtime/import.cpp
src/runtime/import.cpp
+14
-13
test/tests/package_import.py
test/tests/package_import.py
+22
-0
No files found.
src/runtime/import.cpp
View file @
233ec44d
...
...
@@ -64,7 +64,8 @@ static bool pathExists(const std::string& path) {
return
exists
;
}
static
BoxedModule
*
importPackageFromDirectory
(
const
std
::
string
&
name
,
const
std
::
string
&
path
)
{
static
BoxedModule
*
importPackageFromDirectory
(
const
std
::
string
&
name
,
const
std
::
string
&
full_name
,
const
std
::
string
&
path
)
{
llvm
::
SmallString
<
128
>
joined_path
;
llvm
::
sys
::
path
::
append
(
joined_path
,
path
,
name
);
...
...
@@ -83,10 +84,10 @@ static BoxedModule* importPackageFromDirectory(const std::string& name, const st
printf
(
"Importing %s from %s
\n
"
,
name
.
c_str
(),
fn
.
c_str
());
return
createAndRunModule
(
name
,
fn
,
dn
);
return
createAndRunModule
(
full_
name
,
fn
,
dn
);
}
static
BoxedModule
*
importFile
(
const
std
::
string
&
name
,
const
std
::
string
&
path
)
{
static
BoxedModule
*
importFile
(
const
std
::
string
&
name
,
const
std
::
string
&
full_name
,
const
std
::
string
&
path
)
{
llvm
::
SmallString
<
128
>
joined_path
;
llvm
::
sys
::
path
::
append
(
joined_path
,
path
,
name
+
".py"
);
...
...
@@ -101,10 +102,10 @@ static BoxedModule* importFile(const std::string& name, const std::string& path)
if
(
VERBOSITY
()
>=
1
)
printf
(
"Importing %s from %s
\n
"
,
name
.
c_str
(),
fn
.
c_str
());
return
createAndRunModule
(
name
,
fn
);
return
createAndRunModule
(
full_
name
,
fn
);
}
static
Box
*
importSub
(
const
std
::
string
*
name
,
Box
*
parent_module
)
{
static
Box
*
importSub
(
const
std
::
string
&
name
,
const
std
::
string
&
full_
name
,
Box
*
parent_module
)
{
BoxedList
*
path_list
;
if
(
parent_module
==
NULL
)
{
path_list
=
getSysPath
();
...
...
@@ -114,7 +115,7 @@ static Box* importSub(const std::string* name, Box* parent_module) {
}
else
{
path_list
=
static_cast
<
BoxedList
*>
(
parent_module
->
getattr
(
"__path__"
,
NULL
));
if
(
path_list
==
NULL
||
path_list
->
cls
!=
list_cls
)
{
raiseExcHelper
(
ImportError
,
"No module named %s"
,
name
->
c_str
());
raiseExcHelper
(
ImportError
,
"No module named %s"
,
name
.
c_str
());
}
}
...
...
@@ -131,25 +132,25 @@ static Box* importSub(const std::string* name, Box* parent_module) {
BoxedModule
*
module
;
module
=
importPackageFromDirectory
(
*
name
,
dn
);
module
=
importPackageFromDirectory
(
name
,
full_
name
,
dn
);
if
(
!
module
)
module
=
importFile
(
*
name
,
dn
);
module
=
importFile
(
name
,
full_
name
,
dn
);
if
(
module
)
{
if
(
parent_module
)
parent_module
->
setattr
(
*
name
,
module
,
NULL
);
parent_module
->
setattr
(
name
,
module
,
NULL
);
return
module
;
}
}
if
(
*
name
==
"basic_test"
)
{
if
(
name
==
"basic_test"
)
{
return
importTestExtension
(
"basic_test"
);
}
if
(
*
name
==
"descr_test"
)
{
if
(
name
==
"descr_test"
)
{
return
importTestExtension
(
"descr_test"
);
}
raiseExcHelper
(
ImportError
,
"No module named %s"
,
name
->
c_str
());
raiseExcHelper
(
ImportError
,
"No module named %s"
,
name
.
c_str
());
}
static
Box
*
import
(
const
std
::
string
*
name
,
bool
return_first
)
{
...
...
@@ -176,7 +177,7 @@ static Box* import(const std::string* name, bool return_first) {
last_module
=
sys_modules
->
d
[
s
];
}
else
{
std
::
string
small_name
=
std
::
string
(
*
name
,
l
,
r
-
l
);
last_module
=
importSub
(
&
small
_name
,
last_module
);
last_module
=
importSub
(
small_name
,
prefix
_name
,
last_module
);
}
if
(
l
==
0
)
{
...
...
test/tests/package_import.py
View file @
233ec44d
...
...
@@ -2,3 +2,25 @@ import distutils
import
distutils.log
print
type
(
distutils
)
print
type
(
distutils
.
log
)
import
sys
print
distutils
.
log
==
sys
.
modules
[
'distutils.log'
]
print
'log'
in
sys
.
modules
print
distutils
.
log
.
__name__
# should be "distutils.log"
try
:
import
distutils.doesnt_exist
except
ImportError
,
e
:
# CPython prints: "No module named doesnt_exist"
# PyPy prints: "No module named distutils.doesnt_exist"
# We print "No module named doesnt_exist"
print
e
try
:
import
distutils7.doesnt_exist
except
ImportError
,
e
:
# CPython prints: "No module named distutils7.doesnt_exist"
# PyPy prints: "No module named distutils7"
# We print: "No module named distutils7"
# print e
print
"(Caught import error)"
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