Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic publishing on PyPI on new release #77

Merged
merged 16 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
88 changes: 88 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Update Version, Test, Publish to PyPI, and Upload Release Artifacts

on:
release:
types: [created, edited]

jobs:
build-test-publish-upload:
runs-on: ubuntu-latest
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Set release version
run: |
# Get the tag from the GitHub release
TAG=${GITHUB_REF#refs/tags/}
# Remove 'v' prefix if present
VERSION=${TAG#v}
hatch version $VERSION
- name: Build package
run: hatch build
- name: Run tests
run: hatch run test:pytest
- name: Retrieve and mint OIDC token
# (https://docs.pypi.org/trusted-publishers/using-a-publisher/)
run: |
adamamer20 marked this conversation as resolved.
Show resolved Hide resolved
# retrieve the ambient OIDC token
resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi")
oidc_token=$(jq -r '.value' <<< "${resp}")

# exchange the OIDC token for an API token
resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}")
api_token=$(jq -r '.token' <<< "${resp}")

# mask the newly minted API token, so that we don't accidentally leak it
echo "::add-mask::${api_token}"

# see the next step in the workflow for an example of using this step output
echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}"
- name: Publish to PyPI
env:
PYPI_API_TOKEN: ${{ steps.mint-token.outputs.api-token }}
run: |
hatch publish -u __token__ -a $PYPI_API_TOKEN
- name: Upload Release Asset
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: "dist/*"
token: ${{ secrets.GITHUB_TOKEN }}
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true
- name: Verify PyPI Release and Update to Next Version
run: |
# Verify PyPI release
PACKAGE_NAME="mesa_frames"
CURRENT_VERSION=$(hatch version)
pip install $PACKAGE_NAME==$CURRENT_VERSION
python -c "import mesa_frames; print(mesa_frames.__version__)"

# Bump to next development version
hatch version patch
hatch version dev

# Get the new version
NEW_VERSION=$(hatch version)

# Commit and push the version bump
git config user.name github-actions
git config user.email [email protected]
git add mesa-frames/__init__.py
git commit -m "Bump version to $NEW_VERSION [skip ci]"
git push
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ conda activate myenv
Then, to install mesa-frames itself:

```bash
# For pandas backend
pip install -e .[pandas]
# Alternatively, for Polars backend
pip install -e .[polars]
pip install -e .
```

### Installing in a Python Virtual Environment
Expand All @@ -69,10 +66,7 @@ source myenv/bin/activate # On Windows, use `myenv\Scripts\activate`
Then, to install mesa-frames itself:

```bash
# For pandas backend
pip install -e .[pandas]
# Alternatively, for Polars backend
pip install -e .[polars]
pip install -e .
```

## Usage
Expand Down
4 changes: 1 addition & 3 deletions docs/general/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ Check out our performance graphs comparing mesa and mesa-frames for the [Boltzma
```bash
git clone https://github.com/adamamer20/mesa_frames.git
cd mesa_frames
pip install -e .[pandas] # For pandas backend
# or
pip install -e .[polars] # For Polars backend
pip install -e .
```

### Basic Usage
Expand Down
2 changes: 2 additions & 0 deletions mesa_frames/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ def __init__(self, width, height):
"GridPandas",
"GridPolars",
]

__version__ = "0.1.0alpha"
2 changes: 1 addition & 1 deletion mesa_frames/concrete/pandas/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def _prepare_df(df: pd.DataFrame, on: str | list[str] | None) -> pd.DataFrame:
# Reset index if it is not used as a key to keep it in the DataFrame
if df.index.name is not None or df.index.names[0] is not None:
df = df.reset_index()
df = df.set_index(on)
df = df.set_index(on)
return df

left_index = False
Expand Down
59 changes: 45 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,52 @@ build-backend = "hatchling.build"

[project]
name = "mesa_frames"
version = "0.1.0-alpha1"
version = "mesa-frames/__init__.py"
description = "An extension to the Mesa framework which uses pandas/Polars DataFrames for enhanced performance"
authors = [
{ name = "Adam Amer" },
{ name = "Adam Amer"},
]
license = { text = "MIT" }
readme = "README.md"
keywords = [
"simulation",
"simulation-environment",
"gis",
"pandas",
"simulation-framework",
"agent-based-modeling",
"complex-systems",
"spatial-models",
"mesa",
"complexity-analysis",
"modeling-agents",
"agent-based-modelling"
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering::Artificial Life",
]
dependencies = [
"numpy~=1.26",
"typing-extensions>=4.9" #typing-extensions.Self added in 4.9
]

[project.optional-dependencies]
pandas = [
"pandas~=2.2",
"pyarrow",
"typing-extensions>=4.9", #typing-extensions.Self added in 4.9
## pandas
"pandas>=2.2",
"pyarrow", #for conversion to pandas
#"geopandas" (only after GeoGrid / ContinousSpace is implemented)
]
polars = [
## polars
"polars>=1.0.0", #polars._typing (see mesa_frames.types) added in 1.0.0
#"geopolars" (currently in pre-alpha)
]
requires-python = ">=3.8"

[project.urls]
Documentation = "https://adamamer20.github.io/mesa-frames"
Repository = "https://github.com/adamamer20/mesa-frames.git"

[project.optional-dependencies]

mkdocs = [
"mkdocs-material",
Expand All @@ -44,20 +69,26 @@ sphinx = [
]

docs = [
"mesa_frames[pandas, polars, mkdocs, sphinx]",
"mesa_frames[mkdocs, sphinx]",
# Readme Script
"perfplot",
"seaborn"
]

dev = [
"mesa_frames[pandas, polars, docs]",
test = [
"pytest",
"pytest-cov",
"typeguard",
]

dev = [
"mesa_frames[test, docs]",
"mesa",
]

[tool.hatch.envs.test]
features = ["test"]

[tool.hatch.envs.dev] #Allows installing dev as virtual env
features = ["dev"]

Expand Down
Loading