Skip to content

Commit

Permalink
More fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello committed Nov 26, 2024
1 parent 70632b7 commit f2d245c
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 26 deletions.
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
7 changes: 1 addition & 6 deletions .github/has-functional-changes.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#! /usr/bin/env bash

echo "Run has functionnal changes"

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

echo "Last tagged commit: $last_tagged_commit"

if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published.
then
echo "No functional changes detected."
exit 1
else echo "The functional files above were changed."
fi
echo "The functional files above were changed."
exit 0
18 changes: 15 additions & 3 deletions .github/is-version-number-acceptable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .github/publish-git-tag.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /usr/bin/env bash

git tag `python setup.py --version`
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
82 changes: 82 additions & 0 deletions .github/pyproject_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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_france = None
with open('./pyproject.toml', 'r') as file:
content = file.read()
# Extract the version of openfisca_france
version_match = re.search(r'^version\s*=\s*"([\d.]*)"', content, re.MULTILINE)
if version_match:
openfisca_france = version_match.group(1)
else:
raise Exception('Package version not found in pyproject.toml')
# Extract dependencies
version = re.search(r'openfisca-core\[web-api\]\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')

Check failure on line 35 in .github/pyproject_version.py

View workflow job for this annotation

GitHub Actions / check-version-and-changelog

Dependencies not found in pyproject.toml
return {
'openfisca_france': openfisca_france,
'openfisca_core_api': openfisca_core_api.replace(' ', ''),
'numpy': numpy.replace(' ', ''),
}


def replace_in_file(filepath: str, info: dict):
'''
::filepath:: Path to meta.yaml, with filename
::info:: Dict with information to populate
'''
with open(filepath, 'rt') as fin:
meta = fin.read()
# Replace with info from pyproject.toml
if PACKAGE_VERSION not in meta:
raise Exception(f'{PACKAGE_VERSION=} not found in {filepath}')
meta = meta.replace(PACKAGE_VERSION, info['openfisca_france'])
if CORE_VERSION not in meta:
raise Exception(f'{CORE_VERSION=} not found in {filepath}')
meta = meta.replace(CORE_VERSION, info['openfisca_core_api'])
if NUMPY_VERSION not in meta:
raise Exception(f'{NUMPY_VERSION=} not found in {filepath}')
meta = meta.replace(NUMPY_VERSION, info['numpy'])
with open(filepath, 'wt') as fout:
fout.write(meta)
logging.info(f'File {filepath} has been updated with informations from pyproject.toml.')


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_france"]}') # noqa: T201
exit()
logging.info('Versions :')
print(info) # noqa: T201
if args.replace:
logging.info(f'Replace in {file}')
replace_in_file(file, info)
else:
logging.info('Dry mode, no replace made')
12 changes: 6 additions & 6 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }}-${{ matrix.os }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-${{ matrix.os }}
restore-keys: | # in case of a cache miss (systematically unless the same commit is built repeatedly), the keys below will be used to restore dependencies from previous builds, and the cache will be stored at the end of the job, making up-to-date dependencies available for all jobs of the workflow; see more at https://docs.github.com/en/actions/advanced-guides/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ matrix.os }}
build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ matrix.os }}
build-${{ env.pythonLocation }}-${{ matrix.os }}
- name: Build package
run: make build
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }}-ubuntu-20.04
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-ubuntu-20.04
- run: pip install -e .[dev] # Need to install linter
- run: make check-syntax-errors
- run: make check-style
Expand All @@ -103,7 +103,7 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }}-${{ matrix.os }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-${{ matrix.os }}
- name: install
run: make install
- name: test
Expand Down Expand Up @@ -164,13 +164,13 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }}-ubuntu-20.04
key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-ubuntu-20.04
- name: Cache release
id: restore-release
uses: actions/cache@v4
with:
path: dist
key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }}-ubuntu-20.04
key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }}-ubuntu-20.04
- name: Upload a Python package to PyPi
run: twine upload dist/* --username __token__ --password $PYPI_TOKEN_OPENFISCA_BOT
- name: Publish a git tag
Expand Down

0 comments on commit f2d245c

Please sign in to comment.