Skip to content

Prepare crimepy-cdc 0.1.0 for PyPI - #2

Merged
apwheele merged 2 commits into
mainfrom
cursor/pypi-packaging-fd8b
Nov 21, 2026
Merged

apwheele merged 2 commits into
mainfrom
cursor/pypi-packaging-fd8b

Conversation

@apwheele

@apwheele apwheele commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Replaces setup.py with a setuptools pyproject.toml so the first release can be published as crimepy-cdc (the name crimepy is taken) while the import stays import crimepy. Version is 0.1.0. Nothing was published and no tag was pushed.

requires-python is >=3.11. The code uses scipy.stats.false_discovery_control (scipy>=1.11). Current wheels for numpy, scipy, pandas, geopandas, matplotlib, scikit-learn, shapely, and pyproj all support 3.11; several of the latest releases already require 3.12, so 3.10 and earlier will not resolve a current install. Python 3.6 from the old setup.py was not viable.

License is the SPDX expression MIT plus the existing LICENSE file (License-Expression and License-File in the wheel metadata). setuptools 77+ rejects the old License :: OSI Approved :: MIT License classifier when an SPDX expression is set, so that classifier is omitted.

cdcplot.add_logo now loads a path string with matplotlib's imread. A test passes the bundled logo path and checks that the inset image is drawn.

Distributions

Artifact Size
crimepy_cdc-0.1.0-py3-none-any.whl 5,802,241 bytes (5.6 MiB)
crimepy_cdc-0.1.0.tar.gz 5,813,801 bytes (5.6 MiB)

twine check --strict passes on both. Almost all of the size is dallasdata.csv.zip (5,408,512 bytes; about 25 MB uncompressed).

The wheel contains the package modules plus the six files the code actually opens:

  • dallasdata.csv.zip, Dallas_MainArea_Proj.zip, CarrolltonGrid.csv.zip
  • Edges_Gang1.csv, Nodes_Gang1.csv
  • CDCWLineRec.PNG (uppercase extension, so the old *.png pattern missed it)

Loaders use importlib.resources.as_file. A fresh venv install of the wheel imports every crimepy module and loads each of those files. Tests pass from the checkout, including the bundled-data tests and the add_logo path test.

Left out of the wheel and sdist (still in git for the notebooks): bronx_data.csv, bronx_precinct.gpkg, bronx_uberhex.gpkg, CDC_Logo.svg, plus notebooks, images/, analysis outputs, and .ipynb_checkpoints. crimepy.egg-info was gitignored and not tracked.

Dependencies

Core: beautifulsoup4, cycler, folium, geopandas, lxml, matplotlib, networkx, numpy, openpyxl, pandas, pyproj, requests, scikit-learn, scipy>=1.11, shapely.

Newly declared because the code imports them directly: numpy, pyproj, cycler, and lxml (BeautifulSoup(..., "lxml")). shapely and openpyxl stay required (query.read_data calls read_excel). Duplicate geopandas/folium entries are gone. importlib_resources is dropped in favor of the stdlib.

Moved into extras. Imports that used to run at module import are now lazy and name the extra in the error:

Extra Packages Why
network osmnx pmed.get_distance / street networks
opt pulp, highspy, libpysal districting and site selection. highspy is not imported; PuLP uses it for the HiGHS solver the districting notebooks look for in pmed.av_solv
notebooks jupyter, ipycytoscape, contextily notebooks and domset.color_cytoscape
gbtm statsmodels Poisson-mixture GBTM only. It was imported eagerly and was missing from install_requires
tableau TableauScraper only the QueryData notebook imports it
all everything above
test pytest CI

Dropped entirely (nothing in the library or notebooks imports them, or the import was unused): matplotlib-map-utils, tabulate, and matplotlib-scalebar (ScaleBar was imported in geo.py and never called). contextily was imported in geo.py and never used; notebooks import it themselves, so it lives in [notebooks].

import crimepy.pmed still exposes pmed.pulp and pmed.av_solv. Those attributes import PuLP on first use, which is what the patrol and drone notebooks read.

CI

  • .github/workflows/ci.yml runs pytest on Python 3.11, 3.12, and 3.13.
  • .github/workflows/publish.yml runs on v* tags, builds once, runs twine check --strict, then publishes that artifact with pypa/gh-action-pypi-publish@release/v1 in the pypi environment. id-token: write is only on the publish job (that job also has actions: read so it can download the build artifact).

Concerns

  • Bronx sample files stay in the git tree because the GBTM and scaled-SPPT notebooks open them by path. They are not installed with the package, so those notebooks need a clone, not a bare pip install.
  • Patrol-district notebooks need both [network] and [opt].
  • The sdist is the package, tests, and project metadata. GitHub Actions reads workflows from the git tag, not from the sdist.
  • Trusted publishing still needs a PyPI project crimepy-cdc and a GitHub environment named pypi before the first v* tag.
Open in Web Open in Cursor 

cursoragent and others added 2 commits November 21, 2026 17:20
Replace setup.py with pyproject.toml, ship only the data files the
library loads, and move optional imports behind extras.

Co-authored-by: Andrew Wheeler <apwheele@users.noreply.github.com>
Load path strings with matplotlib's imread, and cover that case with a test.

Co-authored-by: Andrew Wheeler <apwheele@users.noreply.github.com>
@apwheele
apwheele merged commit e28c817 into main Nov 21, 2026
3 checks passed
@apwheele
apwheele deleted the cursor/pypi-packaging-fd8b branch November 21, 2026 17:26
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.

2 participants