Skip to content

refactor: Move imports to top and centralize API URLs#4

Merged
dshkol merged 3 commits intomainfrom
refactor/code-organization
Jan 18, 2026
Merged

refactor: Move imports to top and centralize API URLs#4
dshkol merged 3 commits intomainfrom
refactor/code-organization

Conversation

@dshkol
Copy link
Owner

@dshkol dshkol commented Jan 15, 2026

Summary

  • Move all imports to the top of files (Python PEP 8 convention)
  • Centralize API base URLs as constants in settings.py

Changes

  • Added CENSUSMAPPER_API_URL and CENSUSMAPPER_DATA_URL constants to settings.py
  • Moved inline imports to file tops in: core.py, vectors.py, regions.py, datasets.py, hierarchy.py, intersect_geometry.py, resilience.py
  • Replaced hardcoded URLs with constants across all modules

Why

  • Single source of truth: API URLs defined once, easier to update
  • Python conventions: Imports at top follow PEP 8 and make dependencies visible
  • IDE support: Better autocomplete and static analysis

Test plan

  • All existing tests pass (pytest tests/test_basic.py)
  • No behavioral changes - pure refactor

🤖 Generated with Claude Code

dshkol and others added 3 commits January 14, 2026 22:45
This commit makes two code organization improvements:

1. Move all inline imports to the top of their respective files
   - Follows Python convention (PEP 8)
   - Improves static analysis and IDE support
   - Makes dependencies visible at a glance

2. Centralize API URLs in settings.py
   - CENSUSMAPPER_API_URL for api/v1 endpoints
   - CENSUSMAPPER_DATA_URL for data_sets endpoints
   - Single source of truth eliminates drift risk

Files modified:
- settings.py: Add URL constants
- core.py: Move json, io, hashlib imports; use URL constant
- vectors.py: Move io, warnings imports; use URL constant
- regions.py: Move io import; use URL constant
- datasets.py: Move re import; use URL constant
- hierarchy.py: Move re import to top
- intersect_geometry.py: Reorganize imports; use URL constant
- resilience.py: Move atexit import to top

All existing tests pass unchanged, confirming no behavioral impact.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The unconditional import of RPythonBridge was causing CI failures
since the cross_validation module is only available locally.
Wrap the import in try/except like other test files.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update actions/checkout@v3 → v4 in validate_examples.yml
- Update actions/upload-artifact@v3 → v4 in validate_examples.yml
- Update codecov/codecov-action@v3 → v4 in ci.yml

These v3 actions are deprecated and cause CI warnings/failures.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dshkol dshkol merged commit 92c9d20 into main Jan 18, 2026
5 of 6 checks passed
@dshkol dshkol deleted the refactor/code-organization branch January 18, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant