forked from pybamm-team/PyBaMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix telemetry issues in wheel build and unit tests (pybamm-team#4591)
* Reorganize to make sure capture does not run * Cleanup * Mock telemetry object * Fix logic * Minor fixes for networking * temporary trigger * testing env * Remove requirement * Try again * Last attempt * Update wheel env * Cleanup * More cleanup * Final test for cleanup * Turn off wheel build * Make sure opt out is in all tests * Fix some coverage * Cover last line * style: pre-commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e17b549
commit 6c7c21a
Showing
12 changed files
with
86 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]: | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters