Skip to content

Commit

Permalink
Merge branch 'master' into test_scenario_csv
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello authored Dec 2, 2024
2 parents 11b3815 + caafc7c commit 63f8c7a
Show file tree
Hide file tree
Showing 69 changed files with 6,258 additions and 2,847 deletions.
96 changes: 0 additions & 96 deletions .circleci/config.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .circleci/publish-git-tag.sh

This file was deleted.

4 changes: 0 additions & 4 deletions .circleci/publish-python-package.sh

This file was deleted.

32 changes: 32 additions & 0 deletions .conda/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Publish to conda

There are two publishing systems for openfisca conda packages:
- A fully automatic CI that publishes to an _openfisca_ channel. `openfisca-survey-manager` conda package is published to this channel. See below for more information.
- A more complex CI calling Conda-Forge CI, that publishes to the _Conda-Forge_ channel. See https://www.youtube.com/watch?v=N2XwK9BkJpA for an introduction to Conda-Forge. We do not use it for this repository.

## Automatic upload

The CI automaticaly builds the conda package from the [PyPi package](https://pypi.org/project/OpenFisca-Survey-Manager/), and uploads it to [anaconda.org](https://anaconda.org/search?q=openfisca-survey-manager). You can check this out in the GitHub Actions configuration file `.github/workflow/workflow.yml` and its `publish-to-conda` step.

## Manual actions made to make it work the first time

- Create an account on https://anaconda.org.
- Create a token on https://anaconda.org/openfisca/settings/access with _Allow write access to the API site_.
- Put the token in a CI environment variable named `ANACONDA_TOKEN`.

⚠️ Warning, the current token expires on 2025/01/14. Check existing tokens and their expiration dates on Anaconda.org website and its [_Access_ section](https://anaconda.org/openfisca/settings/access).

## Manual actions before initializing the CI or to test the conda packaging

Before initializing the CI the conda package was created locally. Now, the conda packaging is done by the CI. Nevertheless, if you want to test it, this section describes how a package is built and uploaded.

To create a conda package for this repository you can check the packaging configuration in `.conda/meta.yaml` and do the following in the project root folder:

1. Build package:
- `conda install -c anaconda conda-build anaconda-client`
(`conda-build` to build the package and [anaconda-client](https://github.com/Anaconda-Platform/anaconda-client) to push the package to anaconda.org)
- `conda build .conda --channel openfisca`

2. Upload the package to Anaconda.org, but DON'T do it if you don't want to publish your locally built package as an official OpenFisca-Survey-Manager library:
- `anaconda login`
- `anaconda upload openfisca-survey-manager-<VERSION>-py_0.tar.bz2`
103 changes: 103 additions & 0 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
###############################################################################
## File describing the package for Anaconda.org
## It uses Jinja2 templating code to retreive information from setup.py
###############################################################################

{% set name = "OpenFisca-Survey-Manager" %}
{% set data = load_setup_py_data() %}
{% set version = data.get('version') %}

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

# openfisca-survey-manager package source
source:
path: ..

build:
noarch: python
number: 0
script: "{{ PYTHON }} -m pip install . -vv"

requirements:
host:
- python
- pip
run:
{% for req in data.get('install_requires', []) %}
{% if req.startswith('tables') %}
# PyPI 'tables' library is named 'pytables' for conda
- {{ req.replace('tables', 'pytables') }}
{% else %}
- {{ req | replace(" ","")}}
{% endif %}
{% endfor %}


test:
imports:
- openfisca_survey_manager
requires:
- pip
commands:
- pip check

outputs:
- name: openfisca-survey-manager

- name: openfisca-survey-manager-matching
build:
noarch: python
commands:
- echo {{ data.keys() }}
requirements:
host:
- python
run:
{% if 'extra_requires' in data %}
{% for req in data['extra_requires'].get('matching', []) %}
- {{ req }}
{% endfor %}
{% endif %}
- {{ pin_subpackage('openfisca-survey-manager', exact=True) }}

- name: openfisca-survey-manager-dev
build:
noarch: python
requirements:
host:
- python
run:
{% if 'extra_requires' in data %}
{% for req in data['extra_requires'].get('dev', []) %}
- {{ req }}
{% endfor %}
{% endif %}
- {{ pin_subpackage('openfisca-survey-manager', exact=True) }}

- name: openfisca-survey-manager-sas
build:
noarch: python
requirements:
host:
- python
run:
{% if 'extra_requires' in data %}
{% for req in data['extra_requires'].get('sas', []) %}
- {{ req }}
{% endfor %}
{% endif %}
- {{ pin_subpackage('openfisca-survey-manager', exact=True) }}

about:
home: https://fr.openfisca.org/
license_family: AGPL
license: AGPL-3.0-only
license_file: LICENSE.AGPL.txt
summary: "Survey-Manager module, to work with OpenFisca and survey data."
description: |
OpenFisca is a versatile microsimulation free software.
This repository contains the Survey-Manager module, to work with OpenFisca and survey data.
doc_url: https://fr.openfisca.org/
dev_url: https://github.com/openfisca/openfisca-survey-manager/
13 changes: 3 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "00:00"
timezone: Europe/Paris
open-pull-requests-limit: 2
reviewers:
- benjello
ignore:
- dependency-name: autopep8
versions:
- 1.5.6
interval: weekly
labels:
- kind:dependencies
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .circleci/* .github/*"
IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .github/* .conda/*"

last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

if [[ $CIRCLE_BRANCH == master ]]
if [[ ${GITHUB_REF#refs/heads/} == master ]]
then
echo "No need for a version check on master."
exit 0
Expand All @@ -12,16 +12,28 @@ then
exit 0
fi

current_version=`python setup.py --version`
current_version=$(python `dirname "$BASH_SOURCE"`/pyproject_version.py --only_package_version True) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273
if [ $? -eq 0 ]; then
echo "Package version in pyproject.toml : $current_version"
else
echo "ERROR getting current version: $current_version"
exit 3
fi

if [[ -z $current_version ]]
then
echo "Error getting current version"
exit 1
fi

if git rev-parse --verify --quiet $current_version
then
echo "Version $current_version already exists in commit:"
git --no-pager log -1 $current_version
echo
echo "Update the version number in setup.py before merging this branch into master."
echo "Update the version number in pyproject.toml before merging this branch into master."
echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated."
exit 1
exit 2
fi

if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md
Expand Down
5 changes: 5 additions & 0 deletions .github/publish-git-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /usr/bin/env bash

current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273
git tag $current_version
git push --tags # update the repository version
56 changes: 56 additions & 0 deletions .github/pyproject_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Read package version in pyproject.toml and replace it in .conda/recipe.yaml

import argparse
import logging
import re

logging.basicConfig(level=logging.INFO, format='%(message)s')
PACKAGE_VERSION = 'X.X.X'
CORE_VERSION = '>=43,<44'
NUMPY_VERSION = '>=1.24.3,<2'


def get_versions():
'''
Read package version and deps in pyproject.toml
'''
# openfisca_core_api = None
openfisca_survey_manager = None
# numpy = None
with open('./pyproject.toml', 'r') as file:
content = file.read()
# Extract the version of openfisca_survey_manager
version_match = re.search(r'^version\s*=\s*"([\d.]*)"', content, re.MULTILINE)
if version_match:
openfisca_survey_manager = version_match.group(1)
else:
raise Exception('Package version not found in pyproject.toml')
# Extract dependencies
# version = re.search(r'openfisca-core\s*(>=\s*[\d\.]*,\s*<\d*)"', content, re.MULTILINE)
# if version:
# openfisca_core_api = version.group(1)
# version = re.search(r'numpy\s*(>=\s*[\d\.]*,\s*<\d*)"', content, re.MULTILINE)
# if version:
# numpy = version.group(1)
# if not openfisca_core_api or not numpy:
# raise Exception('Dependencies not found in pyproject.toml')
return {
'openfisca_survey_manager': openfisca_survey_manager,
# 'openfisca_core_api': openfisca_core_api.replace(' ', ''),
# 'numpy': numpy.replace(' ', ''),
}


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--replace', type=bool, default=False, required=False, help='replace in file')
parser.add_argument('-f', '--filename', type=str, default='.conda/recipe.yaml', help='Path to recipe.yaml, with filename')
parser.add_argument('-o', '--only_package_version', type=bool, default=False, help='Only display current package version')
args = parser.parse_args()
info = get_versions()
file = args.filename
if args.only_package_version:
print(f'{info["openfisca_survey_manager"]}') # noqa: T201
exit()
logging.info('Versions :')
print(info) # noqa: T201
Loading

0 comments on commit 63f8c7a

Please sign in to comment.