2020-05-22 22:01:15 +00:00
|
|
|
// Copyright 2016-2020, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package python
|
|
|
|
|
|
|
|
import (
|
2022-06-09 21:57:56 +00:00
|
|
|
"context"
|
2023-01-03 10:19:35 +00:00
|
|
|
"errors"
|
2020-05-22 22:01:15 +00:00
|
|
|
"fmt"
|
2020-12-04 03:22:16 +00:00
|
|
|
"io"
|
2020-05-22 22:01:15 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
2020-06-09 23:42:53 +00:00
|
|
|
|
2022-07-25 10:52:17 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
|
2020-05-22 22:01:15 +00:00
|
|
|
)
|
|
|
|
|
2020-12-07 07:32:24 +00:00
|
|
|
const (
|
|
|
|
windows = "windows"
|
|
|
|
pythonShimCmdFormat = "pulumi-%s-shim.cmd"
|
|
|
|
)
|
2020-05-22 22:01:15 +00:00
|
|
|
|
2022-10-09 14:58:33 +00:00
|
|
|
// CommandPath finds the correct path and command for Python. If the `PULUMI_PYTHON_CMD`
|
2021-08-21 02:38:51 +00:00
|
|
|
// variable is set it will be looked for on `PATH`, otherwise, `python3` and
|
|
|
|
// `python` will be looked for.
|
|
|
|
func CommandPath() (string /*pythonPath*/, string /*pythonCmd*/, error) {
|
2020-05-22 22:01:15 +00:00
|
|
|
var err error
|
|
|
|
var pythonCmds []string
|
|
|
|
|
|
|
|
if pythonCmd := os.Getenv("PULUMI_PYTHON_CMD"); pythonCmd != "" {
|
|
|
|
pythonCmds = []string{pythonCmd}
|
|
|
|
} else {
|
2021-02-11 19:34:07 +00:00
|
|
|
// Look for `python3` by default, but fallback to `python` if not found, except on Windows
|
|
|
|
// where we look for these in the reverse order because the default python.org Windows
|
|
|
|
// installation does not include a `python3` binary, and the existence of a `python3.exe`
|
|
|
|
// symlink to `python.exe` on some systems does not work correctly with the Python `venv`
|
|
|
|
// module.
|
2020-05-22 22:01:15 +00:00
|
|
|
pythonCmds = []string{"python3", "python"}
|
2021-02-11 19:34:07 +00:00
|
|
|
if runtime.GOOS == windows {
|
|
|
|
pythonCmds = []string{"python", "python3"}
|
|
|
|
}
|
2020-05-22 22:01:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 07:32:24 +00:00
|
|
|
var pythonCmd, pythonPath string
|
|
|
|
for _, pythonCmd = range pythonCmds {
|
2020-05-22 22:01:15 +00:00
|
|
|
pythonPath, err = exec.LookPath(pythonCmd)
|
|
|
|
// Break on the first cmd we find on the path (if any)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
2020-11-18 05:21:51 +00:00
|
|
|
// second-chance on windows for python being installed through the Windows app store.
|
|
|
|
if runtime.GOOS == windows {
|
2020-12-07 07:32:24 +00:00
|
|
|
pythonCmd, pythonPath, err = resolveWindowsExecutionAlias(pythonCmds)
|
2020-11-18 05:21:51 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
2023-01-03 10:19:35 +00:00
|
|
|
return "", "", fmt.Errorf(
|
|
|
|
"failed to locate any of %q on your PATH. Have you installed Python 3.6 or greater?",
|
2020-11-18 05:21:51 +00:00
|
|
|
pythonCmds)
|
|
|
|
}
|
2020-05-22 22:01:15 +00:00
|
|
|
}
|
2021-08-21 02:38:51 +00:00
|
|
|
return pythonPath, pythonCmd, nil
|
|
|
|
}
|
2020-12-07 07:32:24 +00:00
|
|
|
|
2021-08-21 02:38:51 +00:00
|
|
|
// Command returns an *exec.Cmd for running `python`. Uses `ComandPath`
|
|
|
|
// internally to find the correct executable.
|
2022-06-09 21:57:56 +00:00
|
|
|
func Command(ctx context.Context, arg ...string) (*exec.Cmd, error) {
|
2021-08-21 02:38:51 +00:00
|
|
|
pythonPath, pythonCmd, err := CommandPath()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-12-07 07:32:24 +00:00
|
|
|
if needsPythonShim(pythonPath) {
|
|
|
|
shimCmd := fmt.Sprintf(pythonShimCmdFormat, pythonCmd)
|
2022-06-09 21:57:56 +00:00
|
|
|
return exec.CommandContext(ctx, shimCmd, arg...), nil
|
2020-12-07 07:32:24 +00:00
|
|
|
}
|
2022-06-09 21:57:56 +00:00
|
|
|
return exec.CommandContext(ctx, pythonPath, arg...), nil
|
2020-05-22 22:01:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 01:14:15 +00:00
|
|
|
// resolveWindowsExecutionAlias performs a lookup for python among UWP
|
|
|
|
// application execution aliases which exec.LookPath() can't handle.
|
|
|
|
// Windows 10 supports execution aliases for UWP applications. If python
|
|
|
|
// is installed using the Windows store app, the installer will drop an alias
|
|
|
|
// in %LOCALAPPDATA%\Microsoft\WindowsApps which is a zero-length file - also
|
|
|
|
// called an execution alias. This directory is also added to the PATH.
|
|
|
|
// See https://www.tiraniddo.dev/2019/09/overview-of-windows-execution-aliases.html
|
|
|
|
// for an overview.
|
|
|
|
// Most of this code is a replacement of the windows version of exec.LookPath
|
|
|
|
// but uses os.Lstat instead of an os.Stat which fails with a
|
|
|
|
// "CreateFile <path>: The file cannot be accessed by the system".
|
2020-12-07 07:32:24 +00:00
|
|
|
func resolveWindowsExecutionAlias(pythonCmds []string) (string, string, error) {
|
2020-11-19 01:14:15 +00:00
|
|
|
exts := []string{""}
|
|
|
|
x := os.Getenv(`PATHEXT`)
|
|
|
|
if x != "" {
|
|
|
|
for _, e := range strings.Split(strings.ToLower(x), `;`) {
|
|
|
|
if e == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if e[0] != '.' {
|
|
|
|
e = "." + e
|
|
|
|
}
|
|
|
|
exts = append(exts, e)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
exts = append(exts, ".com", ".exe", ".bat", ".cmd")
|
|
|
|
}
|
|
|
|
|
|
|
|
path := os.Getenv("PATH")
|
|
|
|
for _, dir := range filepath.SplitList(path) {
|
|
|
|
if !strings.Contains(strings.ToLower(dir), filepath.Join("microsoft", "windowsapps")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, pythonCmd := range pythonCmds {
|
|
|
|
for _, ext := range exts {
|
|
|
|
path := filepath.Join(dir, pythonCmd+ext)
|
2020-12-07 07:32:24 +00:00
|
|
|
_, err := os.Lstat(path)
|
2020-11-19 01:14:15 +00:00
|
|
|
if err != nil && !os.IsNotExist(err) {
|
2023-01-03 10:19:35 +00:00
|
|
|
return "", "", fmt.Errorf("evaluating python execution alias: %w", err)
|
2020-11-19 01:14:15 +00:00
|
|
|
}
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
continue
|
|
|
|
}
|
2020-12-07 07:32:24 +00:00
|
|
|
return pythonCmd, path, nil
|
2020-11-19 01:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 07:32:24 +00:00
|
|
|
return "", "", errors.New("no python execution alias found")
|
2020-11-19 01:14:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 22:01:15 +00:00
|
|
|
// VirtualEnvCommand returns an *exec.Cmd for running a command from the specified virtual environment
|
|
|
|
// directory.
|
2020-06-09 23:42:53 +00:00
|
|
|
func VirtualEnvCommand(virtualEnvDir, name string, arg ...string) *exec.Cmd {
|
2020-05-22 22:01:15 +00:00
|
|
|
if runtime.GOOS == windows {
|
2023-12-12 12:19:42 +00:00
|
|
|
name = name + ".exe"
|
2020-05-22 22:01:15 +00:00
|
|
|
}
|
|
|
|
cmdPath := filepath.Join(virtualEnvDir, virtualEnvBinDirName(), name)
|
|
|
|
return exec.Command(cmdPath, arg...)
|
|
|
|
}
|
|
|
|
|
2020-06-09 23:42:53 +00:00
|
|
|
// IsVirtualEnv returns true if the specified directory contains a python binary.
|
|
|
|
func IsVirtualEnv(dir string) bool {
|
|
|
|
pyBin := filepath.Join(dir, virtualEnvBinDirName(), "python")
|
|
|
|
if runtime.GOOS == windows {
|
2023-12-12 12:19:42 +00:00
|
|
|
pyBin = pyBin + ".exe"
|
2020-06-09 23:42:53 +00:00
|
|
|
}
|
|
|
|
if info, err := os.Stat(pyBin); err == nil && !info.IsDir() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-28 20:28:14 +00:00
|
|
|
// NewVirtualEnvError creates an error about the virtual environment with more info on how to resolve the issue.
|
|
|
|
func NewVirtualEnvError(dir, fullPath string) error {
|
|
|
|
pythonBin := "python3"
|
|
|
|
if runtime.GOOS == windows {
|
|
|
|
pythonBin = "python"
|
|
|
|
}
|
|
|
|
venvPythonBin := filepath.Join(fullPath, virtualEnvBinDirName(), "python")
|
|
|
|
|
|
|
|
message := "doesn't appear to be a virtual environment"
|
|
|
|
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
|
|
|
message = "doesn't exist"
|
|
|
|
}
|
|
|
|
|
|
|
|
commandsText := fmt.Sprintf(" 1. %s -m venv %s\n", pythonBin, fullPath) +
|
|
|
|
fmt.Sprintf(" 2. %s -m pip install --upgrade pip setuptools wheel\n", venvPythonBin) +
|
|
|
|
fmt.Sprintf(" 3. %s -m pip install -r requirements.txt\n", venvPythonBin)
|
|
|
|
|
2023-01-03 10:19:35 +00:00
|
|
|
return fmt.Errorf("The 'virtualenv' option in Pulumi.yaml is set to %q, but %q %s; "+
|
2020-07-28 20:28:14 +00:00
|
|
|
"run the following commands to create the virtual environment and install dependencies into it:\n\n%s\n\n"+
|
|
|
|
"For more information see: https://www.pulumi.com/docs/intro/languages/python/#virtual-environments",
|
|
|
|
dir, fullPath, message, commandsText)
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:01:15 +00:00
|
|
|
// ActivateVirtualEnv takes an array of environment variables (same format as os.Environ()) and path to
|
|
|
|
// a virtual environment directory, and returns a new "activated" array with the virtual environment's
|
|
|
|
// "bin" dir ("Scripts" on Windows) prepended to the `PATH` environment variable and `PYTHONHOME` variable
|
|
|
|
// removed.
|
|
|
|
func ActivateVirtualEnv(environ []string, virtualEnvDir string) []string {
|
|
|
|
virtualEnvBin := filepath.Join(virtualEnvDir, virtualEnvBinDirName())
|
|
|
|
var hasPath bool
|
|
|
|
var result []string
|
|
|
|
for _, env := range environ {
|
2022-07-25 10:52:17 +00:00
|
|
|
split := strings.SplitN(env, "=", 2)
|
2023-02-15 01:06:56 +00:00
|
|
|
contract.Assertf(len(split) == 2, "unexpected environment variable: %q", env)
|
2022-07-25 10:52:17 +00:00
|
|
|
key, value := split[0], split[1]
|
|
|
|
|
|
|
|
// Case-insensitive compare, as Windows will normally be "Path", not "PATH".
|
|
|
|
if strings.EqualFold(key, "PATH") {
|
2020-05-22 22:01:15 +00:00
|
|
|
hasPath = true
|
|
|
|
// Prepend the virtual environment bin directory to PATH so any calls to run
|
|
|
|
// python or pip will use the binaries in the virtual environment.
|
2022-07-25 10:52:17 +00:00
|
|
|
path := fmt.Sprintf("%s=%s%s%s", key, virtualEnvBin, string(os.PathListSeparator), value)
|
2020-05-22 22:01:15 +00:00
|
|
|
result = append(result, path)
|
2022-07-25 10:52:17 +00:00
|
|
|
} else if strings.EqualFold(key, "PYTHONHOME") {
|
2020-05-22 22:01:15 +00:00
|
|
|
// Skip PYTHONHOME to "unset" this value.
|
|
|
|
} else {
|
|
|
|
result = append(result, env)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !hasPath {
|
2023-12-12 12:19:42 +00:00
|
|
|
path := "PATH=" + virtualEnvBin
|
2020-05-22 22:01:15 +00:00
|
|
|
result = append(result, path)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-06-09 23:42:53 +00:00
|
|
|
// InstallDependencies will create a new virtual environment and install dependencies in the root directory.
|
2022-06-09 21:57:56 +00:00
|
|
|
func InstallDependencies(ctx context.Context, root, venvDir string, showOutput bool) error {
|
|
|
|
return InstallDependenciesWithWriters(ctx, root, venvDir, showOutput, os.Stdout, os.Stderr)
|
2020-12-04 03:22:16 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 21:57:56 +00:00
|
|
|
func InstallDependenciesWithWriters(ctx context.Context,
|
2023-03-03 16:36:39 +00:00
|
|
|
root, venvDir string, showOutput bool, infoWriter, errorWriter io.Writer,
|
|
|
|
) error {
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
printmsg := func(message string) {
|
2020-07-23 20:33:09 +00:00
|
|
|
if showOutput {
|
2020-12-04 03:22:16 +00:00
|
|
|
fmt.Fprintf(infoWriter, "%s\n", message)
|
2020-07-23 20:33:09 +00:00
|
|
|
}
|
2020-06-09 23:42:53 +00:00
|
|
|
}
|
|
|
|
|
2023-10-25 16:03:02 +00:00
|
|
|
if venvDir != "" {
|
|
|
|
printmsg("Creating virtual environment...")
|
2020-07-23 20:33:09 +00:00
|
|
|
|
2023-10-25 16:03:02 +00:00
|
|
|
// Create the virtual environment by running `python -m venv <venvDir>`.
|
|
|
|
if !filepath.IsAbs(venvDir) {
|
|
|
|
venvDir = filepath.Join(root, venvDir)
|
|
|
|
}
|
2021-03-24 19:51:46 +00:00
|
|
|
|
2023-10-25 16:03:02 +00:00
|
|
|
cmd, err := Command(ctx, "-m", "venv", venvDir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if output, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
if len(output) > 0 {
|
|
|
|
fmt.Fprintf(errorWriter, "%s\n", string(output))
|
|
|
|
}
|
2024-01-30 15:02:59 +00:00
|
|
|
return fmt.Errorf("creating virtual environment at '%s': %w", venvDir, err)
|
2020-06-09 23:42:53 +00:00
|
|
|
}
|
|
|
|
|
2023-10-25 16:03:02 +00:00
|
|
|
printmsg("Finished creating virtual environment")
|
|
|
|
}
|
2020-07-23 20:33:09 +00:00
|
|
|
|
|
|
|
runPipInstall := func(errorMsg string, arg ...string) error {
|
2023-10-25 16:03:02 +00:00
|
|
|
args := append([]string{"-m", "pip", "install"}, arg...)
|
|
|
|
|
|
|
|
var pipCmd *exec.Cmd
|
|
|
|
if venvDir == "" {
|
|
|
|
var err error
|
|
|
|
pipCmd, err = Command(ctx, args...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pipCmd = VirtualEnvCommand(venvDir, "python", args...)
|
|
|
|
}
|
2020-07-23 20:33:09 +00:00
|
|
|
pipCmd.Dir = root
|
|
|
|
pipCmd.Env = ActivateVirtualEnv(os.Environ(), venvDir)
|
|
|
|
|
|
|
|
wrapError := func(err error) error {
|
2023-01-03 10:19:35 +00:00
|
|
|
return fmt.Errorf("%s via '%s': %w", errorMsg, strings.Join(pipCmd.Args, " "), err)
|
2020-07-23 20:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if showOutput {
|
|
|
|
// Show stdout/stderr output.
|
2020-12-04 03:22:16 +00:00
|
|
|
pipCmd.Stdout = infoWriter
|
|
|
|
pipCmd.Stderr = errorWriter
|
2020-07-23 20:33:09 +00:00
|
|
|
if err := pipCmd.Run(); err != nil {
|
|
|
|
return wrapError(err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, only show output if there is an error.
|
|
|
|
if output, err := pipCmd.CombinedOutput(); err != nil {
|
|
|
|
if len(output) > 0 {
|
2020-12-04 03:22:16 +00:00
|
|
|
fmt.Fprintf(errorWriter, "%s\n", string(output))
|
2020-07-23 20:33:09 +00:00
|
|
|
}
|
|
|
|
return wrapError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
printmsg("Updating pip, setuptools, and wheel in virtual environment...")
|
2020-07-23 20:33:09 +00:00
|
|
|
|
2024-01-30 15:02:59 +00:00
|
|
|
// activate virtual environment
|
|
|
|
|
2023-10-25 16:03:02 +00:00
|
|
|
err := runPipInstall("updating pip, setuptools, and wheel", "--upgrade", "pip", "setuptools", "wheel")
|
2020-07-23 20:33:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-06-09 23:42:53 +00:00
|
|
|
}
|
|
|
|
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
printmsg("Finished updating")
|
2020-07-23 20:33:09 +00:00
|
|
|
|
|
|
|
// If `requirements.txt` doesn't exist, exit early.
|
2020-06-09 23:42:53 +00:00
|
|
|
requirementsPath := filepath.Join(root, "requirements.txt")
|
|
|
|
if _, err := os.Stat(requirementsPath); os.IsNotExist(err) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
printmsg("Installing dependencies in virtual environment...")
|
2020-06-09 23:42:53 +00:00
|
|
|
|
2020-07-23 20:33:09 +00:00
|
|
|
err = runPipInstall("installing dependencies", "-r", "requirements.txt")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-06-09 23:42:53 +00:00
|
|
|
}
|
|
|
|
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
printmsg("Finished installing dependencies")
|
2020-06-09 23:42:53 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:01:15 +00:00
|
|
|
func virtualEnvBinDirName() string {
|
|
|
|
if runtime.GOOS == windows {
|
|
|
|
return "Scripts"
|
|
|
|
}
|
|
|
|
return "bin"
|
|
|
|
}
|