From ff8a1112132e0178344491c17abcc117e228787d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Sun, 26 Nov 2023 19:13:33 +0100 Subject: [PATCH 1/5] Switch to pyproject.toml --- .ci_support/release.py | 61 +++++++++++++++++++++++++ .github/workflows/black.yml | 2 +- .github/workflows/dependabot.yml | 2 +- .github/workflows/deploy.yml | 12 +++-- .github/workflows/mini.yml | 2 +- .github/workflows/pypicheck.yml | 2 +- .github/workflows/unittests.yml | 2 +- .github/workflows/unittests_old.yml | 2 +- pyproject.toml | 70 +++++++++++++++++++++++++++++ setup.cfg | 13 ------ setup.py | 51 +-------------------- structuretoolkit/__init__.py | 4 ++ 12 files changed, 148 insertions(+), 75 deletions(-) create mode 100644 .ci_support/release.py create mode 100644 pyproject.toml delete mode 100644 setup.cfg diff --git a/.ci_support/release.py b/.ci_support/release.py new file mode 100644 index 000000000..79620758c --- /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('pyproject.toml', "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('pyproject.toml', "w") as f: + f.writelines(setup_content_new) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 9f5d698e1..572a0e26f 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -12,7 +12,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: psf/black@stable with: options: "--check --diff" diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml index fb5936842..756af1d4e 100644 --- a/.github/workflows/dependabot.yml +++ b/.github/workflows/dependabot.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest if: (github.actor == 'dependabot[bot]') steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} # Check out the head of the actual branch, not the PR fetch-depth: 0 # otherwise, you will fail to push refs to dest repo diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3607ace63..c8ff34087 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,15 +22,13 @@ jobs: - uses: actions/setup-python@v2 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 pyproject.toml - 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 diff --git a/.github/workflows/mini.yml b/.github/workflows/mini.yml index 069022437..99c687402 100644 --- a/.github/workflows/mini.yml +++ b/.github/workflows/mini.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup environment run: cp .ci_support/environment_mini.yml environment.yml - name: Setup Mambaforge diff --git a/.github/workflows/pypicheck.yml b/.github/workflows/pypicheck.yml index da2583c4f..c697718f5 100644 --- a/.github/workflows/pypicheck.yml +++ b/.github/workflows/pypicheck.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup environment run: cp .ci_support/environment.yml environment.yml - name: Setup Mambaforge diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index aaf5233ec..de65594fc 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -45,7 +45,7 @@ jobs: prefix: /usr/share/miniconda3/envs/my-env steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup environment run: cp .ci_support/environment.yml environment.yml - name: Setup Mambaforge diff --git a/.github/workflows/unittests_old.yml b/.github/workflows/unittests_old.yml index c11206e69..7960d678e 100644 --- a/.github/workflows/unittests_old.yml +++ b/.github/workflows/unittests_old.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup Mambaforge uses: conda-incubator/setup-miniconda@v2 with: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..0f47a9da9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,70 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "structuretoolkit" +description = "build, analyse and visualise atomistic structures for materials science" +authors = [ + { name = "Jan Janssen", email = "janssen@mpie.de" }, +] +readme = "README.md" +license = { file = "LICENSE" } +keywords = ["pyiron"] +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Topic :: Scientific/Engineering :: Physics", + "License :: OSI Approved :: BSD License", + "Intended Audience :: Science/Research", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] +dependencies = [ + "ase==3.22.1", + "matplotlib==3.8.2", + "numpy==1.26.0", + "scipy==1.11.4", +] +dynamic = ["version"] + +[project.urls] +Homepage = "https://github.com/pyiron/structuretoolkit" +Documentation = "https://github.com/pyiron/structuretoolkit" +Repository = "https://github.com/pyiron/structuretoolkit" + +[project.optional-dependencies] +grainboundary = [ + "aimsgb==1.1.0", + "pymatgen==2023.11.12", +] +pyscal = ["pyscal2==2.10.18"] +nglview = ["nglview==3.0.8"] +plotly = ["plotly==5.18.0"] +clusters = ["scikit-learn==1.3.2"] +symmetry = ["spglib==2.1.0"] +surface = [ + "spglib==2.1.0", + "pymatgen==2023.11.12", +] +phonopy = [ + "phonopy==2.20.0", + "spglib==2.1.0", +] +pyxtal = ["pyxtal==0.6.1"] + +[tool.setuptools] +packages = ["structuretoolkit"] + +[tool.setuptools.dynamic] +version = {attr = "structuretoolkit.__version__"} + +[tool.versioneer] +VCS = "git" +style = "pep440-pre" +versionfile_source = "structuretoolkit/_version.py" +parentdir_prefix = "structuretoolkit" +tag_prefix = "structuretoolkit-" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b516ae651..000000000 --- a/setup.cfg +++ /dev/null @@ -1,13 +0,0 @@ - -# See the docstring in versioneer.py for instructions. Note that you must -# re-run 'versioneer.py setup' after changing this section, and commit the -# resulting files. - -[versioneer] -VCS = git -style = pep440-pre -versionfile_source = structuretoolkit/_version.py -#versionfile_build = -tag_prefix = structuretoolkit- -parentdir_prefix = structuretoolkit - diff --git a/setup.py b/setup.py index 63c624b30..fc1f76c84 100644 --- a/setup.py +++ b/setup.py @@ -1,50 +1,3 @@ -""" -Setuptools based setup module -""" -from setuptools import setup, find_packages -import versioneer +from setuptools import setup -setup( - name='structuretoolkit', - version=versioneer.get_version(), - description='structuretoolkit - to analyse, build and visualise atomistic structures.', - long_description='http://pyiron.org', - - url='https://github.com/pyiron/structuretoolkit', - author='Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department', - author_email='janssen@mpie.de', - license='BSD', - - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Topic :: Scientific/Engineering :: Physics', - 'License :: OSI Approved :: BSD License', - 'Intended Audience :: Science/Research', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11' - ], - - keywords='pyiron', - packages=find_packages(exclude=["*tests*", "*docs*", "*binder*", "*conda*", "*notebooks*", "*.ci_support*"]), - install_requires=[ - 'ase==3.22.1', - 'matplotlib==3.8.2', # ase already requires matplotlib - 'numpy==1.26.0', # ase already requires numpy - 'scipy==1.11.4', # ase already requires scipy - ], - extras_require={ - "grainboundary": ['aimsgb==1.1.0', 'pymatgen==2023.11.12'], - "pyscal": ['pyscal2==2.10.18'], - "nglview": ['nglview==3.0.8'], - "plotly": ['plotly==5.18.0'], - "clusters": ['scikit-learn==1.3.2'], - "symmetry": ['spglib==2.1.0'], - "surface": ['spglib==2.1.0', 'pymatgen==2023.11.12'], - "phonopy": ['phonopy==2.20.0', 'spglib==2.1.0'], - "pyxtal": ['pyxtal==0.6.1'] - }, - cmdclass=versioneer.get_cmdclass(), -) +setup() \ No newline at end of file diff --git a/structuretoolkit/__init__.py b/structuretoolkit/__init__.py index cf64fdab7..67567d97d 100644 --- a/structuretoolkit/__init__.py +++ b/structuretoolkit/__init__.py @@ -1,3 +1,5 @@ +from . import _version + # Analyse from structuretoolkit.analyse import ( find_mic, @@ -73,3 +75,5 @@ grainboundary as grainboundary_build, sqs_structures as get_sqs_structures, ) + +__version__ = _version.get_versions()["version"] \ No newline at end of file From 59d651ffa176cb97085488a7a08c57a1908d7e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Sun, 26 Nov 2023 19:15:04 +0100 Subject: [PATCH 2/5] black formatting --- structuretoolkit/__init__.py | 2 +- structuretoolkit/analyse/spatial.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/structuretoolkit/__init__.py b/structuretoolkit/__init__.py index 67567d97d..470edb17b 100644 --- a/structuretoolkit/__init__.py +++ b/structuretoolkit/__init__.py @@ -76,4 +76,4 @@ sqs_structures as get_sqs_structures, ) -__version__ = _version.get_versions()["version"] \ No newline at end of file +__version__ = _version.get_versions()["version"] diff --git a/structuretoolkit/analyse/spatial.py b/structuretoolkit/analyse/spatial.py index 252819a1f..da9299fd3 100644 --- a/structuretoolkit/analyse/spatial.py +++ b/structuretoolkit/analyse/spatial.py @@ -174,7 +174,7 @@ def __init__( var_ratio=5, min_samples=None, neigh_args={}, - **kwargs + **kwargs, ): """ @@ -333,7 +333,7 @@ def get_interstitials( var_ratio=5, min_samples=None, neigh_args={}, - **kwargs + **kwargs, ): return Interstitials( structure=structure, @@ -347,7 +347,7 @@ def get_interstitials( var_ratio=var_ratio, min_samples=min_samples, neigh_args=neigh_args, - **kwargs + **kwargs, ) From e0f25ec74679affed857416cb5ec35d1d08d912b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Sun, 26 Nov 2023 19:28:23 +0100 Subject: [PATCH 3/5] clean up actions --- .github/workflows/mini.yml | 13 ++++--------- .github/workflows/pypicheck.yml | 10 +++------- .github/workflows/unittests.yml | 10 ++-------- .github/workflows/unittests_old.yml | 10 ++++------ 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/.github/workflows/mini.yml b/.github/workflows/mini.yml index 99c687402..d73d362b4 100644 --- a/.github/workflows/mini.yml +++ b/.github/workflows/mini.yml @@ -18,8 +18,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup environment - run: cp .ci_support/environment_mini.yml environment.yml - name: Setup Mambaforge uses: conda-incubator/setup-miniconda@v2 with: @@ -28,14 +26,11 @@ jobs: channels: conda-forge channel-priority: strict activate-environment: my-env + environment-file: .ci_support/environment.yml use-mamba: true - - name: Update environment - run: mamba env update -n my-env -f environment.yml - - name: Setup - shell: bash -l {0} - run: | - pip install --no-deps . - name: Test shell: bash -l {0} timeout-minutes: 30 - run: python -m unittest discover tests + run: | + python -m pip install --no-deps . + python -m unittest discover tests diff --git a/.github/workflows/pypicheck.yml b/.github/workflows/pypicheck.yml index c697718f5..a52449dcc 100644 --- a/.github/workflows/pypicheck.yml +++ b/.github/workflows/pypicheck.yml @@ -15,8 +15,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup environment - run: cp .ci_support/environment.yml environment.yml - name: Setup Mambaforge uses: conda-incubator/setup-miniconda@v2 with: @@ -25,12 +23,10 @@ jobs: channels: conda-forge channel-priority: strict activate-environment: my-env + environment-file: .ci_support/environment.yml use-mamba: true - - name: Update environment - run: mamba env update -n my-env -f environment.yml - if: steps.cache.outputs.cache-hit != 'true' - name: Pip check shell: bash -l {0} run: | - pip install --no-deps . - pip check \ No newline at end of file + python -m pip install --no-deps . + python -m pip check \ No newline at end of file diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index de65594fc..df5368612 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -46,8 +46,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup environment - run: cp .ci_support/environment.yml environment.yml - name: Setup Mambaforge uses: conda-incubator/setup-miniconda@v2 with: @@ -56,17 +54,13 @@ jobs: channels: conda-forge channel-priority: strict activate-environment: my-env + environment-file: .ci_support/environment.yml use-mamba: true - - name: Update environment - run: mamba env update -n my-env -f environment.yml - - name: Setup - shell: bash -l {0} - run: | - pip install --no-deps . - name: Test shell: bash -l {0} timeout-minutes: 30 run: | + python -m pip install --no-deps . coverage run --omit structuretoolkit/_version.py -m unittest discover tests - name: Coverage if: matrix.label == 'linux-64-py-3-10' diff --git a/.github/workflows/unittests_old.yml b/.github/workflows/unittests_old.yml index 7960d678e..6060d2bf6 100644 --- a/.github/workflows/unittests_old.yml +++ b/.github/workflows/unittests_old.yml @@ -22,13 +22,11 @@ jobs: channels: conda-forge channel-priority: strict activate-environment: my-env + environment-file: .ci_support/environment-old.yml use-mamba: true - - name: Update environment - run: mamba env update -n my-env -f .ci_support/environment-old.yml - - name: Setup - shell: bash -l {0} - run: pip install --no-deps . - name: Test shell: bash -l {0} timeout-minutes: 30 - run: python -m unittest discover tests + run: | + python -m pip install --no-deps . + python -m unittest discover tests From 726be26d3ff544bb0cdc787694fa62ffdf1354ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Sun, 26 Nov 2023 19:48:39 +0100 Subject: [PATCH 4/5] fix requires --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0f47a9da9..6d1679642 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools"] +requires = ["ase", "matplotlib", "numpy", "setuptools", "scipy"] build-backend = "setuptools.build_meta" [project] From d8271aa81980d188e70110e846c0d24ab565f90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Sun, 26 Nov 2023 20:08:34 +0100 Subject: [PATCH 5/5] numpy update --- .ci_support/environment.yml | 2 +- .ci_support/environment_mini.yml | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci_support/environment.yml b/.ci_support/environment.yml index 8e1da3668..9b8910d8a 100644 --- a/.ci_support/environment.yml +++ b/.ci_support/environment.yml @@ -6,7 +6,7 @@ dependencies: - coverage - matplotlib-base =3.8.2 - nglview =3.0.8 -- numpy =1.26.0 +- numpy =1.26.2 - phonopy =2.20.0 - plotly =5.18.0 - pymatgen =2023.11.12 diff --git a/.ci_support/environment_mini.yml b/.ci_support/environment_mini.yml index ddbb914c2..f6620267d 100644 --- a/.ci_support/environment_mini.yml +++ b/.ci_support/environment_mini.yml @@ -4,5 +4,5 @@ dependencies: - ase =3.22.1 - coverage - matplotlib-base =3.8.2 -- numpy =1.26.0 +- numpy =1.26.2 - scipy =1.11.4 diff --git a/pyproject.toml b/pyproject.toml index 6d1679642..9a3919fed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ classifiers = [ dependencies = [ "ase==3.22.1", "matplotlib==3.8.2", - "numpy==1.26.0", + "numpy==1.26.2", "scipy==1.11.4", ] dynamic = ["version"]