Refactor into submodules #19

Closed
opened 2026-04-28 08:07:09 +10:00 by unkinben · 2 comments
Owner

Refactor the codebase into submodules.

E.g.

cache.redis
database.postgres
remote.{helm,npm,python,rpm,generic}

There should be no function change with this refactor

Refactor the codebase into submodules. E.g. cache.redis database.postgres remote.{helm,npm,python,rpm,generic} There should be no function change with this refactor
Author
Owner

Resolution

Refactored the flat module structure into proper subpackages with no functional changes.

Changes made:

  • cache/redis.py — RedisCache moved from cache.py; cache/__init__.py re-exports it for backwards compatibility
  • database/postgres.py — DatabaseManager moved from database.py; database/__init__.py re-exports it
  • remote/base.py — get_content_type() extracted from main.py
  • remote/python.py — PyPI URL construction and HTML rewriting
  • remote/npm.py — npm metadata URL rewriting
  • remote/helm.py — Helm index.yaml URL rewriting
  • remote/rpm.py — RPM remote (uses base content type; mutable patterns remain in config.py)
  • remote/generic.py — generic HTTP remotes

How main.py was updated: _resolve_content() and construct_remote_url() now delegate to the relevant remote.* submodule instead of containing inline per-package logic. _get_content_type() removed from main.py.

All 187 existing tests pass. README updated with a code layout diagram.

Potential future improvements:

  • storage.py and docker_auth.py could similarly be moved to storage/s3.py and remote/docker.py
  • The remote/ modules currently only contain content resolution; route logic (auth headers, URL building) could be further extracted per-package
## Resolution Refactored the flat module structure into proper subpackages with no functional changes. **Changes made:** - `cache/redis.py` — RedisCache moved from cache.py; cache/__init__.py re-exports it for backwards compatibility - `database/postgres.py` — DatabaseManager moved from database.py; database/__init__.py re-exports it - `remote/base.py` — get_content_type() extracted from main.py - `remote/python.py` — PyPI URL construction and HTML rewriting - `remote/npm.py` — npm metadata URL rewriting - `remote/helm.py` — Helm index.yaml URL rewriting - `remote/rpm.py` — RPM remote (uses base content type; mutable patterns remain in config.py) - `remote/generic.py` — generic HTTP remotes **How main.py was updated:** _resolve_content() and construct_remote_url() now delegate to the relevant remote.* submodule instead of containing inline per-package logic. _get_content_type() removed from main.py. All 187 existing tests pass. README updated with a code layout diagram. **Potential future improvements:** - storage.py and docker_auth.py could similarly be moved to storage/s3.py and remote/docker.py - The remote/ modules currently only contain content resolution; route logic (auth headers, URL building) could be further extracted per-package
Author
Owner

Additional refactor: storage/s3, auth/docker, and artifact/ handler split

storage/s3.py — S3Storage moved from storage.py. storage/__init__.py re-exports for backwards compat.

auth/docker.py — Docker Bearer token logic moved from docker_auth.py. docker_auth.py kept as a thin shim (re-exports all public symbols including _token_cache) so existing tests and import paths continue to work.

artifact/ subpackage — All route handler logic extracted from main.py. Each @app.route() in main.py is now a single-line delegation:

  • artifact/proxy.py — remote GET, caching, mutable revalidation, UpstreamUnreachable
  • artifact/local.py — local repo upload/check/delete
  • artifact/docker.py — Docker Registry v2 proxy + ping
  • artifact/discovery.py — GitHub release discovery + bulk cache
  • artifact/flush.py — cache flush

Tests updated to patch helpers at their new locations (artifactapi.artifact.proxy.*).

Wheel build confirmed with uv build. Docker stack (make docker-up) starts clean; /health, /, /v2/ all respond correctly.

## Additional refactor: storage/s3, auth/docker, and artifact/ handler split **storage/s3.py** — S3Storage moved from storage.py. storage/__init__.py re-exports for backwards compat. **auth/docker.py** — Docker Bearer token logic moved from docker_auth.py. docker_auth.py kept as a thin shim (re-exports all public symbols including _token_cache) so existing tests and import paths continue to work. **artifact/ subpackage** — All route handler logic extracted from main.py. Each @app.route() in main.py is now a single-line delegation: - artifact/proxy.py — remote GET, caching, mutable revalidation, UpstreamUnreachable - artifact/local.py — local repo upload/check/delete - artifact/docker.py — Docker Registry v2 proxy + ping - artifact/discovery.py — GitHub release discovery + bulk cache - artifact/flush.py — cache flush Tests updated to patch helpers at their new locations (artifactapi.artifact.proxy.*). Wheel build confirmed with uv build. Docker stack (make docker-up) starts clean; /health, /, /v2/ all respond correctly.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/artifactapi#19