mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Don't create .json files when getting paths
This commit is contained in:
+18
-34
@@ -342,9 +342,8 @@ class Environment:
|
||||
pylib_lines = []
|
||||
pyinc_lines = []
|
||||
py_command = (
|
||||
"import sysconfig, distutils.sysconfig, io, json, sys; paths = {{"
|
||||
"%s }}; value = u'{{0}}'.format(json.dumps(paths));"
|
||||
"fh = io.open('{0}', 'w'); fh.write(value); fh.close()"
|
||||
"import sysconfig, distutils.sysconfig, io, json, sys; paths = {"
|
||||
"%s }; value = u'{0}'.format(json.dumps(paths)); print(value)"
|
||||
)
|
||||
distutils_line = "distutils.sysconfig.get_python_{0}(plat_specific={1})"
|
||||
sysconfig_line = "sysconfig.get_path('{0}')"
|
||||
@@ -354,24 +353,24 @@ class Environment:
|
||||
# XXX: We need to get 'stdlib' or 'platstdlib'
|
||||
sys_prefix = "{}stdlib".format("" if key == "pure" else key)
|
||||
pylib_lines.append(
|
||||
f"u'{dist_prefix}': u'{{{{0}}}}'.format({distutils_line.format(var, val)})"
|
||||
f"u'{dist_prefix}': u'{{0}}'.format({distutils_line.format(var, val)})"
|
||||
)
|
||||
pylib_lines.append(
|
||||
f"u'{sys_prefix}': u'{{{{0}}}}'.format({sysconfig_line.format(sys_prefix)})"
|
||||
f"u'{sys_prefix}': u'{{0}}'.format({sysconfig_line.format(sys_prefix)})"
|
||||
)
|
||||
if python_inc:
|
||||
for key, var, val in (("include", "inc", "0"), ("platinclude", "inc", "1")):
|
||||
pylib_lines.append(
|
||||
f"u'{key}': u'{{{{0}}}}'.format({distutils_line.format(var, val)})"
|
||||
f"u'{key}': u'{{0}}'.format({distutils_line.format(var, val)})"
|
||||
)
|
||||
lines = pylib_lines + pyinc_lines
|
||||
if scripts:
|
||||
lines.append(
|
||||
"u'scripts': u'{{0}}'.format(%s)" % sysconfig_line.format("scripts")
|
||||
"u'scripts': u'{0}'.format(%s)" % sysconfig_line.format("scripts")
|
||||
)
|
||||
if py_version:
|
||||
lines.append(
|
||||
"u'py_version_short': u'{{0}}'.format(distutils.sysconfig.get_python_version()),"
|
||||
"u'py_version_short': u'{0}'.format(distutils.sysconfig.get_python_version()),"
|
||||
)
|
||||
lines_as_str = ",".join(lines)
|
||||
py_command = py_command % lines_as_str
|
||||
@@ -384,18 +383,13 @@ class Environment:
|
||||
:return: The python paths for the environment
|
||||
:rtype: Dict[str, str]
|
||||
"""
|
||||
tmpfile = vistir.path.create_tracked_tempfile(suffix=".json")
|
||||
tmpfile.close()
|
||||
tmpfile_path = make_posix(tmpfile.name)
|
||||
py_command = self.build_command(
|
||||
python_lib=True, python_inc=True, scripts=True, py_version=True
|
||||
)
|
||||
command = [self.python, "-c", py_command.format(tmpfile_path)]
|
||||
command = [self.python, "-c", py_command]
|
||||
c = subprocess_run(command)
|
||||
if c.returncode == 0:
|
||||
paths = {}
|
||||
with open(tmpfile_path, "r", encoding="utf-8") as fh:
|
||||
paths = json.load(fh)
|
||||
paths = json.loads(c.stdout)
|
||||
if "purelib" in paths:
|
||||
paths["libdir"] = paths["purelib"] = make_posix(paths["purelib"])
|
||||
for key in (
|
||||
@@ -420,17 +414,12 @@ class Environment:
|
||||
:return: The python include path for the environment
|
||||
:rtype: Dict[str, str]
|
||||
"""
|
||||
tmpfile = vistir.path.create_tracked_tempfile(suffix=".json")
|
||||
tmpfile.close()
|
||||
tmpfile_path = make_posix(tmpfile.name)
|
||||
py_command = self.build_command(python_lib=True)
|
||||
command = [self.python, "-c", py_command.format(tmpfile_path)]
|
||||
command = [self.python, "-c", py_command]
|
||||
c = subprocess_run(command)
|
||||
paths = None
|
||||
if c.returncode == 0:
|
||||
paths = {}
|
||||
with open(tmpfile_path, "r", encoding="utf-8") as fh:
|
||||
paths = json.load(fh)
|
||||
paths = json.loads(c.stdout)
|
||||
if "purelib" in paths:
|
||||
paths["libdir"] = paths["purelib"] = make_posix(paths["purelib"])
|
||||
for key in ("platlib", "platstdlib", "stdlib"):
|
||||
@@ -476,22 +465,17 @@ class Environment:
|
||||
:return: The python include path for the environment
|
||||
:rtype: Dict[str, str]
|
||||
"""
|
||||
tmpfile = vistir.path.create_tracked_tempfile(suffix=".json")
|
||||
tmpfile.close()
|
||||
tmpfile_path = make_posix(tmpfile.name)
|
||||
py_command = (
|
||||
"import distutils.sysconfig, io, json, sys; paths = {{u'include': "
|
||||
"u'{{0}}'.format(distutils.sysconfig.get_python_inc(plat_specific=0)), "
|
||||
"u'platinclude': u'{{0}}'.format(distutils.sysconfig.get_python_inc("
|
||||
"plat_specific=1)) }}; value = u'{{0}}'.format(json.dumps(paths));"
|
||||
"fh = io.open('{0}', 'w'); fh.write(value); fh.close()"
|
||||
"import distutils.sysconfig, io, json, sys; paths = {u'include': "
|
||||
"u'{0}'.format(distutils.sysconfig.get_python_inc(plat_specific=0)), "
|
||||
"u'platinclude': u'{0}'.format(distutils.sysconfig.get_python_inc("
|
||||
"plat_specific=1)) }; value = u'{0}'.format(json.dumps(paths));"
|
||||
"print(value)"
|
||||
)
|
||||
command = [self.python, "-c", py_command.format(tmpfile_path)]
|
||||
command = [self.python, "-c", py_command]
|
||||
c = subprocess_run(command)
|
||||
if c.returncode == 0:
|
||||
paths = []
|
||||
with open(tmpfile_path, "r", encoding="utf-8") as fh:
|
||||
paths = json.load(fh)
|
||||
paths = json.loads(c.stdout)
|
||||
for key in ("include", "platinclude"):
|
||||
if key in paths:
|
||||
paths[key] = make_posix(paths[key])
|
||||
|
||||
Reference in New Issue
Block a user