Skip to content

Commit f0cd8f8

Browse files
JacobCoffeeclaude
andcommitted
fix: scope PYTHONDONTWRITEBYTECODE to test targets only
Addresses review feedback to prevent unintended side effects from global PYTHONDONTWRITEBYTECODE export. **Problem:** With .EXPORT_ALL_VARIABLES enabled, setting PYTHONDONTWRITEBYTECODE=1 globally affected ALL make targets (dev servers, docker builds, docs), which could: - Slow down dev servers by preventing .pyc caching - Affect docker builds that benefit from .pyc files - Impact other tooling unnecessarily **Solution:** - Removed global PYTHONDONTWRITEBYTECODE variable from Makefile - Set PYTHONDONTWRITEBYTECODE=1 inline for test-related targets only - Removed from .env.example (no longer needed) - Kept in CI workflows (appropriate for CI environment) - Added comment explaining the scoping decision **Affected targets:** - test: PYTHONDONTWRITEBYTECODE=1 pytest - coverage: PYTHONDONTWRITEBYTECODE=1 pytest + coverage **Unaffected targets (benefit from .pyc caching):** - run-dev-server, run-dev-bot (faster restarts) - docker-* (faster container startup) - docs-* (faster builds) - install, type-check, lint (faster execution) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 2f93d31 commit f0cd8f8

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ WEB_URL=https://byte-bot.app
1313
SECRET_KEY=ThisIsNotAProductionToken
1414
ENVIRONMENT=dev
1515
DEBUG=True
16-
PYTHONDONTWRITEBYTECODE=1
1716

1817
# --- Database Settings
1918
# Prefix is ``DB_`` for all Database settings

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ USING_UV = $(shell grep "tool.uv" pyproject.toml && echo "yes")
99
VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')")
1010
UV_OPTS ?=
1111
UV ?= uv $(UV_OPTS)
12-
PYTHONDONTWRITEBYTECODE = 1
1312

1413
.EXPORT_ALL_VARIABLES:
1514

@@ -118,12 +117,15 @@ ruff-noqa: ## Runs Ruff, adding noqa comments to disable warnings
118117
type-check: ## Run ty type checker
119118
@$(UV) run --no-sync ty check
120119

120+
# PYTHONDONTWRITEBYTECODE is set inline for test targets to prevent .pyc generation
121+
# during testing, which reduces I/O overhead. It's NOT set globally to avoid affecting
122+
# dev servers, docker builds, and other targets that benefit from .pyc caching.
121123
test: ## Run the tests
122-
@$(UV) run --no-sync pytest
124+
@PYTHONDONTWRITEBYTECODE=1 $(UV) run --no-sync pytest
123125

124126
coverage: ## Run the tests and generate coverage report
125-
@$(UV) run --no-sync pytest --cov=byte_bot
126-
@$(UV) run --no-sync coverage html
127+
@PYTHONDONTWRITEBYTECODE=1 $(UV) run --no-sync pytest --cov=byte_bot
128+
@PYTHONDONTWRITEBYTECODE=1 $(UV) run --no-sync coverage html
127129
@$(UV) run --no-sync coverage xml
128130

129131
check-all: lint type-check fmt test ## Run all linting, formatting, and tests

tests/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,10 @@ Current test execution time (1036 tests total):
204204
Following best practices from [awesome-pytest-speedup](https://github.com/zupo/awesome-pytest-speedup), we've implemented several optimizations:
205205

206206
#### 1. PYTHONDONTWRITEBYTECODE=1
207-
- **Impact**: Reduces I/O overhead
208-
- **Location**: `Makefile`, `.github/workflows/ci.yml`, `.env.example`
209-
- Prevents `.pyc` file generation during test runs
207+
- **Impact**: Reduces I/O overhead during test runs
208+
- **Location**: Scoped to test targets in `Makefile`, set globally in `.github/workflows/ci.yml`
209+
- Prevents `.pyc` file generation during testing
210+
- **Note**: NOT set globally to avoid affecting dev servers, Docker builds, and other targets that benefit from .pyc caching
210211

211212
#### 2. Disabled Unnecessary Builtin Plugins
212213
- **Impact**: Faster collection

0 commit comments

Comments
 (0)