Skip to content

Commit ac02291

Browse files
Snow 1999047 fix binaries visible as pypi in telemetry (#2141)
1 parent 361ff69 commit ac02291

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

scripts/packaging/build_isolated_binary_with_hatch.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
PROJECT_ROOT = Path(__file__).parent.parent.parent
2424
PYPROJECT_PATH = PROJECT_ROOT / "pyproject.toml"
25+
INSTALLATION_SOURCE_VARIABLE = "INSTALLATION_SOURCE"
2526

2627

2728
@contextlib.contextmanager
@@ -112,10 +113,28 @@ def hatch_install_python(python_tmp_dir: Path, python_version: str) -> bool:
112113
return not completed_proc.returncode
113114

114115

115-
def pip_install_project(python_exe: str, project_whl: Path) -> bool:
116+
@contextlib.contextmanager
117+
def override_is_installation_source_variable():
118+
about_file = PROJECT_ROOT / "src" / "snowflake" / "cli" / "__about__.py"
119+
contents = about_file.read_text()
120+
if INSTALLATION_SOURCE_VARIABLE not in contents:
121+
raise RuntimeError(
122+
f"{INSTALLATION_SOURCE_VARIABLE} variable not defined in __about__.py"
123+
)
124+
about_file.write_text(
125+
contents.replace(
126+
f"{INSTALLATION_SOURCE_VARIABLE} = CLIInstallationSource.PYPI",
127+
f"{INSTALLATION_SOURCE_VARIABLE} = CLIInstallationSource.BINARY",
128+
)
129+
)
130+
yield
131+
subprocess.run(["git", "checkout", str(about_file)])
132+
133+
134+
def pip_install_project(python_exe: str) -> bool:
116135
"""Install the project into the Python distribution."""
117136
completed_proc = subprocess.run(
118-
[python_exe, "-m", "pip", "install", "-U", str(project_whl)],
137+
[python_exe, "-m", "pip", "install", "-U", str(PROJECT_ROOT)],
119138
capture_output=True,
120139
)
121140
return not completed_proc.returncode
@@ -145,7 +164,8 @@ def main():
145164
print("-> installed")
146165

147166
print(f"Installing project into Python distribution...")
148-
pip_install_project(str(settings.python_dist_exe), PROJECT_ROOT)
167+
with override_is_installation_source_variable():
168+
pip_install_project(str(settings.python_dist_exe))
149169
print("-> installed")
150170

151171
print("Making distribution archive...")

src/snowflake/cli/__about__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@
1414

1515
from __future__ import annotations
1616

17+
from enum import Enum, unique
18+
1719
VERSION = "3.7.0.dev0"
20+
21+
22+
@unique
23+
class CLIInstallationSource(Enum):
24+
BINARY = "binary"
25+
PYPI = "pypi"
26+
27+
28+
# This variable is changed in binary release script
29+
INSTALLATION_SOURCE = CLIInstallationSource.PYPI

src/snowflake/cli/_app/telemetry.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@
4040
from snowflake.connector.time_util import get_time_millis
4141

4242

43-
@unique
44-
class CLIInstallationSource(Enum):
45-
BINARY = "binary"
46-
PYPI = "pypi"
47-
48-
4943
@unique
5044
class CLITelemetryField(Enum):
5145
# Basic information
@@ -172,12 +166,6 @@ def _get_definition_version() -> str | None:
172166
return None
173167

174168

175-
def _get_installation_source() -> CLIInstallationSource:
176-
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
177-
return CLIInstallationSource.BINARY
178-
return CLIInstallationSource.PYPI
179-
180-
181169
def _get_ci_environment_type() -> str:
182170
if "GITHUB_ACTIONS" in os.environ:
183171
return "GITHUB_ACTIONS"
@@ -214,7 +202,7 @@ def generate_telemetry_data_dict(
214202
) -> Dict[str, Any]:
215203
data = {
216204
CLITelemetryField.SOURCE: PARAM_APPLICATION_NAME,
217-
CLITelemetryField.INSTALLATION_SOURCE: _get_installation_source().value,
205+
CLITelemetryField.INSTALLATION_SOURCE: __about__.INSTALLATION_SOURCE.value,
218206
CLITelemetryField.VERSION_CLI: __about__.VERSION,
219207
CLITelemetryField.VERSION_OS: platform.platform(),
220208
CLITelemetryField.VERSION_PYTHON: python_version(),

0 commit comments

Comments
 (0)