Skip to content

chore: slim analytics package to the static-site core #4912

Description

@NoopDog

Part 3 of retiring the legacy analytics report formats — do this only after #4910 and #4911 are merged (they remove the in-repo consumers of the code deleted here). Completing the dependency-burden rationale from #4910: after this ticket, the package's install_requires no longer pulls gspread, gspread-formatting, or matplotlib, and consuming repos (anvil-portal, ncpi-dataset-catalog) can drop those pins from their dependabot-watched requirements.

Current structure (verified)

  • sheets_api.py (493 lines) — pure gspread/Drive/Sheets formatting; only legacy consumers.
  • sheets_elements.py (606 lines) — mostly GA4 element functions the static site needs (get_page_views_change, get_page_views_over_time_df, get_outbound_links_change, get_index_filter_selected_change, get_index_table_download_df, get_bounds_for_month_and_prev, ADDITIONAL_DATA_BEHAVIOR), plus Sheets-only *_FORMATTING dicts importing COLUMN_FORMAT_OPTIONS from sheets_api.
  • charts.py (454 lines) — core GA fetch helpers (get_data_df, get_df_over_time) needed by _sheets_utils, mixed with matplotlib/IPython notebook plotting.
  • api.py, entities.py, _sheets_utils.py, static_site/ — the keep-side core.

Steps

  1. Extract get_data_df / get_df_over_time (and any pure-fetch helpers they need) from charts.py into a new module (e.g. ga_data.py); update _sheets_utils.py imports.
  2. Delete the remainder of charts.py (matplotlib/IPython plotting), and delete sheets_api.py.
  3. Strip the *_FORMATTING dicts and the from .sheets_api import COLUMN_FORMAT_OPTIONS import from sheets_elements.py; rename it (e.g. elements.py) and update static_site/fetch.py (from .. import sheets_elements as elements → the new name). Optionally rename _sheets_utils.py similarly.\n4. setup.py: remove gspread, gspread-formatting, matplotlib from install_requires; bump the version (breaking change for any straggler consumer of the deleted modules).
  4. Regenerate analytics/requirements.txt without the removed packages.

Verification

  • python -c 'from analytics.static_site import generate_site' succeeds in a fresh venv without gspread/matplotlib installed.
  • Run one full generate_static_site.py (anvil-explorer) — output data unchanged.

Downstream

After merge, anvilproject/anvil-portal (which installs this package from main) and NIH-NCPI/ncpi-dataset-catalog can finish slimming their requirements — tracked in their per-repo retirement tickets.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions