@@ -36,9 +36,12 @@ script = """\
36
36
from sysconfig import *
37
37
import numpy
38
38
import json
39
+ import site
39
40
vars = get_config_vars()
40
41
vars["plat"] = get_platform()
41
42
vars["numpy_include"] = numpy.get_include()
43
+ vars["site_packages"] = site.getsitepackages()
44
+ vars["user_site_packages"] = site.getusersitepackages()
42
45
print(json.dumps(vars))
43
46
"""
44
47
info = json .loads (get_command_output (localenv ["python_cmd" ], "-c" , script ))
@@ -50,6 +53,8 @@ py_version_short = parse_version(info["py_version_short"])
50
53
py_version_full = parse_version (info ["py_version" ])
51
54
py_version_nodot = info ["py_version_nodot" ]
52
55
numpy_include = info ["numpy_include" ]
56
+ site_packages = info ["site_packages" ]
57
+ user_site_packages = info ["user_site_packages" ]
53
58
localenv .Prepend (CPPPATH = [Dir ('#include' ), inc , numpy_include ])
54
59
localenv .Prepend (LIBS = localenv ['cantera_libs' ])
55
60
@@ -137,6 +142,27 @@ elif not env["default_prefix"]:
137
142
install_cmd .append (f"--prefix={ env ['prefix' ]} " )
138
143
python_prefix = env ["prefix" ]
139
144
145
+ # Check for existing Python module installation. Allow pip to remove an existing
146
+ # installation only if we're installing to the same location. Also disable
147
+ # uninstallation if we're installing to a staging directory.
148
+ if env ["stage_dir" ]:
149
+ install_cmd .append ("--ignore-installed" )
150
+ else :
151
+ info = get_command_output (localenv ["python_cmd" ], "-m" , "pip" , "show" , "cantera" ,
152
+ ignore_errors = True )
153
+
154
+ if user_install :
155
+ test_prefix = Path (user_site_packages ).parents [2 ]
156
+ elif python_prefix is None :
157
+ test_prefix = Path (site_packages [0 ]).parents [2 ]
158
+ else :
159
+ test_prefix = Path (python_prefix )
160
+
161
+ match = re .search (r"Location: (.*)\n" , info , re .MULTILINE )
162
+ existing_prefix = Path (match .group (1 )).parents [2 ] if match else None
163
+ if existing_prefix and existing_prefix != test_prefix :
164
+ install_cmd .append ("--ignore-installed" )
165
+
140
166
if env ["stage_dir" ]:
141
167
# Get the absolute path to the stage directory. If the stage directory is a relative
142
168
# path, consider it to be relative to the root of the Cantera source directory.
0 commit comments