-
-
Notifications
You must be signed in to change notification settings - Fork 549
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
Fix telemetry issues in wheel build and unit tests #4591
Changes from all commits
78677fd
90ff2d3
b739a62
f211c11
d894dca
781ebfb
a4cdeb9
3bf454e
a851b90
5d9ba33
33cdc35
ec62beb
58170fb
6c422dc
289cc03
50721df
a53a3d4
12c11a3
1bf656d
880c3e0
f911b90
f31fae1
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,6 +5,7 @@ on: | |
pull_request: | ||
|
||
env: | ||
PYBAMM_DISABLE_TELEMETRY: "true" | ||
FORCE_COLOR: 3 | ||
PYBAMM_IDAKLU_EXPR_CASADI: ON | ||
PYBAMM_IDAKLU_EXPR_IREE: ON | ||
|
@@ -36,7 +37,6 @@ jobs: | |
pre-commit run -a | ||
|
||
run_unit_integration_and_coverage_tests: | ||
needs: style | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
|
@@ -132,7 +132,6 @@ jobs: | |
|
||
# Skips IDAKLU module compilation for speedups, which is already tested in other jobs. | ||
run_doctests: | ||
needs: style | ||
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. If style fails then PR is updated with the pre-commit fixes and the old jobs get canceled. This just speeds up the start of the jobs a bit |
||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
|
@@ -177,7 +176,6 @@ jobs: | |
run: python -m nox -s docs | ||
|
||
run_example_tests: | ||
needs: style | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
|
@@ -233,7 +231,6 @@ jobs: | |
run: python -m nox -s examples | ||
|
||
run_scripts_tests: | ||
needs: style | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,6 @@ def set_iree_state(): | |
"IREE_INDEX_URL": os.getenv( | ||
"IREE_INDEX_URL", "https://iree.dev/pip-release-links.html" | ||
), | ||
"PYBAMM_DISABLE_TELEMETRY": "true", | ||
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. As far as I could tell, this was not working. It seemed like telemetry was still running in tests. |
||
} | ||
VENV_DIR = Path("./venv").resolve() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,18 @@ | |
import time | ||
|
||
|
||
def check_env_opt_out(): | ||
return os.getenv("PYBAMM_DISABLE_TELEMETRY", "false").lower() != "false" | ||
|
||
|
||
def check_opt_out(): | ||
opt_out = check_env_opt_out() | ||
config = pybamm.config.read() | ||
if config: | ||
opt_out = opt_out or not config["enable_telemetry"] | ||
return opt_out | ||
|
||
|
||
def is_running_tests(): # pragma: no cover | ||
""" | ||
Detect if the code is being run as part of a test suite or building docs with Sphinx. | ||
|
@@ -21,20 +33,18 @@ def is_running_tests(): # pragma: no cover | |
): | ||
return True | ||
|
||
# Check for GitHub Actions environment variable | ||
if "GITHUB_ACTIONS" in os.environ: | ||
return True | ||
|
||
# Check for other common CI environment variables | ||
ci_env_vars = ["CI", "TRAVIS", "CIRCLECI", "JENKINS_URL", "GITLAB_CI"] | ||
ci_env_vars = [ | ||
"GITHUB_ACTIONS", | ||
"CI", | ||
"TRAVIS", | ||
"CIRCLECI", | ||
"JENKINS_URL", | ||
"GITLAB_CI", | ||
] | ||
if any(var in os.environ for var in ci_env_vars): | ||
return True | ||
|
||
# Check for common test runner names in command-line arguments | ||
test_runners = ["pytest", "unittest", "nose", "trial", "nox", "tox"] | ||
if any(runner in arg.lower() for arg in sys.argv for runner in test_runners): | ||
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. This did not seem to work on Mac or Windows. I was seeing nox and pytest commands go right past this. I tested it by moving it to the top of the file and putting an assert below it. |
||
return True | ||
|
||
# Check if building docs with Sphinx | ||
if any(mod == "sphinx" or mod.startswith("sphinx.") for mod in sys.modules): | ||
print( | ||
|
@@ -110,7 +120,7 @@ def get_input(): # pragma: no cover | |
|
||
|
||
def generate(): | ||
if is_running_tests(): | ||
if is_running_tests() or check_opt_out(): | ||
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. Since |
||
return | ||
|
||
# Check if the config file already exists | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
from posthog import Posthog | ||
import os | ||
import pybamm | ||
import sys | ||
|
||
_posthog = Posthog( | ||
# this is the public, write only API key, so it's ok to include it here | ||
project_api_key="phc_bLZKBW03XjgiRhbWnPsnKPr0iw0z03fA6ZZYjxgW7ej", | ||
host="https://us.i.posthog.com", | ||
) | ||
|
||
_posthog.log.setLevel("CRITICAL") | ||
class MockTelemetry: | ||
def __init__(self): | ||
self.disabled = True | ||
|
||
@staticmethod | ||
def capture(**kwargs): # pragma: no cover | ||
pass | ||
|
||
def disable(): | ||
_posthog.disabled = True | ||
|
||
if pybamm.config.check_opt_out(): | ||
_posthog = MockTelemetry() | ||
else: # pragma: no cover | ||
_posthog = Posthog( | ||
# this is the public, write only API key, so it's ok to include it here | ||
project_api_key="phc_bLZKBW03XjgiRhbWnPsnKPr0iw0z03fA6ZZYjxgW7ej", | ||
host="https://us.i.posthog.com", | ||
) | ||
_posthog.log.setLevel("CRITICAL") | ||
|
||
|
||
_opt_out = os.getenv("PYBAMM_DISABLE_TELEMETRY", "false").lower() | ||
if _opt_out != "false": # pragma: no cover | ||
disable() | ||
def disable(): | ||
_posthog.disabled = True | ||
|
||
|
||
def capture(event): # pragma: no cover | ||
# don't capture events in automated testing | ||
if pybamm.config.is_running_tests() or _posthog.disabled: | ||
return | ||
|
||
properties = { | ||
"python_version": sys.version, | ||
"pybamm_version": pybamm.__version__, | ||
} | ||
if pybamm.config.check_opt_out(): | ||
disable() | ||
return | ||
|
||
config = pybamm.config.read() | ||
if config: | ||
if config["enable_telemetry"]: | ||
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. This check is now in the |
||
user_id = config["uuid"] | ||
_posthog.capture(user_id, event, properties=properties) | ||
properties = { | ||
"python_version": sys.version, | ||
"pybamm_version": pybamm.__version__, | ||
} | ||
user_id = config["uuid"] | ||
_posthog.capture(distinct_id=user_id, event=event, properties=properties) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,12 +336,12 @@ def no_internet_connection(): | |
conn = socket.create_connection((host, 80), 2) | ||
conn.close() | ||
return False | ||
except socket.gaierror: | ||
except (socket.gaierror, TimeoutError): | ||
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. Sometimes I get timeouts from the |
||
return True | ||
|
||
|
||
def assert_domain_equal(a, b): | ||
"Check that two domains are equal, ignoring empty domains" | ||
"""Check that two domains are equal, ignoring empty domains""" | ||
a_dict = {k: v for k, v in a.items() if v != []} | ||
b_dict = {k: v for k, v in b.items() if v != []} | ||
assert a_dict == b_dict |
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.
As far as I can tell the environment variables were not making it into the CIBW environment. This disables telemetry in the wheel tests