diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..c99c7cd8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,70 @@ +name: Publish Python Package + +on: + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build twine + - name: Build package + run: | + python -m build + - name: Upload distribution artifacts + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + - name: Publish to TestPyPI + env: + TWINE_USERNAME: ${{ secrets.TESTPYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TESTPYPI_PASSWORD }} + run: | + twine upload --repository testpypi dist/* + + # Updated verification step with basic import test instead of pytest + - name: Verify package from TestPyPI + run: | + # Wait for TestPyPI to process the upload + sleep 60 + + # Create a new virtual environment for testing + python -m venv test_env + source test_env/bin/activate + + # Install the package from TestPyPI + pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ patientflow + + # Perform a basic import test (more reliable than requiring pytest) + python -c "import patientflow; print(f'Successfully installed patientflow version: {patientflow.__version__}')" + + # Deactivate the virtual environment + deactivate + + # Add a manual approval step before publishing to PyPI + - name: Request approval for PyPI publish + uses: trstringer/manual-approval@v1 + with: + secret: ${{ secrets.GITHUB_TOKEN }} + approvers: zmek + minimum-approvals: 1 + issue-title: "Approve PyPI Deployment for ${{ github.event.release.tag_name }}" + issue-body: "The package has been successfully published to TestPyPI and verified. Please approve to publish to PyPI." + exclude-workflow-initiator-as-approver: false + + - name: Publish to PyPI + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/* diff --git a/README.md b/README.md index 3c450089..c576cdd2 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,8 @@ [![Linting status][linting-badge]][linting-link] [![Documentation status][documentation-badge]][documentation-link] [![License][license-badge]](./LICENSE.md) - - [tests-badge]: https://github.com/zmek/patientflow/actions/workflows/tests.yml/badge.svg @@ -19,14 +15,11 @@ [linting-link]: https://github.com/zmek/patientflow/actions/workflows/linting.yml [documentation-badge]: https://github.com/zmek/patientflow/actions/workflows/docs.yml/badge.svg [documentation-link]: https://github.com/zmek/patientflow/actions/workflows/docs.yml -[conda-badge]: https://img.shields.io/conda/vn/conda-forge/patientflow -[conda-link]: https://github.com/conda-forge/patientflow-feedstock [license-badge]: https://img.shields.io/badge/License-MIT-yellow.svg -[![ORCID](https://img.shields.io/badge/ORCID-0000--0001--7389--1527-green.svg)](https://orcid.org/0000-0001-7389-1527) - - +[pypi-version]: https://img.shields.io/pypi/v/patientflow +[![ORCID](https://img.shields.io/badge/ORCID-0000--0001--7389--1527-green.svg)](https://orcid.org/0000-0001-7389-1527) ## Summary @@ -90,18 +83,22 @@ This snapshot-based approach to predicting demand generalises to other aspects o ### Installation -To install the latest development version, clone it first (so that you have access to the synthetic data and the notebooks) and then install it. +You can install `patientflow` directly from PyPI: ```sh -git clone https://github.com/zmek/patientflow.git -cd patientflow -pip install -e ".[test]" #this will install the code in test mode +pip install patientflow +``` + +To access the example notebooks and synthetic data, clone the repository: +```sh +git clone https://github.com/ucl-coru/patientflow.git +cd patientflow ``` ### Development Installation (optional) -If you plan to contribute to the project or run documentation locally, install the development and documentation dependencies: +If you want to contribute or modify the code, or run documentation locally, install the development and documentation dependencies: ```sh # For development tools (linting, formatting, etc.) @@ -208,8 +205,8 @@ Thank you for contributing! ## Roadmap - [x] Initial Research -- [x] Minimum viable product <-- You are Here -- [ ] Alpha Release +- [x] Minimum viable product +- [x] Alpha Release (PyPI Package) <-- You are Here - [ ] Feature-Complete Release ### Project Team diff --git a/docs/notebooks/0_Set_up_your_environment.md b/docs/notebooks/0_Set_up_your_environment.md index b3602cac..95abd654 100644 --- a/docs/notebooks/0_Set_up_your_environment.md +++ b/docs/notebooks/0_Set_up_your_environment.md @@ -24,8 +24,9 @@ try: import patientflow print(f"✓ patientflow {patientflow.__version__} imported successfully") except ImportError: - print("❌ patientflow not found - please check installation instructions in README") - print(" pip install -e '.[test]'") + print("❌ patientflow not found - please install using one of the following methods:") + print(" From PyPI: pip install patientflow") + print(" For development: pip install -e '.[test]'") except Exception as e: print(f"❌ Error: {e}") ``` diff --git a/docs/notebooks/README.md b/docs/notebooks/README.md index 458bb060..54eadf96 100644 --- a/docs/notebooks/README.md +++ b/docs/notebooks/README.md @@ -36,7 +36,15 @@ A set of notebooks follow, to show how we have used the functions in `patientflo ## Preparing your notebook environment -The `PATH_TO_PATIENTFLOW` environment variable needs to be set so notebooks know where the patientflow repository resides on your computer. You have various options: +### Installation + +You can install the `patientflow` package directly from PyPI: + +```bash +pip install patientflow +``` + +For development purposes or to run these notebooks with the latest code, you may still want to use the Github repository directly. In that case, the `PATH_TO_PATIENTFLOW` environment variable needs to be set so notebooks know where the patientflow repository resides on your computer. You have various options: - use a virtual environment and set PATH_TO_PATIENTFLOW up within that - set PATH_TO_PATIENTFLOW globally on your computer diff --git a/notebooks/0_Set_up_your_environment.ipynb b/notebooks/0_Set_up_your_environment.ipynb index 5f1f4e66..7acce4cc 100644 --- a/notebooks/0_Set_up_your_environment.ipynb +++ b/notebooks/0_Set_up_your_environment.ipynb @@ -59,8 +59,9 @@ " import patientflow\n", " print(f\"✓ patientflow {patientflow.__version__} imported successfully\")\n", "except ImportError:\n", - " print(\"❌ patientflow not found - please check installation instructions in README\")\n", - " print(\" pip install -e '.[test]'\")\n", + " print(\"❌ patientflow not found - please install using one of the following methods:\")\n", + " print(\" From PyPI: pip install patientflow\")\n", + " print(\" For development: pip install -e '.[test]'\")\n", "except Exception as e:\n", " print(f\"❌ Error: {e}\")" ] diff --git a/notebooks/README.md b/notebooks/README.md index e6bfefef..c63b64db 100644 --- a/notebooks/README.md +++ b/notebooks/README.md @@ -36,7 +36,15 @@ A set of notebooks follow, to show how we have used the functions in `patientflo ## Preparing your notebook environment -The `PATH_TO_PATIENTFLOW` environment variable needs to be set so notebooks know where the patientflow repository resides on your computer. You have various options: +### Installation + +You can install the `patientflow` package directly from PyPI: + +```bash +pip install patientflow +``` + +For development purposes or to run these notebooks with the latest code, you may still want to use the Github repository directly. In that case, the `PATH_TO_PATIENTFLOW` environment variable needs to be set so notebooks know where the patientflow repository resides on your computer. You have various options: - use a virtual environment and set PATH_TO_PATIENTFLOW up within that - set PATH_TO_PATIENTFLOW globally on your computer diff --git a/src/patientflow/__init__.py b/src/patientflow/__init__.py index 40661192..3a4e0fc0 100644 --- a/src/patientflow/__init__.py +++ b/src/patientflow/__init__.py @@ -5,6 +5,10 @@ making predictions about emergency demand, elective demand, and hospital discharges. """ -__version__ = "0.2.0" +try: + from ._version import __version__ +except ImportError: + __version__ = "0.0.0" # Fallback for when not installed + __author__ = "Zella King" __email__ = "zella.king@ucl.ac.uk"