Skip to content

Commit

Permalink
Update wheel env
Browse files Browse the repository at this point in the history
  • Loading branch information
kratman committed Nov 15, 2024
1 parent 5d9ba33 commit 33cdc35
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
run: pipx run cibuildwheel --output-dir wheelhouse
env:
CIBW_ENVIRONMENT: >
PYBAMM_DISABLE_TELEMETRY="true"
PYBAMM_USE_VCPKG=ON
VCPKG_ROOT_DIR=C:\vcpkg
VCPKG_DEFAULT_TRIPLET=x64-windows-static-md
Expand Down Expand Up @@ -117,6 +118,8 @@ jobs:
- name: Build wheels on Linux
run: pipx run cibuildwheel --output-dir wheelhouse
env:
CIBW_ENVIRONMENT: >
PYBAMM_DISABLE_TELEMETRY="true"
CIBW_ARCHS_LINUX: x86_64
CIBW_BEFORE_ALL_LINUX: >
yum -y install openblas-devel lapack-devel &&
Expand Down Expand Up @@ -243,6 +246,8 @@ jobs:
python scripts/install_KLU_Sundials.py
python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_ENVIRONMENT: >
PYBAMM_DISABLE_TELEMETRY="true"
# 10.13 for Intel (macos-13), 11.0 for Apple Silicon (macos-14 and macos-latest)
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os == 'macos-14' && '11.0' || '10.13' }}
CIBW_ARCHS_MACOS: auto
Expand Down
18 changes: 9 additions & 9 deletions src/pybamm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
import time


def check_opt_out():
opt_out = os.getenv("PYBAMM_DISABLE_TELEMETRY", "false").lower() != "false"
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.
Returns:
bool: True if running tests or building docs, False otherwise.
"""
# 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):
return True

# Check for other common CI environment variables
ci_env_vars = [
"GITHUB_ACTIONS",
Expand All @@ -28,13 +31,10 @@ def is_running_tests(): # pragma: no cover
"CIRCLECI",
"JENKINS_URL",
"GITLAB_CI",
"CIBW_TEST_COMMAND",
]
if any(var in os.environ for var in ci_env_vars):
return True

assert False

# Check if pytest or unittest is running
if any(
test_module in sys.modules for test_module in ["pytest", "unittest", "nose"]
Expand Down Expand Up @@ -116,7 +116,7 @@ def get_input(): # pragma: no cover


def generate():
if is_running_tests():
if is_running_tests() or check_opt_out():
return

# Check if the config file already exists
Expand Down
15 changes: 3 additions & 12 deletions src/pybamm/telemetry.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
from posthog import Posthog
import os
import pybamm
import sys


def check_opt_out():
opt_out = os.getenv("PYBAMM_DISABLE_TELEMETRY", "false").lower() != "false"
config = pybamm.config.read()
if config:
opt_out = opt_out or not config["enable_telemetry"]
return opt_out


class MockTelemetry:
def __init__(self):
class MockLog:
Expand All @@ -27,7 +18,7 @@ def capture(**kwargs):
pass


if check_opt_out():
if pybamm.config.check_opt_out():
_posthog = MockTelemetry()
else:
_posthog = Posthog(
Expand All @@ -43,7 +34,7 @@ def disable():
_posthog.disabled = True


if check_opt_out(): # pragma: no cover
if pybamm.config.check_opt_out(): # pragma: no cover
disable()


Expand All @@ -52,7 +43,7 @@ def capture(event): # pragma: no cover
if pybamm.config.is_running_tests() or _posthog.disabled:
return

if check_opt_out():
if pybamm.config.check_opt_out():
disable()
return

Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ def mock_select(*args, **kwargs):
assert "Timeout reached. Defaulting to not enabling telemetry." in captured.out

def test_generate_and_read(self, monkeypatch, tmp_path):
# Mock is_running_tests to return False
monkeypatch.setattr(pybamm.config, "is_running_tests", lambda: False)

# Mock ask_user_opt_in to return True
monkeypatch.setattr(pybamm.config, "check_opt_out", lambda: False)
monkeypatch.setattr(pybamm.config, "ask_user_opt_in", lambda: True)

# Mock telemetry capture
Expand Down

0 comments on commit 33cdc35

Please sign in to comment.