[3.7] bpo-34977: Use venv redirector instead of original python.exe o… · python/cpython@b264c60 (original) (raw)

`@@ -9,6 +9,7 @@

`

9

9

`import shutil

`

10

10

`import subprocess

`

11

11

`import sys

`

``

12

`+

import sysconfig

`

12

13

`import types

`

13

14

``

14

15

`logger = logging.getLogger(name)

`

`@@ -63,10 +64,11 @@ def create(self, env_dir):

`

63

64

`self.system_site_packages = False

`

64

65

`self.create_configuration(context)

`

65

66

`self.setup_python(context)

`

``

67

`+

if not self.upgrade:

`

``

68

`+

self.setup_scripts(context)

`

66

69

`if self.with_pip:

`

67

70

`self._setup_pip(context)

`

68

71

`if not self.upgrade:

`

69

``

`-

self.setup_scripts(context)

`

70

72

`self.post_setup(context)

`

71

73

`if true_system_site_packages:

`

72

74

`# We had set it to False before, now

`

`@@ -157,14 +159,6 @@ def create_configuration(self, context):

`

157

159

`f.write('include-system-site-packages = %s\n' % incl)

`

158

160

`f.write('version = %d.%d.%d\n' % sys.version_info[:3])

`

159

161

``

160

``

`-

if os.name == 'nt':

`

161

``

`-

def include_binary(self, f):

`

162

``

`-

if f.endswith(('.pyd', '.dll')):

`

163

``

`-

result = True

`

164

``

`-

else:

`

165

``

`-

result = f.startswith('python') and f.endswith('.exe')

`

166

``

`-

return result

`

167

``

-

168

162

`def symlink_or_copy(self, src, dst, relative_symlinks_ok=False):

`

169

163

`"""

`

170

164

` Try symlinking a file, and if that fails, fall back to copying.

`

`@@ -194,9 +188,9 @@ def setup_python(self, context):

`

194

188

`binpath = context.bin_path

`

195

189

`path = context.env_exe

`

196

190

`copier = self.symlink_or_copy

`

197

``

`-

copier(context.executable, path)

`

198

191

`dirname = context.python_dir

`

199

192

`if os.name != 'nt':

`

``

193

`+

copier(context.executable, path)

`

200

194

`if not os.path.islink(path):

`

201

195

`os.chmod(path, 0o755)

`

202

196

`for suffix in ('python', 'python3'):

`

`@@ -208,32 +202,33 @@ def setup_python(self, context):

`

208

202

`if not os.path.islink(path):

`

209

203

`os.chmod(path, 0o755)

`

210

204

`else:

`

211

``

`-

subdir = 'DLLs'

`

212

``

`-

include = self.include_binary

`

213

``

`-

files = [f for f in os.listdir(dirname) if include(f)]

`

214

``

`-

for f in files:

`

215

``

`-

src = os.path.join(dirname, f)

`

216

``

`-

dst = os.path.join(binpath, f)

`

217

``

`-

if dst != context.env_exe: # already done, above

`

218

``

`-

copier(src, dst)

`

219

``

`-

dirname = os.path.join(dirname, subdir)

`

220

``

`-

if os.path.isdir(dirname):

`

221

``

`-

files = [f for f in os.listdir(dirname) if include(f)]

`

222

``

`-

for f in files:

`

223

``

`-

src = os.path.join(dirname, f)

`

224

``

`-

dst = os.path.join(binpath, f)

`

225

``

`-

copier(src, dst)

`

226

``

`-

copy init.tcl over

`

227

``

`-

for root, dirs, files in os.walk(context.python_dir):

`

228

``

`-

if 'init.tcl' in files:

`

229

``

`-

tcldir = os.path.basename(root)

`

230

``

`-

tcldir = os.path.join(context.env_dir, 'Lib', tcldir)

`

231

``

`-

if not os.path.exists(tcldir):

`

232

``

`-

os.makedirs(tcldir)

`

233

``

`-

src = os.path.join(root, 'init.tcl')

`

234

``

`-

dst = os.path.join(tcldir, 'init.tcl')

`

235

``

`-

shutil.copyfile(src, dst)

`

236

``

`-

break

`

``

205

`+

For normal cases, the venvlauncher will be copied from

`

``

206

`+

our scripts folder. For builds, we need to copy it

`

``

207

`+

manually.

`

``

208

`+

if sysconfig.is_python_build(True):

`

``

209

`+

suffix = '.exe'

`

``

210

`+

if context.python_exe.lower().endswith('_d.exe'):

`

``

211

`+

suffix = '_d.exe'

`

``

212

+

``

213

`+

src = os.path.join(dirname, "venvlauncher" + suffix)

`

``

214

`+

dst = os.path.join(binpath, context.python_exe)

`

``

215

`+

copier(src, dst)

`

``

216

+

``

217

`+

src = os.path.join(dirname, "venvwlauncher" + suffix)

`

``

218

`+

dst = os.path.join(binpath, "pythonw" + suffix)

`

``

219

`+

copier(src, dst)

`

``

220

+

``

221

`+

copy init.tcl over

`

``

222

`+

for root, dirs, files in os.walk(context.python_dir):

`

``

223

`+

if 'init.tcl' in files:

`

``

224

`+

tcldir = os.path.basename(root)

`

``

225

`+

tcldir = os.path.join(context.env_dir, 'Lib', tcldir)

`

``

226

`+

if not os.path.exists(tcldir):

`

``

227

`+

os.makedirs(tcldir)

`

``

228

`+

src = os.path.join(root, 'init.tcl')

`

``

229

`+

dst = os.path.join(tcldir, 'init.tcl')

`

``

230

`+

shutil.copyfile(src, dst)

`

``

231

`+

break

`

237

232

``

238

233

`def _setup_pip(self, context):

`

239

234

`"""Installs or upgrades pip in a virtual environment"""

`

`@@ -320,7 +315,7 @@ def install_scripts(self, context, path):

`

320

315

`dstfile = os.path.join(dstdir, f)

`

321

316

`with open(srcfile, 'rb') as f:

`

322

317

`data = f.read()

`

323

``

`-

if not srcfile.endswith('.exe'):

`

``

318

`+

if not srcfile.endswith(('.exe', '.pdb')):

`

324

319

`try:

`

325

320

`data = data.decode('utf-8')

`

326

321

`data = self.replace_variables(data, context)

`