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
a01cf3c2
Commit
a01cf3c2
authored
Dec 28, 2016
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merge proposals. Ref #866.
parents
a29c9a4d
1bd827ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
23 deletions
+5
-23
setuptools/depends.py
setuptools/depends.py
+5
-11
setuptools/tests/test_depends.py
setuptools/tests/test_depends.py
+0
-12
No files found.
setuptools/depends.py
View file @
a01cf3c2
...
...
@@ -5,6 +5,7 @@ import dis
from
distutils.version
import
StrictVersion
from
imp
import
PKG_DIRECTORY
,
PY_COMPILED
,
PY_SOURCE
,
PY_FROZEN
__all__
=
[
'Require'
,
'find_module'
,
'get_module_constant'
,
'extract_constant'
]
...
...
@@ -77,14 +78,6 @@ class Require:
return
self
.
version_ok
(
version
)
def
_iter_code
(
code
):
"""Yield '(op,arg)' pair for each operation in code object 'code'"""
return
(
(
op
.
opcode
,
op
.
arg
)
for
op
in
dis
.
Bytecode
(
code
)
)
def
find_module
(
module
,
paths
=
None
):
"""Just like 'imp.find_module()', but with package support"""
...
...
@@ -150,9 +143,8 @@ def extract_constant(code, symbol, default=-1):
only 'STORE_NAME' and 'STORE_GLOBAL' opcodes are checked, and 'symbol'
must be present in 'code.co_names'.
"""
if
symbol
not
in
code
.
co_names
:
# name's not there, can't possibly be an assigment
# name's not there, can't possibly be an assig
n
ment
return
None
name_idx
=
list
(
code
.
co_names
).
index
(
symbol
)
...
...
@@ -163,7 +155,9 @@ def extract_constant(code, symbol, default=-1):
const
=
default
for
op
,
arg
in
_iter_code
(
code
):
for
byte_code
in
dis
.
Bytecode
(
code
):
op
=
byte_code
.
opcode
arg
=
byte_code
.
arg
if
op
==
LOAD_CONST
:
const
=
code
.
co_consts
[
arg
]
...
...
setuptools/tests/test_depends.py
View file @
a01cf3c2
...
...
@@ -14,15 +14,3 @@ class TestGetModuleConstant:
val
=
depends
.
get_module_constant
(
mod_name
,
'value'
)
assert
val
==
'three, sir!'
assert
'setuptools.tests.mod_with_constant'
not
in
sys
.
modules
class
TestIterCode
:
def
test_empty
(
self
):
code
=
compile
(
''
,
'<string>'
,
mode
=
'exec'
)
expected
=
(
100
,
0
),
(
83
,
None
)
assert
tuple
(
depends
.
_iter_code
(
code
))
==
expected
def
test_constant
(
self
):
code
=
compile
(
'value = "three, sir!"'
,
'<string>'
,
mode
=
'exec'
)
expected
=
(
100
,
0
),
(
90
,
0
),
(
100
,
1
),
(
83
,
None
)
assert
tuple
(
depends
.
_iter_code
(
code
))
==
expected
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