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

ci: publish to conda #157

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
46 changes: 46 additions & 0 deletions .conda/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
schema_version: 1

context:
name: openfisca-country_template
version: 8.0.0

package:
name: ${{ name|lower }}
version: ${{ version }}

source:
path: ..

build:
noarch: python
script: pip install . -v
files:
include:
- "**/*.py"
- "**/*.json"
- "**/*.yaml"

requirements:
host:
- numpy
- pip
- python
- setuptools >=61.0
run:
- numpy
- python
- openfisca-core-api >=43

tests:
- python:
imports:
- openfisca_country_template

about:
summary: OpenFisca Rules as Code model for Country-Template.
license: AGPL-3.0
license_file: LICENSE

extra:
recipe-maintainers:
- bonjourmauko
9 changes: 9 additions & 0 deletions .conda/variants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
numpy:
- "1.24"
- "1.25"
- "1.26"

python:
- "3.9"
- "3.10"
- "3.11"
21 changes: 16 additions & 5 deletions .github/is-version-number-acceptable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@ then
exit 0
fi

current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273
# parsing with tomllib is complicated, see
# https://github.com/python-poetry/poetry/issues/273
python_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2)

if [[ ! $current_version ]]
# we do the same for conda
conda_version=$(grep '^ version: \d' .conda/recipe.yaml | cut -d ' ' -f 4)

if [[ ! $python_version || ! $conda_version ]]
then
echo "Error getting current version"
exit 1
fi

if git rev-parse --verify --quiet $current_version
if [[ "$python_version" != "$conda_version" ]]
then
echo "Python ($python_version) and Conda ($conda_version) versions do not match"
exit 1
fi

if git rev-parse --verify --quiet "$python_version"
then
echo "Version $current_version already exists in commit:"
git --no-pager log -1 $current_version
echo "Version $python_version already exists in commit:"
git --no-pager log -1 "$python_version"
echo
echo "Update the version number in pyproject.toml before merging this branch into main."
echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated."
Expand Down
32 changes: 27 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ on:
workflow_call:

jobs:
build-and-cache:
python-build-and-cache:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error.

- name: Cache build
uses: actions/cache@v4
with:
Expand All @@ -23,12 +23,34 @@ jobs:
restore-keys: |
build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
build-${{ env.pythonLocation }}-

- name: Build package
run: make build

- name: Cache release
uses: actions/cache@v4
with:
path: dist
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}

conda-build-and-cache:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache build
uses: actions/cache@v4
with:
path: /tmp/conda-bld
key: build-conda-${{ hashFiles('.conda/recipe.yaml') }}-${{ github.sha }}
restore-keys: |
build-conda-${{ hashFiles('.conda/recipe.yaml') }}
build-conda-

- name: Build conda package
uses: prefix-dev/rattler-build-action@v0.2.16
with:
build-args: --channel openfisca --channel conda-forge --output-dir /tmp/conda-bld
recipe-path: .conda/recipe.yaml
upload-artifact: false
28 changes: 28 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ jobs:
pip install twine
twine check dist/*

test-conda:
runs-on: ubuntu-22.04
needs: [ build ]
steps:
- uses: actions/checkout@v4

- name: Setup conda
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: openfisca
miniforge-version: latest
python-version: 3.9.12
use-mamba: true

- name: Restore build
uses: actions/cache@v4
with:
path: /tmp/conda-bld
key: build-conda-${{ hashFiles('.conda/recipe.yaml') }}-${{ github.sha }}

- name: Install package
shell: bash -l {0}
run: mamba install --channel file:///tmp/conda-bld --channel openfisca openfisca-country_template

- name: Test conda package
shell: bash -l {0}
run: openfisca test openfisca_country_template/tests

test-api:
runs-on: ubuntu-22.04
needs: [ build ]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build: clean deps
@# `make build` allows us to be be sure tests are run against the packaged version
@# of OpenFisca-Extension-Template, the same we put in the hands of users and reusers.
python -m build
pip uninstall --yes openfisca-country-template
pip uninstall --yes openfisca-country_template
find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \;

format:
Expand Down
10 changes: 2 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ build-backend = "setuptools.build_meta"
requires = [ "setuptools>=61" ]

[project]
name = "openfisca-country-template"
version = "7.1.7"
name = "openfisca-country_template"
version = "8.0.0"
description = "OpenFisca Rules as Code model for Country-Template."
readme = "README.md"
keywords = [ "benefit", "microsimulation", "rac", "rules-as-code", "tax" ]
Expand All @@ -28,7 +28,6 @@ dependencies = [
]
optional-dependencies.dev = [
"isort>=5.13.2,<6",
"pyproject-fmt>=2.3.1,<3",
"ruff>=0.6.9,<1",
"ruff-lsp>=0.0.57,<1",
"yamllint>=1.35.1",
Expand Down Expand Up @@ -87,11 +86,6 @@ sections = [
"LOCALFOLDER",
]

[tool.pyproject-fmt]
column_width = 79
indent = 4
max_supported_python = "3.11"

[tool.pytest.ini_options]
addopts = "--exitfirst --showlocals --doctest-modules --disable-warnings --import-mode importlib"
testpaths = [ "openfisca_country_template/tests" ]
Expand Down
Loading