Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: vpython/venv/venv_resources_test.go

Issue 2744933003: Re-enable vpython/venv's TestVirtualEnv. (Closed)
Patch Set: better comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | vpython/venv/venv_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package venv 5 package venv
6 6
7 import ( 7 import (
8 "archive/zip" 8 "archive/zip"
9 "crypto/sha256" 9 "crypto/sha256"
10 "encoding/hex" 10 "encoding/hex"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return copyFileIntoDir(tl.pantsWheelPath, root) 156 return copyFileIntoDir(tl.pantsWheelPath, root)
157 157
158 default: 158 default:
159 return errors.Reason("don't know how to install %(package)q"). 159 return errors.Reason("don't know how to install %(package)q").
160 D("package", name). 160 D("package", name).
161 Err() 161 Err()
162 } 162 }
163 } 163 }
164 164
165 func (tl *testingLoader) buildWheelLocked(t *testing.T, py *python.Interpreter, name, outDir string) (string, error) { 165 func (tl *testingLoader) buildWheelLocked(t *testing.T, py *python.Interpreter, name, outDir string) (string, error) {
166 ctx := context.Background()
166 w, err := wheel.ParseName(name) 167 w, err := wheel.ParseName(name)
167 if err != nil { 168 if err != nil {
168 return "", errors.Annotate(err).Reason("failed to parse wheel na me %(name)q"). 169 return "", errors.Annotate(err).Reason("failed to parse wheel na me %(name)q").
169 D("name", name). 170 D("name", name).
170 Err() 171 Err()
171 } 172 }
172 173
173 outWheelPath := filepath.Join(outDir, w.String()) 174 outWheelPath := filepath.Join(outDir, w.String())
174 switch _, err := os.Stat(outWheelPath); { 175 switch _, err := os.Stat(outWheelPath); {
175 case err == nil: 176 case err == nil:
(...skipping 22 matching lines...) Expand all
198 Version: "whatever", 199 Version: "whatever",
199 }, 200 },
200 Loader: tl, 201 Loader: tl,
201 Spec: &vpython.Spec{}, 202 Spec: &vpython.Spec{},
202 203
203 // Testing parameters for this bootstrap wheel-building environm ent. 204 // Testing parameters for this bootstrap wheel-building environm ent.
204 testPreserveInstallationCapability: true, 205 testPreserveInstallationCapability: true,
205 testLeaveReadWrite: true, 206 testLeaveReadWrite: true,
206 } 207 }
207 208
208 » return outWheelPath, With(context.Background(), cfg, true, func(ctx cont ext.Context, env *Env) error { 209 » // Build the wheel in a temporary directory, then copy it into outDir. T his
209 » » cmd := env.InterpreterCommand() 210 » // will stop wheel builds from stepping on each other or inheriting each
210 » » cmd.WorkDir = srcDir 211 » // others' state accidentally.
211 » » if err := cmd.Run(context.Background(), "setup.py", "bdist_wheel ", "--dist-dir", outDir); err != nil { 212 » err = testfs.WithTempDir(t, "vpython_venv_wheel", func(tdir string) erro r {
213 » » buildDir := filepath.Join(tdir, "build")
214 » » if err := filesystem.MakeDirs(buildDir); err != nil {
215 » » » return err
216 » » }
217
218 » » distDir := filepath.Join(tdir, "dist")
219 » » if err := filesystem.MakeDirs(distDir); err != nil {
220 » » » return err
221 » » }
222
223 » » // Use an empty bootstrap VirtualEnv to build the wheel. This gu arantees
224 » » // that we actually have "setuptools" and "wheel" packages, whic h are
225 » » // required for building wheels, and not necessarily present in their
226 » » // expected forms on all systems.
227 » » err := With(ctx, cfg, true, func(ctx context.Context, env *Env) error {
228 » » » cmd := env.InterpreterCommand()
229 » » » cmd.WorkDir = srcDir
230 » » » err := cmd.Run(ctx, "setup.py", "--no-user-cfg", "bdist_ wheel",
231 » » » » "--bdist-dir", buildDir,
232 » » » » "--dist-dir", distDir)
233 » » » if err != nil {
234 » » » » return errors.Annotate(err).Reason("failed to bu ild wheel").Err()
235 » » » }
236 » » » return nil
237 » » })
238 » » if err != nil {
212 return errors.Annotate(err).Reason("failed to build whee l").Err() 239 return errors.Annotate(err).Reason("failed to build whee l").Err()
213 } 240 }
214 241
215 » » if _, err := os.Stat(outWheelPath); err != nil { 242 » » // Assert that the expected wheel file was generated, and copy i t into
243 » » // outDir.
244 » » wheelPath := filepath.Join(distDir, w.String())
245 » » if _, err := os.Stat(wheelPath); err != nil {
216 return errors.Annotate(err).Reason("failed to generate w heel").Err() 246 return errors.Annotate(err).Reason("failed to generate w heel").Err()
217 } 247 }
248 if err := copyFileIntoDir(wheelPath, outDir); err != nil {
249 return errors.Annotate(err).Reason("failed to install wh eel").Err()
250 }
218 251
219 t.Logf("Generated wheel file %q: %s", name, outWheelPath)
220 return nil 252 return nil
221 }) 253 })
254 if err != nil {
255 return "", err
256 }
257
258 t.Logf("Generated wheel file %q: %s", name, outWheelPath)
259 return outWheelPath, nil
222 } 260 }
223 261
224 func (tl *testingLoader) ensureRemoteFilesLocked(ctx context.Context, t *testing .T) error { 262 func (tl *testingLoader) ensureRemoteFilesLocked(ctx context.Context, t *testing .T) error {
225 MainLoop: 263 MainLoop:
226 for _, rf := range remoteFiles { 264 for _, rf := range remoteFiles {
227 cachePath := filepath.Join(tl.cacheDir, rf.name) 265 cachePath := filepath.Join(tl.cacheDir, rf.name)
228 266
229 // Check if the remote file is already cached. 267 // Check if the remote file is already cached.
230 err := getCachedFileLocked(t, cachePath, rf.contentHash) 268 err := getCachedFileLocked(t, cachePath, rf.contentHash)
231 if err == nil { 269 if err == nil {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 if _, err := io.Copy(dfd, sfd); err != nil { 467 if _, err := io.Copy(dfd, sfd); err != nil {
430 return errors.Annotate(err).Reason("failed to copy file").Err() 468 return errors.Annotate(err).Reason("failed to copy file").Err()
431 } 469 }
432 if fi != nil { 470 if fi != nil {
433 if err := os.Chmod(dst, fi.Mode()); err != nil { 471 if err := os.Chmod(dst, fi.Mode()); err != nil {
434 return errors.Annotate(err).Reason("failed to chmod").Er r() 472 return errors.Annotate(err).Reason("failed to chmod").Er r()
435 } 473 }
436 } 474 }
437 return nil 475 return nil
438 } 476 }
OLDNEW
« no previous file with comments | « no previous file | vpython/venv/venv_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698