Skip to content

Commit

Permalink
Automatic publishing on PyPI on new release (#77)
Browse files Browse the repository at this point in the history
* adding version to __init__.py

* add publishing GH Action

* updating pyproject.toml

* updating the GH Action

* Revert "updating the GH Action"

This reverts commit 34689a0.

* updating dependencies

* updating dependencies on documentation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* adding edited to yml

* pypa publishing action

* fix: mesa-frames version

* fix: add version to dynamic

* fix topic

* adding creation of version branch

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
adamamer20 and pre-commit-ci[bot] authored Aug 28, 2024
1 parent 98af5c8 commit 73eae6d
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 15 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Verify PyPI Release
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__)"
- name: Create or recreate version branch
- name: Create or recreate version branch
run: |
CURRENT_VERSION=$(hatch version)
BRANCH_NAME="v$CURRENT_VERSION"
git config user.name github-actions
git config user.email [email protected]
# Delete the branch if it exists (both locally and remotely)
git branch -D $BRANCH_NAME || true
git push origin --delete $BRANCH_NAME || true
# Create and push the new branch
git checkout -b $BRANCH_NAME
git push -u origin $BRANCH_NAME
# Switch back to the main branch
git checkout main
- name: Update to Next Version
run: |
# 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
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"
68 changes: 53 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,56 @@ build-backend = "hatchling.build"

[project]
name = "mesa_frames"
version = "0.1.0-alpha1"
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"
dynamic = [
"version"
]



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

[project.optional-dependencies]
mkdocs = [
"mkdocs-material",
"mkdocs-jupyter",
Expand All @@ -44,26 +72,35 @@ 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"]

[tool.hatch.build.targets.wheel]
packages = ["mesa_frames"]

[tool.hatch.version]
path = "mesa_frames/__init__.py"

[tool.ruff.lint]
select = ["D"]
ignore = ["D101", "D102", "D105"]
Expand All @@ -74,4 +111,5 @@ convention = "numpy"
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D"]
"examples/*" = ["D"]
"docs/*" = ["D"]
"docs/*" = ["D"]

0 comments on commit 73eae6d

Please sign in to comment.