Skip to content

Convert nmaci to a pip-installable Python package#7

Open
OleBialas wants to merge 9 commits intoneuromatch:mainfrom
OleBialas:main
Open

Convert nmaci to a pip-installable Python package#7
OleBialas wants to merge 9 commits intoneuromatch:mainfrom
OleBialas:main

Conversation

@OleBialas
Copy link
Copy Markdown

Summary

This PR converts nmaci from a collection of standalone scripts (downloaded as a tarball by course repo CI) into a proper pip-installable Python package with a unified CLI entry point.

What changed

Package structure (src/ layout with hatchling build backend)

  • Added pyproject.toml — declares dependencies, entry point, and build config
  • Source moved to src/nmaci/ — one module per command, importable as a package
  • src/nmaci/cli.py — single nmaci entry point dispatching to subcommands via lazy importlib imports
  • src/nmaci/__main__.py — enables python -m nmaci <command>

Scripts refactored

  • generate_book.py, generate_book_dl.py, parse_html_for_errors.py — removed module-level sys.argv access that crashed on import
  • select_notebooks.py, find_unreferenced_content.py — wrapped bare __main__ blocks into main(arglist=None)
  • All modules now follow the main(arglist=None) convention (argparse reads sys.argv[1:] when arglist is None)

Backward-compatible shims (scripts/)

  • All scripts in scripts/ are now 3-line shims that delegate to src/nmaci/
  • Course repo CI (python ci/process_notebooks.py) continues to work unchanged as long as nmaci is installed

Tests & CI

  • Tests import from nmaci.* directly; subprocess tests use python -m nmaci <command>
  • CI switched from pip install -r requirements.txt to uv sync --extra dev
  • from __future__ import annotations added to fix Path | str union syntax on Python 3.9

Backward compatibility

Course repos that currently do python ci/process_notebooks.py <args> are unaffected — the shims preserve that interface. The only new requirement is that nmaci be installed as a package, which the updated setup-ci-tools action handles.

Testing

Copy link
Copy Markdown

@iamzoltan iamzoltan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. left some small nits

Comment on lines 3 to +15
"README.md"
],
"imageSize": 100,
"commit": false,
"commitType": "docs",
"commitConvention": "angular",
"contributors": [
{
"login": "OleBialas",
"name": "Ole Bialas",
"avatar_url": "https://avatars.githubusercontent.com/u/38684453?v=4",
"profile": "https://github.com/OleBialas",
"contributions": [
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets remove this change. we can add that using the all contributors bot on the main repo automatically

uses: astral-sh/setup-uv@v5
with:
python-version: 3.9
python-version: "3.9"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets update this to 3.10

Comment on lines +2 to +4
[![CI](https://github.com/OleBialas/nmaci/actions/workflows/ci.yaml/badge.svg)](https://github.com/OleBialas/nmaci/actions/workflows/ci.yaml)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets also remove these changes. We should create a new PR with updated docs that reference the main repo

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