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
a9eb9e73
Commit
a9eb9e73
authored
Jun 16, 2020
by
Ram Rachum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix exception causes all over the codebase
parent
30831426
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
51 additions
and
41 deletions
+51
-41
changelog.d/2199.misc.rst
changelog.d/2199.misc.rst
+1
-0
pkg_resources/__init__.py
pkg_resources/__init__.py
+9
-9
setuptools/archive_util.py
setuptools/archive_util.py
+2
-2
setuptools/command/easy_install.py
setuptools/command/easy_install.py
+9
-5
setuptools/command/egg_info.py
setuptools/command/egg_info.py
+2
-2
setuptools/command/rotate.py
setuptools/command/rotate.py
+2
-2
setuptools/config.py
setuptools/config.py
+3
-2
setuptools/dist.py
setuptools/dist.py
+21
-17
setuptools/installer.py
setuptools/installer.py
+1
-1
setuptools/msvc.py
setuptools/msvc.py
+1
-1
No files found.
changelog.d/2199.misc.rst
0 → 100644
View file @
a9eb9e73
Fix exception causes all over the codebase by using ``raise new_exception from old_exception``
\ No newline at end of file
pkg_resources/__init__.py
View file @
a9eb9e73
...
@@ -1378,7 +1378,7 @@ def evaluate_marker(text, extra=None):
...
@@ -1378,7 +1378,7 @@ def evaluate_marker(text, extra=None):
marker = packaging.markers.Marker(text)
marker = packaging.markers.Marker(text)
return marker.evaluate()
return marker.evaluate()
except packaging.markers.InvalidMarker as e:
except packaging.markers.InvalidMarker as e:
raise SyntaxError(e)
raise SyntaxError(e)
from e
class NullProvider:
class NullProvider:
...
@@ -2287,8 +2287,8 @@ def declare_namespace(packageName):
...
@@ -2287,8 +2287,8 @@ def declare_namespace(packageName):
__import__(parent)
__import__(parent)
try:
try:
path = sys.modules[parent].__path__
path = sys.modules[parent].__path__
except AttributeError:
except AttributeError
as e
:
raise TypeError("
Not
a
package
:
", parent)
raise TypeError("
Not
a
package
:
", parent)
from e
# Track what packages are namespaces, so when new path items are added,
# Track what packages are namespaces, so when new path items are added,
# they can be updated
# they can be updated
...
@@ -2468,7 +2468,7 @@ class EntryPoint:
...
@@ -2468,7 +2468,7 @@ class EntryPoint:
try:
try:
return functools.reduce(getattr, self.attrs, module)
return functools.reduce(getattr, self.attrs, module)
except AttributeError as exc:
except AttributeError as exc:
raise ImportError(str(exc))
raise ImportError(str(exc))
from exc
def require(self, env=None, installer=None):
def require(self, env=None, installer=None):
if self.extras and not self.dist:
if self.extras and not self.dist:
...
@@ -2688,14 +2688,14 @@ class Distribution:
...
@@ -2688,14 +2688,14 @@ class Distribution:
def
version
(
self
):
def
version
(
self
):
try
:
try
:
return
self
.
_version
return
self
.
_version
except
AttributeError
:
except
AttributeError
as
e
:
version
=
self
.
_get_version
()
version
=
self
.
_get_version
()
if
version
is
None
:
if
version
is
None
:
path
=
self
.
_get_metadata_path_for_display
(
self
.
PKG_INFO
)
path
=
self
.
_get_metadata_path_for_display
(
self
.
PKG_INFO
)
msg
=
(
msg
=
(
"Missing 'Version:' header and/or {} file at path: {}"
"Missing 'Version:' header and/or {} file at path: {}"
).
format
(
self
.
PKG_INFO
,
path
)
).
format
(
self
.
PKG_INFO
,
path
)
raise
ValueError
(
msg
,
self
)
raise
ValueError
(
msg
,
self
)
from
e
return
version
return
version
...
@@ -2748,10 +2748,10 @@ class Distribution:
...
@@ -2748,10 +2748,10 @@ class Distribution:
for
ext
in
extras
:
for
ext
in
extras
:
try
:
try
:
deps
.
extend
(
dm
[
safe_extra
(
ext
)])
deps
.
extend
(
dm
[
safe_extra
(
ext
)])
except
KeyError
:
except
KeyError
as
e
:
raise
UnknownExtra
(
raise
UnknownExtra
(
"%s has no such extra feature %r"
%
(
self
,
ext
)
"%s has no such extra feature %r"
%
(
self
,
ext
)
)
)
from
e
return
deps
return
deps
def
_get_metadata_path_for_display
(
self
,
name
):
def
_get_metadata_path_for_display
(
self
,
name
):
...
@@ -3109,7 +3109,7 @@ class Requirement(packaging.requirements.Requirement):
...
@@ -3109,7 +3109,7 @@ class Requirement(packaging.requirements.Requirement):
try:
try:
super(Requirement, self).__init__(requirement_string)
super(Requirement, self).__init__(requirement_string)
except packaging.requirements.InvalidRequirement as e:
except packaging.requirements.InvalidRequirement as e:
raise RequirementParseError(str(e))
raise RequirementParseError(str(e))
from e
self.unsafe_name = self.name
self.unsafe_name = self.name
project_name = safe_name(self.name)
project_name = safe_name(self.name)
self.project_name, self.key = project_name, project_name.lower()
self.project_name, self.key = project_name, project_name.lower()
...
...
setuptools/archive_util.py
View file @
a9eb9e73
...
@@ -134,10 +134,10 @@ def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
...
@@ -134,10 +134,10 @@ def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
"""
"""
try
:
try
:
tarobj
=
tarfile
.
open
(
filename
)
tarobj
=
tarfile
.
open
(
filename
)
except
tarfile
.
TarError
:
except
tarfile
.
TarError
as
e
:
raise
UnrecognizedFormat
(
raise
UnrecognizedFormat
(
"%s is not a compressed or uncompressed tar file"
%
(
filename
,)
"%s is not a compressed or uncompressed tar file"
%
(
filename
,)
)
)
from
e
with
contextlib
.
closing
(
tarobj
):
with
contextlib
.
closing
(
tarobj
):
# don't do any chowning!
# don't do any chowning!
tarobj
.
chown
=
lambda
*
args
:
None
tarobj
.
chown
=
lambda
*
args
:
None
...
...
setuptools/command/easy_install.py
View file @
a9eb9e73
...
@@ -356,8 +356,10 @@ class easy_install(Command):
...
@@ -356,8 +356,10 @@ class easy_install(Command):
self
.
optimize
=
int
(
self
.
optimize
)
self
.
optimize
=
int
(
self
.
optimize
)
if
not
(
0
<=
self
.
optimize
<=
2
):
if
not
(
0
<=
self
.
optimize
<=
2
):
raise
ValueError
raise
ValueError
except
ValueError
:
except
ValueError
as
e
:
raise
DistutilsOptionError
(
"--optimize must be 0, 1, or 2"
)
raise
DistutilsOptionError
(
"--optimize must be 0, 1, or 2"
)
from
e
if
self
.
editable
and
not
self
.
build_directory
:
if
self
.
editable
and
not
self
.
build_directory
:
raise
DistutilsArgError
(
raise
DistutilsArgError
(
...
@@ -765,9 +767,9 @@ class easy_install(Command):
...
@@ -765,9 +767,9 @@ class easy_install(Command):
[
requirement
],
self
.
local_index
,
self
.
easy_install
[
requirement
],
self
.
local_index
,
self
.
easy_install
)
)
except
DistributionNotFound
as
e
:
except
DistributionNotFound
as
e
:
raise
DistutilsError
(
str
(
e
))
raise
DistutilsError
(
str
(
e
))
from
e
except
VersionConflict
as
e
:
except
VersionConflict
as
e
:
raise
DistutilsError
(
e
.
report
())
raise
DistutilsError
(
e
.
report
())
from
e
if
self
.
always_copy
or
self
.
always_copy_from
:
if
self
.
always_copy
or
self
.
always_copy_from
:
# Force all the relevant distros to be copied or activated
# Force all the relevant distros to be copied or activated
for
dist
in
distros
:
for
dist
in
distros
:
...
@@ -1156,7 +1158,9 @@ class easy_install(Command):
...
@@ -1156,7 +1158,9 @@ class easy_install(Command):
try
:
try
:
run_setup
(
setup_script
,
args
)
run_setup
(
setup_script
,
args
)
except
SystemExit
as
v
:
except
SystemExit
as
v
:
raise
DistutilsError
(
"Setup script exited with %s"
%
(
v
.
args
[
0
],))
raise
DistutilsError
(
"Setup script exited with %s"
%
(
v
.
args
[
0
],)
)
from
v
def
build_and_install
(
self
,
setup_script
,
setup_base
):
def
build_and_install
(
self
,
setup_script
,
setup_base
):
args
=
[
'bdist_egg'
,
'--dist-dir'
]
args
=
[
'bdist_egg'
,
'--dist-dir'
]
...
...
setuptools/command/egg_info.py
View file @
a9eb9e73
...
@@ -208,11 +208,11 @@ class egg_info(InfoCommon, Command):
...
@@ -208,11 +208,11 @@ class egg_info(InfoCommon, Command):
list(
list(
parse_requirements(spec % (self.egg_name, self.egg_version))
parse_requirements(spec % (self.egg_name, self.egg_version))
)
)
except ValueError:
except ValueError
as e
:
raise distutils.errors.DistutilsOptionError(
raise distutils.errors.DistutilsOptionError(
"Invalid distribution name or version syntax: %s-%s" %
"Invalid distribution name or version syntax: %s-%s" %
(self.egg_name, self.egg_version)
(self.egg_name, self.egg_version)
)
)
from e
if self.egg_base is None:
if self.egg_base is None:
dirs = self.distribution.package_dir
dirs = self.distribution.package_dir
...
...
setuptools/command/rotate.py
View file @
a9eb9e73
...
@@ -36,8 +36,8 @@ class rotate(Command):
...
@@ -36,8 +36,8 @@ class rotate(Command):
raise
DistutilsOptionError
(
"Must specify number of files to keep"
)
raise
DistutilsOptionError
(
"Must specify number of files to keep"
)
try
:
try
:
self
.
keep
=
int
(
self
.
keep
)
self
.
keep
=
int
(
self
.
keep
)
except
ValueError
:
except
ValueError
as
e
:
raise
DistutilsOptionError
(
"--keep must be an integer"
)
raise
DistutilsOptionError
(
"--keep must be an integer"
)
from
e
if
isinstance
(
self
.
match
,
six
.
string_types
):
if
isinstance
(
self
.
match
,
six
.
string_types
):
self
.
match
=
[
self
.
match
=
[
convert_path
(
p
.
strip
())
for
p
in
self
.
match
.
split
(
','
)
convert_path
(
p
.
strip
())
for
p
in
self
.
match
.
split
(
','
)
...
...
setuptools/config.py
View file @
a9eb9e73
...
@@ -42,9 +42,10 @@ class StaticModule:
...
@@ -42,9 +42,10 @@ class StaticModule:
for
target
in
statement
.
targets
for
target
in
statement
.
targets
if
isinstance
(
target
,
ast
.
Name
)
and
target
.
id
==
attr
if
isinstance
(
target
,
ast
.
Name
)
and
target
.
id
==
attr
)
)
except
Exception
:
except
Exception
as
e
:
raise
AttributeError
(
raise
AttributeError
(
"{self.name} has no attribute {attr}"
.
format
(
**
locals
()))
"{self.name} has no attribute {attr}"
.
format
(
**
locals
())
)
from
e
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
...
...
setuptools/dist.py
View file @
a9eb9e73
...
@@ -204,11 +204,11 @@ def check_importable(dist, attr, value):
...
@@ -204,11 +204,11 @@ def check_importable(dist, attr, value):
try
:
try
:
ep
=
pkg_resources
.
EntryPoint
.
parse
(
'x='
+
value
)
ep
=
pkg_resources
.
EntryPoint
.
parse
(
'x='
+
value
)
assert
not
ep
.
extras
assert
not
ep
.
extras
except
(
TypeError
,
ValueError
,
AttributeError
,
AssertionError
):
except
(
TypeError
,
ValueError
,
AttributeError
,
AssertionError
)
as
e
:
raise
DistutilsSetupError
(
raise
DistutilsSetupError
(
"%r must be importable 'module:attrs' string (got %r)"
"%r must be importable 'module:attrs' string (got %r)"
%
(
attr
,
value
)
%
(
attr
,
value
)
)
)
from
e
def
assert_string_list
(
dist
,
attr
,
value
):
def
assert_string_list
(
dist
,
attr
,
value
):
...
@@ -219,10 +219,10 @@ def assert_string_list(dist, attr, value):
...
@@ -219,10 +219,10 @@ def assert_string_list(dist, attr, value):
assert
isinstance
(
value
,
(
list
,
tuple
))
assert
isinstance
(
value
,
(
list
,
tuple
))
# verify that elements of value are strings
# verify that elements of value are strings
assert
''
.
join
(
value
)
!=
value
assert
''
.
join
(
value
)
!=
value
except
(
TypeError
,
ValueError
,
AttributeError
,
AssertionError
):
except
(
TypeError
,
ValueError
,
AttributeError
,
AssertionError
)
as
e
:
raise
DistutilsSetupError
(
raise
DistutilsSetupError
(
"%r must be a list of strings (got %r)"
%
(
attr
,
value
)
"%r must be a list of strings (got %r)"
%
(
attr
,
value
)
)
)
from
e
def
check_nsp
(
dist
,
attr
,
value
):
def
check_nsp
(
dist
,
attr
,
value
):
...
@@ -247,12 +247,12 @@ def check_extras(dist, attr, value):
...
@@ -247,12 +247,12 @@ def check_extras(dist, attr, value):
"""Verify that extras_require mapping is valid"""
"""Verify that extras_require mapping is valid"""
try
:
try
:
list
(
itertools
.
starmap
(
_check_extra
,
value
.
items
()))
list
(
itertools
.
starmap
(
_check_extra
,
value
.
items
()))
except
(
TypeError
,
ValueError
,
AttributeError
):
except
(
TypeError
,
ValueError
,
AttributeError
)
as
e
:
raise
DistutilsSetupError
(
raise
DistutilsSetupError
(
"'extras_require' must be a dictionary whose values are "
"'extras_require' must be a dictionary whose values are "
"strings or lists of strings containing valid project/version "
"strings or lists of strings containing valid project/version "
"requirement specifiers."
"requirement specifiers."
)
)
from
e
def
_check_extra
(
extra
,
reqs
):
def
_check_extra
(
extra
,
reqs
):
...
@@ -280,7 +280,9 @@ def check_requirements(dist, attr, value):
...
@@ -280,7 +280,9 @@ def check_requirements(dist, attr, value):
"{attr!r} must be a string or list of strings "
"{attr!r} must be a string or list of strings "
"containing valid project/version requirement specifiers; {error}"
"containing valid project/version requirement specifiers; {error}"
)
)
raise
DistutilsSetupError
(
tmpl
.
format
(
attr
=
attr
,
error
=
error
))
raise
DistutilsSetupError
(
tmpl
.
format
(
attr
=
attr
,
error
=
error
)
)
from
error
def
check_specifier
(
dist
,
attr
,
value
):
def
check_specifier
(
dist
,
attr
,
value
):
...
@@ -292,7 +294,9 @@ def check_specifier(dist, attr, value):
...
@@ -292,7 +294,9 @@ def check_specifier(dist, attr, value):
"{attr!r} must be a string "
"{attr!r} must be a string "
"containing valid version specifiers; {error}"
"containing valid version specifiers; {error}"
)
)
raise
DistutilsSetupError
(
tmpl
.
format
(
attr
=
attr
,
error
=
error
))
raise
DistutilsSetupError
(
tmpl
.
format
(
attr
=
attr
,
error
=
error
)
)
from
error
def
check_entry_points
(
dist
,
attr
,
value
):
def
check_entry_points
(
dist
,
attr
,
value
):
...
@@ -300,7 +304,7 @@ def check_entry_points(dist, attr, value):
...
@@ -300,7 +304,7 @@ def check_entry_points(dist, attr, value):
try
:
try
:
pkg_resources
.
EntryPoint
.
parse_map
(
value
)
pkg_resources
.
EntryPoint
.
parse_map
(
value
)
except
ValueError
as
e
:
except
ValueError
as
e
:
raise
DistutilsSetupError
(
e
)
raise
DistutilsSetupError
(
e
)
from
e
def
check_test_suite
(
dist
,
attr
,
value
):
def
check_test_suite
(
dist
,
attr
,
value
):
...
@@ -609,8 +613,8 @@ class Distribution(_Distribution):
...
@@ -609,8 +613,8 @@ class Distribution(_Distribution):
setattr
(
self
,
opt
,
strtobool
(
val
))
setattr
(
self
,
opt
,
strtobool
(
val
))
else
:
else
:
setattr
(
self
,
opt
,
val
)
setattr
(
self
,
opt
,
val
)
except
ValueError
as
msg
:
except
ValueError
as
e
:
raise
DistutilsOptionError
(
msg
)
raise
DistutilsOptionError
(
e
)
from
e
@
staticmethod
@
staticmethod
def
_try_str
(
val
):
def
_try_str
(
val
):
...
@@ -676,8 +680,8 @@ class Distribution(_Distribution):
...
@@ -676,8 +680,8 @@ class Distribution(_Distribution):
raise
DistutilsOptionError
(
raise
DistutilsOptionError
(
"error in %s: command '%s' has no such option '%s'"
"error in %s: command '%s' has no such option '%s'"
%
(
source
,
command_name
,
option
))
%
(
source
,
command_name
,
option
))
except
ValueError
as
msg
:
except
ValueError
as
e
:
raise
DistutilsOptionError
(
msg
)
raise
DistutilsOptionError
(
e
)
from
e
def
parse_config_files
(
self
,
filenames
=
None
,
ignore_option_errors
=
False
):
def
parse_config_files
(
self
,
filenames
=
None
,
ignore_option_errors
=
False
):
"""Parses configuration files from various levels
"""Parses configuration files from various levels
...
@@ -843,10 +847,10 @@ class Distribution(_Distribution):
...
@@ -843,10 +847,10 @@ class Distribution(_Distribution):
)
)
try
:
try
:
old
=
getattr
(
self
,
name
)
old
=
getattr
(
self
,
name
)
except
AttributeError
:
except
AttributeError
as
e
:
raise
DistutilsSetupError
(
raise
DistutilsSetupError
(
"%s: No such distribution setting"
%
name
"%s: No such distribution setting"
%
name
)
)
from
e
if
old
is
not
None
and
not
isinstance
(
old
,
sequence
):
if
old
is
not
None
and
not
isinstance
(
old
,
sequence
):
raise
DistutilsSetupError
(
raise
DistutilsSetupError
(
name
+
": this setting cannot be changed via include/exclude"
name
+
": this setting cannot be changed via include/exclude"
...
@@ -863,10 +867,10 @@ class Distribution(_Distribution):
...
@@ -863,10 +867,10 @@ class Distribution(_Distribution):
)
)
try
:
try
:
old
=
getattr
(
self
,
name
)
old
=
getattr
(
self
,
name
)
except
AttributeError
:
except
AttributeError
as
e
:
raise
DistutilsSetupError
(
raise
DistutilsSetupError
(
"%s: No such distribution setting"
%
name
"%s: No such distribution setting"
%
name
)
)
from
e
if
old
is
None
:
if
old
is
None
:
setattr
(
self
,
name
,
value
)
setattr
(
self
,
name
,
value
)
elif
not
isinstance
(
old
,
sequence
):
elif
not
isinstance
(
old
,
sequence
):
...
...
setuptools/installer.py
View file @
a9eb9e73
...
@@ -127,7 +127,7 @@ def fetch_build_egg(dist, req):
...
@@ -127,7 +127,7 @@ def fetch_build_egg(dist, req):
try
:
try
:
subprocess
.
check_call
(
cmd
)
subprocess
.
check_call
(
cmd
)
except
subprocess
.
CalledProcessError
as
e
:
except
subprocess
.
CalledProcessError
as
e
:
raise
DistutilsError
(
str
(
e
))
raise
DistutilsError
(
str
(
e
))
from
e
wheel
=
Wheel
(
glob
.
glob
(
os
.
path
.
join
(
tmpdir
,
'*.whl'
))[
0
])
wheel
=
Wheel
(
glob
.
glob
(
os
.
path
.
join
(
tmpdir
,
'*.whl'
))[
0
])
dist_location
=
os
.
path
.
join
(
eggs_dir
,
wheel
.
egg_name
())
dist_location
=
os
.
path
.
join
(
eggs_dir
,
wheel
.
egg_name
())
wheel
.
install_as_egg
(
dist_location
)
wheel
.
install_as_egg
(
dist_location
)
...
...
setuptools/msvc.py
View file @
a9eb9e73
...
@@ -277,7 +277,7 @@ def _msvc14_get_vc_env(plat_spec):
...
@@ -277,7 +277,7 @@ def _msvc14_get_vc_env(plat_spec):
except
subprocess
.
CalledProcessError
as
exc
:
except
subprocess
.
CalledProcessError
as
exc
:
raise
distutils
.
errors
.
DistutilsPlatformError
(
raise
distutils
.
errors
.
DistutilsPlatformError
(
"Error executing {}"
.
format
(
exc
.
cmd
)
"Error executing {}"
.
format
(
exc
.
cmd
)
)
)
from
exc
env
=
{
env
=
{
key
.
lower
():
value
key
.
lower
():
value
...
...
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