Skip to content

Commit

Permalink
Merge pull request #1242 from pyiron/pyproject
Browse files Browse the repository at this point in the history
Switch from setup.py to pyproject.toml
  • Loading branch information
jan-janssen authored Dec 3, 2023
2 parents c9f96e5 + 733d9eb commit 55c1fa6
Show file tree
Hide file tree
Showing 30 changed files with 303 additions and 2,651 deletions.
57 changes: 0 additions & 57 deletions .ci_support/condamerge.py

This file was deleted.

2 changes: 1 addition & 1 deletion .ci_support/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ channels:
- conda-forge
dependencies:
- nbsphinx
- sphinx <6.1
- sphinx
- ase
- defusedxml
- future
Expand Down
2 changes: 1 addition & 1 deletion .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ dependencies:
- seekpath =2.1.0
- spglib =2.1.0
- structuretoolkit =0.0.15
- python-blosc2 # required by pytables
- python-blosc2 # required by pytables
79 changes: 79 additions & 0 deletions .ci_support/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import json


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


def convert_key(key, convert_dict):
if key not in convert_dict.keys():
return key
else:
return convert_dict[key]


if __name__ == "__main__":
with open('.ci_support/pypi_vs_conda_names.json', 'r') as f:
name_conversion_dict = {v: k for k, v in json.load(f).items()}

with open('pyproject.toml', "r") as f:
setup_content = f.readlines()

with open('environment.yml', "r") as f:
env_content = f.readlines()

env_version_dict = {
convert_key(key=k, convert_dict=name_conversion_dict): v
for k, v in get_env_version(env_content=env_content).items()
}

setup_content_new = update_dependencies(
setup_content=setup_content[2:],
version_low_dict=env_version_dict,
version_high_dict=get_setup_version_and_pattern(setup_content=setup_content[2:]),
)

with open('pyproject.toml', "w") as f:
f.writelines("".join(setup_content[:2]) + setup_content_new)
3 changes: 2 additions & 1 deletion .ci_support/test_backwards.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ for t in tests/backwards/*save.py; do
python $t
done

pip install --no-deps .
pip install versioneer[toml]==0.29
pip install . --no-deps --no-build-isolation
i=0;
echo "Before loading";
for t in tests/backwards/*load.py; do
Expand Down
26 changes: 7 additions & 19 deletions .github/workflows/backwards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup environment
- uses: actions/checkout@v4
- name: Merge environments
run: |
python .ci_support/condamerge.py --base .ci_support/environment.yml --add .ci_support/environment-notebooks.yml > environment.yml
cp .ci_support/environment.yml environment.yml
tail --lines=+4 .ci_support/environment-notebooks.yml >> environment.yml
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -26,23 +27,10 @@ jobs:
channels: conda-forge
channel-priority: strict
activate-environment: my-env
environment-file: environment.yml
use-mamba: true
- name: Set cache date and number
run: |
echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
cat .github/variables/cache_number.env >> $GITHUB_ENV
- uses: actions/cache@v2
with:
path: /usr/share/miniconda3/envs/my-env
key: linux-64-py-3-10-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
id: cache
- name: Update environment
run: mamba env update -n my-env -f environment.yml
if: steps.cache.outputs.cache-hit != 'true'
- name: Setup
- name: Test
shell: bash -l {0}
run: |
python .ci_support/pyironconfig.py
- name: Test
shell: bash -l {0}
run: ./.ci_support/test_backwards.sh
./.ci_support/test_backwards.sh
41 changes: 13 additions & 28 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,27 @@ on:

jobs:
benchmark:

runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
include:
- operating-system: macos-latest
python-version: '3.10'
label: osx-64-py-3-10
python-version: '3.11'
label: osx-64-py-3-11
prefix: /Users/runner/miniconda3/envs/my-env

- operating-system: windows-latest
python-version: '3.10'
label: win-64-py-3-10
python-version: '3.11'
label: win-64-py-3-11
prefix: C:\Miniconda3\envs\my-env

- operating-system: ubuntu-latest
python-version: '3.10'
label: linux-64-py-3-10
python-version: '3.11'
label: linux-64-py-3-11
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 @@ -42,25 +39,13 @@ jobs:
channels: conda-forge
channel-priority: strict
activate-environment: my-env
environment-file: .ci_support/environment.yml
use-mamba: true
- name: Set cache date and number
run: |
echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
cat .github/variables/cache_number.env >> $GITHUB_ENV
- uses: actions/cache@v2
with:
path: ${{ matrix.prefix }}
key: ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
id: cache
- name: Update environment
run: mamba env update -n my-env -f environment.yml
if: steps.cache.outputs.cache-hit != 'true'
- name: Setup
shell: bash -l {0}
run: |
python .ci_support/pyironconfig.py
pip install --no-deps .
- name: Tests
shell: bash -l {0}
timeout-minutes: 30
run: python -m unittest discover test_benchmarks
run: |
python .ci_support/pyironconfig.py
pip install versioneer[toml]==0.29
pip install . --no-deps --no-build-isolation
python -m unittest discover test_benchmarks
7 changes: 3 additions & 4 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
# This workflow is used to check the differences and find conflict markers or whitespace errors

name: Black

Expand All @@ -13,8 +12,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: "--check --diff"
src: "./pyiron_atomistics"
src: ./${{ github.event.repository.name }}
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 2

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
name: UpdateDependabotPR

on:
pull_request_target:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
if: (github.actor == 'dependabot[bot]')
steps:
- uses: actions/checkout@v2
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
token: ${{ secrets.DEPENDABOT_WORKFLOW_TOKEN }}
- name: UpdateEnvironmentFile
env:
PR_TITLE: ${{ github.event.pull_request.title }}
shell: bash -l {0}
run: |
python .ci_support/update_environment.py $PR_TITLE
- name: UpdateDependabotPR commit
run: |
git config --local user.email "[email protected]"
git config --local user.name "pyiron-runner"
git commit -m "[dependabot skip] Update environment" -a
- name: UpdateDependabotPR push
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.DEPENDABOT_WORKFLOW_TOKEN }}
branch: ${{ github.event.pull_request.head.ref }}
name: Update Dependabot

on:
pull_request_target:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
if: (github.actor == 'dependabot[bot]')
steps:
- 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
token: ${{ secrets.DEPENDABOT_WORKFLOW_TOKEN }}
- name: UpdateEnvironmentFile
shell: bash -l {0}
run: |
package=$(echo "${{ github.event.pull_request.title }}" | awk '{print $2}')
from=$(echo "${{ github.event.pull_request.title }}" | awk '{print $4}')
to=$(echo "${{ github.event.pull_request.title }}" | awk '{print $6}')
sed -i "/${package}/s/${from}/${to}/g" .ci_support/environment.yml
- name: UpdateDependabotPR commit
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "[dependabot skip] Update environment" -a
- name: UpdateDependabotPR push
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.DEPENDABOT_WORKFLOW_TOKEN }}
branch: ${{ github.event.pull_request.head.ref }}
Loading

0 comments on commit 55c1fa6

Please sign in to comment.