Skip to content

Commit ef6511e

Browse files
authored
Fix telemetry when updating pip (#20903)
@luabud This PR adds a minor telemetry change to create environment. There is a new telemetry point indicating pip upgrade.
1 parent b208384 commit ef6511e

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

pythonFiles/create_venv.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,12 @@ def install_requirements(venv_path: str, requirements: List[str]) -> None:
9090
if not requirements:
9191
return
9292

93-
print(f"VENV_INSTALLING_REQUIREMENTS: {requirements}")
94-
args = []
9593
for requirement in requirements:
96-
args += ["-r", requirement]
97-
run_process(
98-
[venv_path, "-m", "pip", "install"] + args,
99-
"CREATE_VENV.PIP_FAILED_INSTALL_REQUIREMENTS",
100-
)
94+
print(f"VENV_INSTALLING_REQUIREMENTS: {requirement}")
95+
run_process(
96+
[venv_path, "-m", "pip", "install", "-r", requirement],
97+
"CREATE_VENV.PIP_FAILED_INSTALL_REQUIREMENTS",
98+
)
10199
print("CREATE_VENV.PIP_INSTALLED_REQUIREMENTS")
102100

103101

@@ -111,10 +109,12 @@ def install_toml(venv_path: str, extras: List[str]) -> None:
111109

112110

113111
def upgrade_pip(venv_path: str) -> None:
112+
print("CREATE_VENV.UPGRADING_PIP")
114113
run_process(
115114
[venv_path, "-m", "pip", "install", "--upgrade", "pip"],
116-
"CREATE_VENV.PIP_UPGRADE_FAILED",
115+
"CREATE_VENV.UPGRADE_PIP_FAILED",
117116
)
117+
print("CREATE_VENV.UPGRADED_PIP")
118118

119119

120120
def add_gitignore(name: str) -> None:

pythonFiles/tests/test_create_venv.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def run_process(args, error_message):
100100
nonlocal pip_upgraded, installing
101101
if args[1:] == ["-m", "pip", "install", "--upgrade", "pip"]:
102102
pip_upgraded = True
103-
assert error_message == "CREATE_VENV.PIP_UPGRADE_FAILED"
103+
assert error_message == "CREATE_VENV.UPGRADE_PIP_FAILED"
104104
elif args[1:-1] == ["-m", "pip", "install", "-r"]:
105105
installing = "requirements"
106106
assert error_message == "CREATE_VENV.PIP_FAILED_INSTALL_REQUIREMENTS"
@@ -146,34 +146,28 @@ def run_process(args, error_message):
146146
@pytest.mark.parametrize(
147147
("extras", "expected"),
148148
[
149-
([], None),
149+
([], []),
150150
(
151151
["requirements/test.txt"],
152-
[sys.executable, "-m", "pip", "install", "-r", "requirements/test.txt"],
152+
[[sys.executable, "-m", "pip", "install", "-r", "requirements/test.txt"]],
153153
),
154154
(
155155
["requirements/test.txt", "requirements/doc.txt"],
156156
[
157-
sys.executable,
158-
"-m",
159-
"pip",
160-
"install",
161-
"-r",
162-
"requirements/test.txt",
163-
"-r",
164-
"requirements/doc.txt",
157+
[sys.executable, "-m", "pip", "install", "-r", "requirements/test.txt"],
158+
[sys.executable, "-m", "pip", "install", "-r", "requirements/doc.txt"],
165159
],
166160
),
167161
],
168162
)
169163
def test_requirements_args(extras, expected):
170164
importlib.reload(create_venv)
171165

172-
actual = None
166+
actual = []
173167

174168
def run_process(args, error_message):
175169
nonlocal actual
176-
actual = args
170+
actual.append(args)
177171

178172
create_venv.run_process = run_process
179173

src/client/common/utils/localize.ts

+1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ export namespace CreateEnv {
439439
export namespace Venv {
440440
export const creating = l10n.t('Creating venv...');
441441
export const created = l10n.t('Environment created...');
442+
export const upgradingPip = l10n.t('Upgrading pip...');
442443
export const installingPackages = l10n.t('Installing packages...');
443444
export const errorCreatingEnvironment = l10n.t('Error while creating virtual environment.');
444445
export const selectPythonPlaceHolder = l10n.t('Select a Python installation to create the virtual environment');

src/client/pythonEnvironments/creation/provider/venvProgressAndTelemetry.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ export const CREATE_VENV_FAILED_MARKER = 'CREATE_VENV.VENV_FAILED_CREATION';
1818
export const VENV_ALREADY_EXISTS_MARKER = 'CREATE_VENV.VENV_ALREADY_EXISTS';
1919
export const INSTALLED_REQUIREMENTS_MARKER = 'CREATE_VENV.PIP_INSTALLED_REQUIREMENTS';
2020
export const INSTALLED_PYPROJECT_MARKER = 'CREATE_VENV.PIP_INSTALLED_PYPROJECT';
21-
export const PIP_UPGRADE_FAILED_MARKER = 'CREATE_VENV.PIP_UPGRADE_FAILED';
21+
export const UPGRADE_PIP_FAILED_MARKER = 'CREATE_VENV.UPGRADE_PIP_FAILED';
22+
export const UPGRADING_PIP_MARKER = 'CREATE_VENV.UPGRADING_PIP';
23+
export const UPGRADED_PIP_MARKER = 'CREATE_VENV.UPGRADED_PIP';
2224

2325
export class VenvProgressAndTelemetry {
2426
private venvCreatedReported = false;
2527

2628
private venvOrPipMissingReported = false;
2729

30+
private venvUpgradingPipReported = false;
31+
32+
private venvUpgradedPipReported = false;
33+
2834
private venvFailedReported = false;
2935

3036
private venvInstallingPackagesReported = false;
@@ -70,6 +76,15 @@ export class VenvProgressAndTelemetry {
7076
reason: 'noPip',
7177
});
7278
this.lastError = PIP_NOT_INSTALLED_MARKER;
79+
} else if (!this.venvUpgradingPipReported && output.includes(UPGRADING_PIP_MARKER)) {
80+
this.venvUpgradingPipReported = true;
81+
this.progress.report({
82+
message: CreateEnv.Venv.upgradingPip,
83+
});
84+
sendTelemetryEvent(EventName.ENVIRONMENT_INSTALLING_PACKAGES, undefined, {
85+
environmentType: 'venv',
86+
using: 'pipUpgrade',
87+
});
7388
} else if (!this.venvFailedReported && output.includes(CREATE_VENV_FAILED_MARKER)) {
7489
this.venvFailedReported = true;
7590
sendTelemetryEvent(EventName.ENVIRONMENT_FAILED, undefined, {
@@ -95,13 +110,13 @@ export class VenvProgressAndTelemetry {
95110
environmentType: 'venv',
96111
using: 'pyproject.toml',
97112
});
98-
} else if (!this.venvInstallingPackagesFailedReported && output.includes(PIP_UPGRADE_FAILED_MARKER)) {
113+
} else if (!this.venvInstallingPackagesFailedReported && output.includes(UPGRADE_PIP_FAILED_MARKER)) {
99114
this.venvInstallingPackagesFailedReported = true;
100115
sendTelemetryEvent(EventName.ENVIRONMENT_INSTALLING_PACKAGES_FAILED, undefined, {
101116
environmentType: 'venv',
102117
using: 'pipUpgrade',
103118
});
104-
this.lastError = PIP_UPGRADE_FAILED_MARKER;
119+
this.lastError = UPGRADE_PIP_FAILED_MARKER;
105120
} else if (!this.venvInstallingPackagesFailedReported && output.includes(INSTALL_REQUIREMENTS_FAILED_MARKER)) {
106121
this.venvInstallingPackagesFailedReported = true;
107122
sendTelemetryEvent(EventName.ENVIRONMENT_INSTALLING_PACKAGES_FAILED, undefined, {
@@ -116,6 +131,12 @@ export class VenvProgressAndTelemetry {
116131
using: 'pyproject.toml',
117132
});
118133
this.lastError = INSTALL_PYPROJECT_FAILED_MARKER;
134+
} else if (!this.venvUpgradedPipReported && output.includes(UPGRADED_PIP_MARKER)) {
135+
this.venvUpgradedPipReported = true;
136+
sendTelemetryEvent(EventName.ENVIRONMENT_INSTALLED_PACKAGES, undefined, {
137+
environmentType: 'venv',
138+
using: 'pipUpgrade',
139+
});
119140
} else if (!this.venvInstalledPackagesReported && output.includes(INSTALLED_REQUIREMENTS_MARKER)) {
120141
this.venvInstalledPackagesReported = true;
121142
sendTelemetryEvent(EventName.ENVIRONMENT_INSTALLED_PACKAGES, undefined, {

src/client/telemetry/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@ export interface IEventNamePropertyMapping {
20542054
*/
20552055
[EventName.ENVIRONMENT_INSTALLING_PACKAGES]: {
20562056
environmentType: 'venv' | 'conda';
2057-
using: 'requirements.txt' | 'pyproject.toml' | 'environment.yml';
2057+
using: 'requirements.txt' | 'pyproject.toml' | 'environment.yml' | 'pipUpgrade';
20582058
};
20592059
/**
20602060
* Telemetry event sent after installing packages.
@@ -2067,7 +2067,7 @@ export interface IEventNamePropertyMapping {
20672067
*/
20682068
[EventName.ENVIRONMENT_INSTALLED_PACKAGES]: {
20692069
environmentType: 'venv' | 'conda';
2070-
using: 'requirements.txt' | 'pyproject.toml' | 'environment.yml';
2070+
using: 'requirements.txt' | 'pyproject.toml' | 'environment.yml' | 'pipUpgrade';
20712071
};
20722072
/**
20732073
* Telemetry event sent if installing packages failed.

0 commit comments

Comments
 (0)