Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/mpc_api_pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: PyTest mpc_api

on:
push:
branches: [main]
paths:
- "mpc-api/**"
- ".github/workflows/mpc_api_pytest.yml"
pull_request:
paths:
- "mpc-api/**"
- ".github/workflows/mpc_api_pytest.yml"

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
working-directory: ./mpc-api
run: |
python -m pip install --upgrade pip
python -m pip install .[test]

- name: Test mpc_api
working-directory: ./mpc-api
run: |
pytest -v -s
67 changes: 67 additions & 0 deletions .github/workflows/mpc_api_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build and publish mpc-api to PyPI

on:
# Auto-release when mpc-api changes are merged to main
push:
branches: [main]
paths:
- "mpc-api/**"
- ".github/workflows/mpc_api_release.yml"
# Keep manual release trigger as a fallback
release:
types: [created]
workflow_dispatch:

jobs:
deploy:
# Skip if this is a release event that doesn't match our tag pattern
if: >
github.event_name != 'release' ||
startsWith(github.event.release.tag_name, 'mpc-api-v')
runs-on: ubuntu-latest
permissions:
id-token: write

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install build tools
run: |
python -m pip install --upgrade pip
python -m pip install build

- name: Check if version already exists on PyPI
id: version_check
working-directory: ./mpc-api
run: |
VERSION=$(python -c "
import re
text = open('pyproject.toml').read()
print(re.search(r'version\s*=\s*\"(.+?)\"', text).group(1))
")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/mpc-api/$VERSION/json")
if [ "$STATUS" = "200" ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Version $VERSION already exists on PyPI — skipping publish"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Version $VERSION not found on PyPI — will publish"
fi

- name: Build package
if: steps.version_check.outputs.exists == 'false'
working-directory: ./mpc-api
run: python -m build --sdist --wheel --outdir dist/ .

- name: Publish to PyPI
if: steps.version_check.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: mpc-api/dist
44 changes: 44 additions & 0 deletions .github/workflows/mpc_api_testpypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish mpc-api to TestPyPI

on:
pull_request:
paths:
- "mpc-api/**"
- ".github/workflows/mpc_api_testpypi.yml"
workflow_dispatch:

jobs:
testpypi:
runs-on: ubuntu-latest
permissions:
id-token: write

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install build tools
run: |
python -m pip install --upgrade pip
python -m pip install build

- name: Set dev version
working-directory: ./mpc-api
run: |
# Append .devN so every run gets a unique version on TestPyPI
sed -i "s/^version = \"\(.*\)\"/version = \"\1.dev${{ github.run_number }}\"/" pyproject.toml
grep '^version' pyproject.toml

- name: Build package
working-directory: ./mpc-api
run: python -m build --sdist --wheel --outdir dist/ .

- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: mpc-api/dist
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ venv.bak/
# Rope project settings
.ropeproject

# mkdocs documentation
# mkdocs documentation (root level — see also "site/" below for subdirs)
/site

# mypy
Expand All @@ -140,3 +140,18 @@ dmypy.json

# PyCharm
.idea

# Editor / AI tool config
.claude/
.opencode/

# C build artifacts
*.o

# mkdocs build output (any subdirectory)
site/

# digest2 build artifacts
digest2/digest2/digest2
digest2/digest2/digest2.model
digest2/digest2/digest2.obscodes
135 changes: 0 additions & 135 deletions CLAUDE.md

This file was deleted.

3 changes: 3 additions & 0 deletions docs-public/docs/tutorials/api_tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

Tutorials on how to use various of the MPC's APIs are linked below.

**Tip:** The [`mpc_api`](https://github.com/Smithsonian/mpc-public/tree/main/mpc_api) Python package (`pip install mpc-api`) wraps all of these APIs into a single `MPCClient` class. Each tutorial below shows both the raw `requests` approach and the equivalent `mpc_api` usage.

<div id="contents-grid"></div>

- [**Getting Started with `mpc_api`**](notebooks/mpc_tutorial_mpcapi.ipynb)
- [Designation-Identifier API](notebooks/mpc_tutorial_api_designation_identifier.ipynb)
- [Submission API](notebooks/mpc_tutorial_api_submission_submission.ipynb)
- [Submission Status API](notebooks/mpc_tutorial_api_submission_status.ipynb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"In the examples below we use Python code to query the API.\n",
"\n",
"Further information and documentation can be found at:\n",
" - https://docs.minorplanetcenter.net/mpc-ops-docs/apis/action-codes"
" - https://minorplanetcenter.net/mpcops/documentation/action-codes-api/\n",
"\n",
"**Tip:** The [`mpc_api`](https://github.com/Smithsonian/mpc-public/tree/main/mpc_api) Python package (`pip install mpc-api`) wraps all MPC API calls into a single `MPCClient` class and provides an alternative means to access the Action Codes API. Examples using `mpc_api` are shown [below](#using-the-mpc_api-package)."
]
},
{
Expand Down Expand Up @@ -279,6 +281,36 @@
"If someone else gains access to your action code, they could potentially retract or modify your observations. Keep your action codes secure."
]
},
{
"cell_type": "markdown",
"id": "ad6a9ddd-e557-4a22-aac9-e796f2510a9e",
"metadata": {},
"source": [
"# Using the `mpc_api` Package\n",
"\n",
"The [`mpc_api`](https://github.com/Smithsonian/mpc-public/tree/main/mpc_api) Python package wraps all MPC API calls into a single `MPCClient` class.\n",
"\n",
"```bash\n",
"pip install mpc-api\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4bc76261-d14e-4ae0-90ee-b5e7d342a87c",
"metadata": {},
"outputs": [],
"source": [
"from mpc_api import MPCClient\n",
"\n",
"mpc = MPCClient()\n",
"\n",
"# Request action code retrieval (emailed to original submitter)\n",
"# result = mpc.request_action_code(\"your-submission-id\")\n",
"# print(result)"
]
},
{
"cell_type": "markdown",
"id": "summary-header",
Expand Down Expand Up @@ -325,4 +357,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Loading
Loading