-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: capture pre-init Python environment in init telemetry #6534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,13 @@ | |
| import importlib.metadata | ||
| import json | ||
| import multiprocessing | ||
| import os | ||
| import platform | ||
| import sys | ||
| import warnings | ||
| from contextlib import suppress | ||
| from datetime import datetime, timezone | ||
| from pathlib import Path | ||
| from typing import Any, TypedDict, cast | ||
|
|
||
| from reflex_base import constants | ||
|
|
@@ -166,6 +169,31 @@ def get_cpu_count() -> int: | |
| return multiprocessing.cpu_count() | ||
|
|
||
|
|
||
| def is_in_virtualenv() -> bool: | ||
| """Whether the current Python is running inside a virtual environment. | ||
|
|
||
| Returns: | ||
| True if a virtual environment appears to be active. | ||
| """ | ||
| if sys.prefix != sys.base_prefix: | ||
| return True | ||
| return bool(os.environ.get("VIRTUAL_ENV")) | ||
|
|
||
|
|
||
| def get_init_environment() -> dict[str, bool]: | ||
| """Return Python tooling flags for the current working directory. | ||
|
|
||
| Returns: | ||
| A dict with ``in_virtualenv``, ``has_pyproject_toml`` and | ||
| ``has_requirements_txt`` boolean flags. | ||
| """ | ||
| return { | ||
| "in_virtualenv": is_in_virtualenv(), | ||
| "has_pyproject_toml": Path(constants.PyprojectToml.FILE).exists(), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
| "has_requirements_txt": Path(constants.RequirementsTxt.FILE).exists(), | ||
| } | ||
|
|
||
|
|
||
| def get_reflex_enterprise_version() -> str | None: | ||
| """Get the version of reflex-enterprise if installed. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,6 +386,10 @@ def initialize_app(app_name: str, template: str | None = None) -> str | None: | |
| telemetry.send("reinit") | ||
| return None | ||
|
|
||
| # Captured before scaffolding so the snapshot reflects the user's CWD, | ||
| # not files the template will create. | ||
| init_environment = telemetry.get_init_environment() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this call above the |
||
|
|
||
| templates: dict[str, Template] = {} | ||
|
|
||
| # Don't fetch app templates if the user directly asked for DEFAULT. | ||
|
|
@@ -412,7 +416,7 @@ def initialize_app(app_name: str, template: str | None = None) -> str | None: | |
| app_name=app_name, template=template, templates=templates | ||
| ) | ||
|
|
||
| telemetry.send("init", template=template) | ||
| telemetry.send("init", template=template, properties=init_environment) | ||
|
|
||
| return template | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
short circuit when telemetry is not enabled