Skip to content

Commit

Permalink
chore: backport changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 4, 2024
1 parent 5216c63 commit a779d98
Show file tree
Hide file tree
Showing 80 changed files with 3,440 additions and 1,648 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
directory: /
schedule:
interval: monthly
labels:
Expand Down
17 changes: 10 additions & 7 deletions .github/get_pypi_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def get_info(package_name: str = "") -> dict:
::return:: A dict with last_version, url and sha256
"""
if package_name == "":
raise ValueError("Package name not provided.")
msg = "Package name not provided."
raise ValueError(msg)
url = f"https://pypi.org/pypi/{package_name}/json"
print(f"Calling {url}") # noqa: T201
resp = requests.get(url)
if resp.status_code != 200:
raise Exception(f"ERROR calling PyPI ({url}) : {resp}")
msg = f"ERROR calling PyPI ({url}) : {resp}"
raise Exception(msg)
resp = resp.json()
version = resp["info"]["version"]

Expand All @@ -38,19 +40,19 @@ def get_info(package_name: str = "") -> dict:
return {}


def replace_in_file(filepath: str, info: dict):
def replace_in_file(filepath: str, info: dict) -> None:
"""Replace placeholder in meta.yaml by their values.
::filepath:: Path to meta.yaml, with filename.
::info:: Dict with information to populate.
"""
with open(filepath, "rt", encoding="utf-8") as fin:
with open(filepath, encoding="utf-8") as fin:
meta = fin.read()
# Replace with info from PyPi
meta = meta.replace("PYPI_VERSION", info["last_version"])
meta = meta.replace("PYPI_URL", info["url"])
meta = meta.replace("PYPI_SHA256", info["sha256"])
with open(filepath, "wt", encoding="utf-8") as fout:
with open(filepath, "w", encoding="utf-8") as fout:
fout.write(meta)
print(f"File {filepath} has been updated with info from PyPi.") # noqa: T201

Expand All @@ -69,12 +71,13 @@ def replace_in_file(filepath: str, info: dict):
"-f",
"--filename",
type=str,
default=".conda/meta.yaml",
default=".conda/openfisca-core/meta.yaml",
help="Path to meta.yaml, with filename",
)
args = parser.parse_args()
info = get_info(args.package)
print( # noqa: T201
"Information of the last published PyPi package :", info["last_version"]
"Information of the last published PyPi package :",
info["last_version"],
)
replace_in_file(args.filename, info)
109 changes: 109 additions & 0 deletions .github/workflows/_before-conda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Setup conda

on:
workflow_call:
inputs:
os:
required: true
type: string

numpy:
required: true
type: string

python:
required: true
type: string

defaults:
run:
shell: bash -l {0}

jobs:
setup:
runs-on: ${{ inputs.os }}
name: conda-setup-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}
env:
# To colorize output of make tasks.
TERM: xterm-256color

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache conda env
uses: actions/cache@v4
with:
path: |
/usr/share/miniconda/envs/openfisca
~/.conda/envs/openfisca
.env.yaml
key: conda-env-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}
restore-keys: conda-env-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-
id: cache-env

- name: Cache conda deps
uses: actions/cache@v4
with:
path: ~/conda_pkgs_dir
key: conda-deps-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}
restore-keys: conda-deps-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-
id: cache-deps

- name: Cache release
uses: actions/cache@v4
with:
path: ~/conda-rel
key: conda-release-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}-${{ github.sha }}

- name: Setup conda
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: openfisca
miniforge-version: latest
python-version: ${{ inputs.python }}
use-mamba: true
if: steps.cache-env.outputs.cache-hit != 'true'

- name: Install dependencies
run: mamba install boa rattler-build anaconda-client
if: steps.cache-env.outputs.cache-hit != 'true'

- name: Update conda & dependencies
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: openfisca
environment-file: .env.yaml
miniforge-version: latest
use-mamba: true
if: steps.cache-env.outputs.cache-hit == 'true'

- name: Build pylint plugin package
run: |
rattler-build build \
--recipe .conda/pylint-per-file-ignores \
--output-dir ~/conda-rel
- name: Build core package
run: |
conda mambabuild .conda/openfisca-core \
--use-local \
--no-anaconda-upload \
--output-folder ~/conda-rel \
--numpy ${{ inputs.numpy }} \
--python ${{ inputs.python }}
- name: Build country template package
run: |
rattler-build build \
--recipe .conda/openfisca-country-template \
--output-dir ~/conda-rel \
- name: Build extension template package
run: |
rattler-build build \
--recipe .conda/openfisca-extension-template \
--output-dir ~/conda-rel
- name: Export env
run: mamba env export --name openfisca > .env.yaml
103 changes: 103 additions & 0 deletions .github/workflows/_before-pip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Setup package

on:
workflow_call:
inputs:
os:
required: true
type: string

numpy:
required: true
type: string

python:
required: true
type: string

activate_command:
required: true
type: string

jobs:
deps:
runs-on: ${{ inputs.os }}
name: pip-deps-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}
env:
# To colorize output of make tasks.
TERM: xterm-256color

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python }}

- name: Use zstd for faster cache restore (windows)
if: ${{ startsWith(inputs.os, 'windows') }}
shell: cmd
run: echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"

- name: Cache dependencies
uses: actions/cache@v4
with:
path: venv
key: pip-deps-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}
restore-keys: pip-deps-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-

- name: Install dependencies
run: |
python -m venv venv
${{ inputs.activate_command }}
make install-deps install-dist
pip install numpy==${{ inputs.numpy }}
build:
runs-on: ${{ inputs.os }}
needs: [deps]
name: pip-build-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}
env:
TERM: xterm-256color

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python }}

- name: Use zstd for faster cache restore (windows)
if: ${{ startsWith(inputs.os, 'windows') }}
shell: cmd
run: echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"

- name: Cache dependencies
uses: actions/cache@v4
with:
path: venv
key: pip-deps-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}

- name: Cache build
uses: actions/cache@v4
with:
path: venv/**/[Oo]pen[Ff]isca*
key: pip-build-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}-${{ github.sha }}
restore-keys: |
pip-build-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}-
pip-build-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-
- name: Cache release
uses: actions/cache@v4
with:
path: dist
key: pip-release-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}-${{ github.sha }}

- name: Build package
run: |
${{ inputs.activate_command }}
make install-test clean build
57 changes: 57 additions & 0 deletions .github/workflows/_lint-pip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Lint package

on:
workflow_call:
inputs:
os:
required: true
type: string

numpy:
required: true
type: string

python:
required: true
type: string

activate_command:
required: true
type: string

jobs:
lint:
runs-on: ${{ inputs.os }}
name: pip-lint-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}
env:
TERM: xterm-256color # To colorize output of make tasks.

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python }}

- name: Use zstd for faster cache restore (windows)
if: ${{ startsWith(inputs.os, 'windows') }}
shell: cmd
run: echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"

- name: Cache dependencies
uses: actions/cache@v4
with:
path: venv
key: pip-deps-${{ inputs.os }}-np${{ inputs.numpy }}-py${{ inputs.python }}-${{ hashFiles('setup.py') }}

- name: Lint doc
run: |
${{ inputs.activate_command }}
make clean check-syntax-errors lint-doc
- name: Lint styles
run: |
${{ inputs.activate_command }}
make clean check-syntax-errors check-style
Loading

0 comments on commit a779d98

Please sign in to comment.