Skip to content

Commit

Permalink
Fix pyproject_version
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello committed Nov 27, 2024
1 parent 410f418 commit 68d8d71
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
36 changes: 5 additions & 31 deletions .github/pyproject_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ def get_versions():
openfisca_france = None
with open('./pyproject.toml', 'r') as file:
content = file.read()
# Extract the version of openfisca_france
# Extract the version of openfisca_survey_manager
version_match = re.search(r'^version\s*=\s*"([\d.]*)"', content, re.MULTILINE)
if version_match:
openfisca_france = version_match.group(1)
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)
Expand All @@ -34,34 +35,12 @@ def get_versions():
if not openfisca_core_api or not numpy:
raise Exception('Dependencies not found in pyproject.toml')
return {
'openfisca_france': openfisca_france,
'openfisca_survey_manager': openfisca_survey_manager,
'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')
Expand All @@ -71,12 +50,7 @@ def replace_in_file(filepath: str, info: dict):
info = get_versions()
file = args.filename
if args.only_package_version:
print(f'{info["openfisca_france"]}') # noqa: T201
print(f'{info["openfisca_survey_manager"]}') # 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')
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- Comment out conda build.
- Add a `openfisa_survey_manager.paths` module to store paths (breaking change).


### 2.3.5 [#319](https://github.com/openfisca/openfisca-survey-manager/pull/319)

* Technical changes
Expand Down

0 comments on commit 68d8d71

Please sign in to comment.