-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1242 from pyiron/pyproject
Switch from setup.py to pyproject.toml
- Loading branch information
Showing
30 changed files
with
303 additions
and
2,651 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ channels: | |
- conda-forge | ||
dependencies: | ||
- nbsphinx | ||
- sphinx <6.1 | ||
- sphinx | ||
- ase | ||
- defusedxml | ||
- future | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 33 additions & 32 deletions
65
.github/workflows/UpdateDependabotPR.yml → .github/workflows/dependabot.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
Oops, something went wrong.