Skip to content

Commit

Permalink
Merge pull request #112 from pyiron/pyproject_toml
Browse files Browse the repository at this point in the history
Switch to pyproject.toml
  • Loading branch information
jan-janssen authored Nov 26, 2023
2 parents fa698ce + cd31d42 commit 308c385
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .ci_support/environment_mini.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ channels:
dependencies:
- ase =3.22.1
- coverage
- matplotlib-base =3.7.2
- matplotlib-base =3.8.2
- numpy =1.26.2
- scipy =1.11.4
61 changes: 61 additions & 0 deletions .ci_support/release.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 5 additions & 10 deletions .github/workflows/mini.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup environment
run: cp .ci_support/environment_mini.yml environment.yml
- uses: actions/checkout@v4
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -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
12 changes: 4 additions & 8 deletions .github/workflows/pypicheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup environment
run: cp .ci_support/environment.yml environment.yml
- uses: actions/checkout@v4
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -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
python -m pip install --no-deps .
python -m pip check
12 changes: 3 additions & 9 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ jobs:
prefix: /usr/share/miniconda3/envs/my-env

steps:
- uses: actions/checkout@v2
- name: Setup environment
run: cp .ci_support/environment.yml environment.yml
- uses: actions/checkout@v4
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -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'
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/unittests_old.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
70 changes: 70 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[build-system]
requires = ["ase", "matplotlib", "numpy", "setuptools", "scipy"]
build-backend = "setuptools.build_meta"

[project]
name = "structuretoolkit"
description = "build, analyse and visualise atomistic structures for materials science"
authors = [
{ name = "Jan Janssen", email = "[email protected]" },
]
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.2",
"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-"
13 changes: 0 additions & 13 deletions setup.cfg

This file was deleted.

51 changes: 2 additions & 49 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
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.2', # 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()
4 changes: 4 additions & 0 deletions structuretoolkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from . import _version

# Analyse
from structuretoolkit.analyse import (
find_mic,
Expand Down Expand Up @@ -73,3 +75,5 @@
grainboundary as grainboundary_build,
sqs_structures as get_sqs_structures,
)

__version__ = _version.get_versions()["version"]
Loading

0 comments on commit 308c385

Please sign in to comment.