From 209d039fe1ab47b9a9cc9f41ce67c899e1ee06a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Fri, 24 Nov 2023 17:17:12 +0100 Subject: [PATCH 1/2] Support releasing strict version dependencies --- .ci_support/environment-old.yml | 1 + .ci_support/release.py | 61 +++++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 11 +++--- 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 .ci_support/release.py diff --git a/.ci_support/environment-old.yml b/.ci_support/environment-old.yml index c4fe920b..a5b6d7a9 100644 --- a/.ci_support/environment-old.yml +++ b/.ci_support/environment-old.yml @@ -2,6 +2,7 @@ channels: - conda-forge dependencies: - ase =3.22.1 +- gpaw =20.1.0 - numpy =1.23.5 - scipy =1.11.1 - spglib =2.0.2 diff --git a/.ci_support/release.py b/.ci_support/release.py new file mode 100644 index 00000000..7c99a520 --- /dev/null +++ b/.ci_support/release.py @@ -0,0 +1,61 @@ +def get_setup_version_and_pattern(setup_content): + depend_lst, version_lst = [], [] + for l in setup_content: + if '==' in l: + lst = l.split('[')[-1].split(']')[0].replace(' ', '').replace('"', '').replace("'", '').split(',') + for dep in lst: + if dep != '\n': + version_lst.append(dep.split('==')[1]) + depend_lst.append(dep.split('==')[0]) + + version_high_dict = {d: v for d, v in zip(depend_lst, version_lst)} + return version_high_dict + + +def get_env_version(env_content): + read_flag = False + depend_lst, version_lst = [], [] + for l in env_content: + if 'dependencies:' in l: + read_flag = True + elif read_flag: + lst = l.replace('-', '').replace(' ', '').replace('\n', '').split("=") + if len(lst) == 2: + depend_lst.append(lst[0]) + version_lst.append(lst[1]) + return {d:v for d, v in zip(depend_lst, version_lst)} + + +def update_dependencies(setup_content, version_low_dict, version_high_dict): + version_combo_dict = {} + for dep, ver in version_high_dict.items(): + if dep in version_low_dict.keys() and version_low_dict[dep] != ver: + version_combo_dict[dep] = dep + ">=" + version_low_dict[dep] + ",<=" + ver + else: + version_combo_dict[dep] = dep + "==" + ver + + setup_content_new = "" + pattern_dict = {d:d + "==" + v for d, v in version_high_dict.items()} + for l in setup_content: + for k, v in pattern_dict.items(): + if v in l: + l = l.replace(v, version_combo_dict[k]) + setup_content_new +=l + return setup_content_new + + +if __name__ == "__main__": + with open('setup.py', "r") as f: + setup_content = f.readlines() + + with open('environment.yml', "r") as f: + env_content = f.readlines() + + setup_content_new = update_dependencies( + setup_content=setup_content, + version_low_dict=get_env_version(env_content=env_content), + version_high_dict=get_setup_version_and_pattern(setup_content=setup_content), + ) + + with open('setup.py', "w") as f: + f.writelines(setup_content_new) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f567fa45..385fc6ef 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,13 +23,12 @@ jobs: with: python-version: "3.11" - name: Install dependencies - run: >- - python -m pip install --user --upgrade setuptools wheel + run: python -m pip install --user --upgrade setuptools wheel - name: Convert dependencies - run: >- - sed -i 's/==/>=/g' setup.py; cat setup.py + run: | + cp .ci_support/environment-old.yml environment.yml + python .ci_support/release.py; cat setup.py - name: Build - run: >- - python setup.py sdist bdist_wheel + run: python setup.py sdist bdist_wheel - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 From 21dbb19bac4567cc1e800754170b9f47011e6fec Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Sat, 25 Nov 2023 18:27:20 +0100 Subject: [PATCH 2/2] Update release.py --- .ci_support/release.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci_support/release.py b/.ci_support/release.py index 7c99a520..79620758 100644 --- a/.ci_support/release.py +++ b/.ci_support/release.py @@ -45,7 +45,7 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict): if __name__ == "__main__": - with open('setup.py', "r") as f: + with open('pyproject.toml', "r") as f: setup_content = f.readlines() with open('environment.yml', "r") as f: @@ -57,5 +57,5 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict): version_high_dict=get_setup_version_and_pattern(setup_content=setup_content), ) - with open('setup.py', "w") as f: + with open('pyproject.toml', "w") as f: f.writelines(setup_content_new)