Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
1410d87f
Commit
1410d87f
authored
Oct 04, 2019
by
isidentical
Committed by
Batuhan Taskaya
Oct 13, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade setuptools.depends to importlib from depracated imp
parent
cb64d3a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
14 deletions
+76
-14
setuptools/depends.py
setuptools/depends.py
+75
-14
setuptools/tests/test_integration.py
setuptools/tests/test_integration.py
+1
-0
No files found.
setuptools/depends.py
View file @
1410d87f
import
sys
import
imp
import
marshal
from
distutils.version
import
StrictVersion
from
imp
import
PKG_DIRECTORY
,
PY_COMPILED
,
PY_SOURCE
,
PY_FROZEN
from
setuptools.extern
import
six
from
.py33compat
import
Bytecode
if
six
.
PY2
:
import
imp
from
imp
import
PKG_DIRECTORY
,
PY_COMPILED
,
PY_SOURCE
,
PY_FROZEN
else
:
import
os.path
from
importlib.util
import
find_spec
,
spec_from_loader
from
importlib.machinery
import
SOURCE_SUFFIXES
,
BYTECODE_SUFFIXES
,
EXTENSION_SUFFIXES
,
BuiltinImporter
,
FrozenImporter
PY_SOURCE
=
1
PY_COMPILED
=
2
C_EXTENSION
=
3
C_BUILTIN
=
6
PY_FROZEN
=
7
__all__
=
[
'Require'
,
'find_module'
,
'get_module_constant'
,
'extract_constant'
...
...
@@ -81,21 +93,59 @@ class Require:
def
find_module
(
module
,
paths
=
None
):
"""Just like 'imp.find_module()', but with package support"""
if
six
.
PY3
:
spec
=
find_spec
(
module
,
paths
)
if
spec
is
None
:
raise
ImportError
(
"Can't find %s"
%
module
)
if
not
spec
.
has_location
and
hasattr
(
spec
,
'submodule_search_locations'
):
spec
=
spec_from_loader
(
'__init__.py'
,
spec
.
loader
)
kind
=
-
1
file
=
None
static
=
isinstance
(
spec
.
loader
,
type
)
if
spec
.
origin
==
'frozen'
or
static
and
issubclass
(
spec
.
loader
,
FrozenImporter
):
kind
=
PY_FROZEN
path
=
None
# imp compabilty
suffix
=
mode
=
''
# imp compability
elif
spec
.
origin
==
'built-in'
or
static
and
issubclass
(
spec
.
loader
,
BuiltinImporter
):
kind
=
C_BUILTIN
path
=
None
# imp compabilty
suffix
=
mode
=
''
# imp compability
elif
spec
.
has_location
:
frozen
=
False
path
=
spec
.
origin
suffix
=
os
.
path
.
splitext
(
path
)[
1
]
mode
=
'r'
if
suffix
in
SOURCE_SUFFIXES
else
'rb'
if
suffix
in
SOURCE_SUFFIXES
:
kind
=
PY_SOURCE
elif
suffix
in
BYTECODE_SUFFIXES
:
kind
=
PY_COMPILED
elif
suffix
in
EXTENSION_SUFFIXES
:
kind
=
C_EXTENSION
if
kind
in
{
PY_SOURCE
,
PY_COMPILED
}:
file
=
open
(
path
,
mode
)
else
:
path
=
None
suffix
=
mode
=
''
parts
=
module
.
split
(
'.'
)
return
file
,
path
,
(
suffix
,
mode
,
kind
)
while
parts
:
part
=
parts
.
pop
(
0
)
f
,
path
,
(
suffix
,
mode
,
kind
)
=
info
=
imp
.
find_module
(
part
,
paths
)
else
:
parts
=
module
.
split
(
'.'
)
while
parts
:
part
=
parts
.
pop
(
0
)
f
,
path
,
(
suffix
,
mode
,
kind
)
=
info
=
imp
.
find_module
(
part
,
paths
)
if
kind
==
PKG_DIRECTORY
:
parts
=
parts
or
[
'__init__'
]
paths
=
[
path
]
if
kind
==
PKG_DIRECTORY
:
parts
=
parts
or
[
'__init__'
]
paths
=
[
path
]
elif
parts
:
raise
ImportError
(
"Can't find %r in %s"
%
(
parts
,
module
))
elif
parts
:
raise
ImportError
(
"Can't find %r in %s"
%
(
parts
,
module
))
return
info
return
info
def
get_module_constant
(
module
,
symbol
,
default
=-
1
,
paths
=
None
):
...
...
@@ -111,18 +161,29 @@ def get_module_constant(module, symbol, default=-1, paths=None):
# Module doesn't exist
return
None
if
six
.
PY3
:
spec
=
find_spec
(
module
,
paths
)
if
hasattr
(
spec
,
'submodule_search_locations'
):
spec
=
spec_from_loader
(
'__init__.py'
,
spec
.
loader
)
try
:
if
kind
==
PY_COMPILED
:
f
.
read
(
8
)
# skip magic & date
code
=
marshal
.
load
(
f
)
elif
kind
==
PY_FROZEN
:
code
=
imp
.
get_frozen_object
(
module
)
if
six
.
PY2
:
code
=
imp
.
get_frozen_object
(
module
)
else
:
code
=
spec
.
loader
.
get_code
(
module
)
elif
kind
==
PY_SOURCE
:
code
=
compile
(
f
.
read
(),
path
,
'exec'
)
else
:
# Not something we can parse; we'll have to import it. :(
if
module
not
in
sys
.
modules
:
imp
.
load_module
(
module
,
f
,
path
,
(
suffix
,
mode
,
kind
))
if
six
.
PY2
:
imp
.
load_module
(
module
,
f
,
path
,
(
suffix
,
mode
,
kind
))
else
:
sys
.
modules
[
module
]
=
module_from_spec
(
spec
)
return
getattr
(
sys
.
modules
[
module
],
symbol
,
None
)
finally
:
...
...
setuptools/tests/test_integration.py
View file @
1410d87f
...
...
@@ -143,6 +143,7 @@ def test_build_deps_on_distutils(request, tmpdir_factory, build_dep):
'tests_require'
,
'python_requires'
,
'install_requires'
,
'long_description_content_type'
,
]
assert
not
match
or
match
.
group
(
1
).
strip
(
'"
\
'
'
)
in
allowed_unknowns
...
...
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