Skip to content

Commit 9895b68

Browse files
committed
moved to pyproject.toml
1 parent 7250da5 commit 9895b68

13 files changed

Lines changed: 196 additions & 3026 deletions

File tree

.github/workflows/main.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v2
1515
with:
16-
fetch-depth: 0
16+
fetch-depth: 0 # This is important for setuptools_scm to get the git history
1717
- name: Set up Python 3.8
1818
uses: actions/setup-python@v2
1919
with:
@@ -22,6 +22,17 @@ jobs:
2222
run: |
2323
# $CONDA is an environment variable pointing to the root of the miniconda directory
2424
echo $CONDA/bin >> $GITHUB_PATH
25+
- name: Extract tag version for conda build
26+
id: get_version
27+
run: |
28+
# Extract the tag name without 'refs/tags/' prefix
29+
GIT_TAG=${GITHUB_REF#refs/tags/}
30+
# Set tag as environment variable for conda build
31+
echo "GIT_DESCRIBE_TAG=$GIT_TAG" >> $GITHUB_ENV
32+
# Also set SETUPTOOLS_SCM_PRETEND_VERSION for consistent versioning
33+
echo "SETUPTOOLS_SCM_PRETEND_VERSION=$GIT_TAG" >> $GITHUB_ENV
34+
# Print for verification
35+
echo "Using version: $GIT_TAG"
2536
- name: Conda build package and upload to anaconda.org
2637
env:
2738
ANACONDA_CHANNEL_UPLOAD_TOKEN: ${{ secrets.ANACONDA_CHANNEL_UPLOAD_TOKEN }}
@@ -30,6 +41,16 @@ jobs:
3041
source $CONDA/etc/profile.d/conda.sh
3142
conda activate test_dmsbatch
3243
conda config --set anaconda_upload yes
44+
echo "Building with GIT_DESCRIBE_TAG=$GIT_DESCRIBE_TAG and SETUPTOOLS_SCM_PRETEND_VERSION=$SETUPTOOLS_SCM_PRETEND_VERSION"
3345
conda build -c defaults -c conda-forge --user cadwr-dms --token "$ANACONDA_CHANNEL_UPLOAD_TOKEN" conda.recipe
3446
conda activate
3547
conda remove -n test_dmsbatch --all
48+
49+
- name: Build and upload PyPI package
50+
if: ${{ false }} # Disabled by default - enable when ready to publish to PyPI
51+
env:
52+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
53+
run: |
54+
python -m pip install --upgrade pip build twine
55+
python -m build
56+
python -m twine upload --skip-existing dist/* --username __token__ --password "$PYPI_API_TOKEN"

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,19 @@ target/
8989
# pyenv python configuration file
9090
.python-version
9191

92+
# setuptools_scm generated version file
93+
dmsbatch/_version.py
94+
95+
# conda build and pip build artifacts
96+
conda-bld/
97+
.eggs/
98+
pip-wheel-metadata/
99+
*.conda
100+
101+
# jupyter notebook specific
102+
.ipython/
103+
.jupyter/
104+
.local/
105+
92106
# include all sample ymls:
93107
!sample_configs/*.yml

MANIFEST.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
include versioneer.py
1+
include LICENSE
2+
include README.md
3+
include dmsbatch/_version.py.template
4+
recursive-include dmsbatch/templates *

README-pyproject.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Migration from setup.py to pyproject.toml
2+
3+
This project has been migrated from a classic `setup.py` configuration to a modern `pyproject.toml` configuration. Here are the key changes and how to work with the new setup:
4+
5+
## Package Structure
6+
7+
- `pyproject.toml`: Main configuration file for building, dependencies, and metadata
8+
- `setup.py`: Minimal file that provides compatibility with older tools
9+
- Automated versioning using setuptools_scm based on git tags
10+
11+
## Building and Development
12+
13+
For development:
14+
```bash
15+
pip install -e .
16+
```
17+
18+
For building:
19+
```bash
20+
pip install build
21+
python -m build
22+
```
23+
24+
## Conda Build
25+
26+
The conda recipe has been updated to work with the new pyproject.toml structure. You can build a conda package using:
27+
28+
```bash
29+
conda build conda.recipe
30+
```
31+
32+
## Version Management with setuptools_scm
33+
34+
The project now uses setuptools_scm for automatic version determination from git tags:
35+
36+
1. Tag your release: `git tag 2025.05.23`
37+
2. The version will automatically be determined from the git metadata
38+
3. Format: `{tag}.post{commits}+{hash}.d{date}` (e.g., `2025.05.23.post2+g7250da5.d20250526`)
39+
40+
## Dependencies
41+
42+
All dependencies are now specified in `pyproject.toml`. Make sure to keep both the pyproject.toml and conda.recipe/meta.yaml files in sync when adding new dependencies.
43+
44+
## CI/CD with GitHub Actions
45+
46+
The GitHub workflow has been updated to work with setuptools_scm:
47+
48+
1. It checks out the complete git history with `fetch-depth: 0` to ensure setuptools_scm has access to all tags
49+
2. It sets the `SETUPTOOLS_SCM_PRETEND_VERSION` environment variable to ensure consistent versioning
50+
3. The version is extracted from the git tag and used for both conda and PyPI (when enabled) builds
51+
52+
When a new version is tagged and pushed to GitHub, the workflow will automatically:
53+
- Build a conda package with the correct version
54+
- Upload it to the specified Anaconda channel

conda.recipe/meta.yaml

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
1-
{% set data = load_setup_py_data() %}
1+
{% set name = "dmsbatch" %}
2+
{% set version = environ.get('GIT_DESCRIBE_TAG', '0.0.0.dev0') %}
23

34
package:
4-
name: dmsbatch
5-
version: {{ data['version'] }}
5+
name: {{ name|lower }}
6+
version: {{ version }}
67

78
source:
89
path: ..
910

1011
build:
11-
# If the installation is complex, or different between Unix and Windows, use
12-
# separate bld.bat and build.sh files instead of this key. Add the line
13-
# "skip: True # [py<35]" (for example) to limit to Python 3.5 and newer, or
14-
# "skip: True # [not win]" to limit to Windows.
1512
script: {{ PYTHON }} -m pip install --no-deps --ignore-installed -vv .
1613
noarch: python
17-
1814
entry_points:
19-
{% for entry in data['entry_points']['console_scripts'] %}
20-
- {{ entry.split('=')[0].strip() }} = {{ entry.split('=')[1].strip() }}
21-
{% endfor %}
22-
15+
- dmsbatch = dmsbatch.cli:main
2316

2417
requirements:
25-
# if you need compilers, uncomment these
26-
# read more at https://docs.conda.io/projects/conda-build/en/latest/resources/compiler-tools.html
27-
# build:
28-
# - {{ compilers('c') }}
2918
host:
3019
- python
3120
- pip
21+
- setuptools >=45
22+
- wheel
23+
- setuptools_scm >=6.2
3224
run:
3325
- python
34-
# dependencies are defined in setup.py
35-
{% for dep in data['install_requires'] %}
36-
- {{ dep.lower() }}
37-
{% endfor %}
26+
- azure-batch >=11.0.0
27+
- azure-storage-blob >=2.1.0
28+
- azure-mgmt-resource >=18.0.0
29+
- azure-identity >=1.5.0
3830

3931
test:
4032
source_files:
@@ -48,6 +40,6 @@ test:
4840
- dmsbatch
4941
about:
5042
home: https://github.com/CADWRDeltaModeling/azure_dms_batch
51-
summary: Azure Batch for Delta Modeling Section
52-
license: {{ data.get('license') }}
43+
summary: Azure Batch for Delta Modeling Section
44+
license: MIT
5345
license_file: LICENSE

dmsbatch/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from ._version import get_versions
2-
__version__ = get_versions()['version']
3-
del get_versions
4-
#
1+
try:
2+
from ._version import __version__
3+
except ImportError:
4+
__version__ = "0.0.0"
5+
56
from .commands import create_batch_client, create_blob_client, query_yes_no
67
from .commands import AzureBatch, AzureBlob
7-
8-
from . import _version
9-
__version__ = _version.get_versions()['version']

0 commit comments

Comments
 (0)