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
57f3b022
Commit
57f3b022
authored
Feb 23, 2016
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite env builder routine to a simple function, _build_paths, using iterables and common recipes.
parent
37bea1da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
31 deletions
+46
-31
setuptools/msvc9_support.py
setuptools/msvc9_support.py
+46
-31
No files found.
setuptools/msvc9_support.py
View file @
57f3b022
...
...
@@ -7,6 +7,9 @@ try:
except
ImportError
:
pass
import
six
unpatched
=
dict
()
def
patch_for_specialized_compiler
():
...
...
@@ -323,37 +326,49 @@ def _query_vcvarsall(version, arch):
# Set Microsoft Visual Studio Team System Database
VsTDb = [os.path.join(reg.find_visual_studio(), r'
VSTSDB
\
Deploy
')]
# Return Environment Variables
env = dict(
include=[VCIncludes, OSIncludes],
lib=[VCLibraries, OSLibraries, FxTools],
libpath=[VCLibraries, FxTools],
path=[VCTools, VSTools, VsTDb, SdkTools, SdkSetup, FxTools],
return dict(
include=_build_paths('
include
', [VCIncludes, OSIncludes]),
lib=_build_paths('
lib
', [VCLibraries, OSLibraries, FxTools]),
libpath=_build_paths('
libpath
', [VCLibraries, FxTools]),
path=_build_paths('
path
', [VCTools, VSTools, VsTDb, SdkTools, SdkSetup, FxTools]),
)
def checkpath(path, varlist):
# Function that add valid paths in list in not already present
if os.path.isdir(path) and path not in varlist:
varlist.append(path)
for key in env.keys():
var = []
# Add valid paths
for val in env[key]:
for subval in val:
checkpath(subval, var)
# Add values from actual environment
try:
for val in os.environ[key].split('
;
'):
checkpath(val, var)
except KeyError:
pass
# Format paths to Environment Variable string
if var:
env[key] = '
;
'.join(var)
else:
msg = "%s environment variable is empty" % key.upper()
raise distutils.errors.DistutilsPlatformError(msg)
return env
def _build_paths(name, spec_path_lists):
"""
Given an environment variable name and specified paths,
return a pathsep-separated string of paths containing
unique, extant, directories from those paths and from
the environment variable. Raise an error if no paths
are resolved.
"""
# flatten spec_path_lists
spec_paths = itertools.chain.from_iterable(spec_path_lists)
env_paths = os.environ.get(name, '').split(os.pathsep)
paths = itertools.chain(spec_paths, env_paths)
extant_paths = list(filter(os.path.isdir, paths))
if not extant_paths:
msg = "%s environment variable is empty" % name.upper()
raise distutils.errors.DistutilsPlatformError(msg)
unique_paths = unique_everseen(extant_paths)
return os.pathsep.join(unique_paths)
# from Python docs
def unique_everseen(iterable, key=None):
"List unique elements, preserving order. Remember all elements ever seen."
# unique_everseen('
AAAABBBCCDAABBB
') --> A B C D
# unique_everseen('
ABBCcAD
', str.lower) --> A B C D
seen = set()
seen_add = seen.add
filterfalse = six.moves.filterfalse
if key is None:
for element in filterfalse(seen.__contains__, iterable):
seen_add(element)
yield element
else:
for element in iterable:
k = key(element)
if k not in seen:
seen_add(k)
yield element
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