-
Notifications
You must be signed in to change notification settings - Fork 5
228 lines (182 loc) · 7.56 KB
/
pyproject-copier.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: pyproject-toml-copier
on:
workflow_dispatch:
inputs:
plugin:
required: true
type: string
gh-org:
required: false
type: string
default: qiime2
distribution:
required: false
type: string
default: amplicon
jobs:
pyproject-copier:
runs-on: ubuntu-latest
env:
plugin_name: ${{ inputs.plugin }}
repository: ${{ inputs.gh-org }}/${{ inputs.plugin }}
repo_url: https://github.com/${{ inputs.gh-org }}/${{ inputs.plugin }}
distro: ${{ inputs.distribution }}
steps:
- uses: actions/checkout@v4
with:
repository: ${{ env.repository }}
- name: 'Construct env vars from action inputs and export'
run: |
PLUGIN_NAME=$(echo "${{ env.plugin_name }}" | sed 's/-/_/g')
MODULE_NAME=$(echo "$PLUGIN_NAME" | sed 's/^q2_//')
PROJECT_URLS_REPOSITORY=${{ env.repo_url }}
echo "PLUGIN_NAME=$PLUGIN_NAME" >> $GITHUB_ENV
echo "MODULE_NAME=$MODULE_NAME" >> $GITHUB_ENV
echo "PROJECT_URLS_REPOSITORY=$PROJECT_URLS_REPOSITORY" >> $GITHUB_ENV
- name: 'Double to single quotes in setup.py for grep consistency'
run: |
sed -i 's/"/'\''/g' setup.py
- name: 'Construct and export env vars from setup.py'
run: |
PROJECT_NAME=$(grep -oP "name\s*=\s*'\K[^']+" setup.py || true)
PROJECT_AUTHOR_NAME=$(grep -oP "author\s*=\s*'\K[^']+" setup.py || true)
PROJECT_AUTHOR_EMAIL=$(grep -oP "author_email\s*=\s*'\K[^']+" setup.py || true)
PROJECT_DESCRIPTION=$(grep -oP "description\s*=\s*'\K[^']+" setup.py || true)
PROJECT_URLS_HOMEPAGE=$(grep -oP "url\s*=\s*'\K[^']+" setup.py || true)
PLUGIN_SCRIPTS=$(grep -oP "scripts=\['\K[^']+" setup.py || true)
if [ -z "$PROJECT_AUTHOR_EMAIL" ]; then
fi
echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_ENV
echo "PROJECT_AUTHOR_NAME=$PROJECT_AUTHOR_NAME" >> $GITHUB_ENV
echo "PROJECT_AUTHOR_EMAIL=$PROJECT_AUTHOR_EMAIL" >> $GITHUB_ENV
echo "PROJECT_DESCRIPTION=$PROJECT_DESCRIPTION" >> $GITHUB_ENV
echo "PROJECT_URLS_HOMEPAGE=$PROJECT_URLS_HOMEPAGE" >> $GITHUB_ENV
echo "PLUGIN_SCRIPTS=$PLUGIN_SCRIPTS" >> $GITHUB_ENV
- name: 'Remove old setup files & relocate recipe file and check status'
run: |
rm MANIFEST.in setup.cfg setup.py versioneer.py $PLUGIN_NAME/_version.py &&
mkdir conda-recipe &&
mv ci/recipe/meta.yaml conda-recipe/meta.yaml
- name: 'Update versioning in __init__.py'
run: |
python - <<EOF
init_path = "$PLUGIN_NAME/__init__.py"
with open(init_path, "r", encoding="utf-8") as f:
lines = f.readlines()
lines = [l for l in lines if "from ._version import get_versions" not in l]
content = "".join(lines)
old_block = (
"__version__ = get_versions()['version']\n"
"del get_versions"
)
new_block = (
"try:\n"
" from ._version import __version__\n"
"except ModuleNotFoundError:\n"
" __version__ = '0.0.0+notfound'"
)
updated_content = content.replace(old_block, new_block)
with open(init_path, "w", encoding="utf-8") as f:
f.write(updated_content)
EOF
- name: 'Update install command in Makefile'
run: |
python - <<EOF
with open("Makefile", "r", encoding="utf-8") as f:
content = f.read()
old_block = ("$(PYTHON) setup.py install")
new_block = ("$(PYTHON) -m pip install -v .")
updated_content = content.replace(old_block, new_block)
with open("Makefile", "w", encoding="utf-8") as f:
f.write(updated_content)
EOF
- name: 'Add _version.py to .gitignore'
run: |
python - <<EOF
version_file = (
"\n"
"# Version file from versioningit\n"
"_version.py\n"
"\n"
)
with open(".gitignore", "a", encoding="utf-8") as f:
f.write(version_file)
EOF
- name: 'Update location of recipe file in ci-dev workflow'
run: |
python - <<EOF
import sys
ci_dev_path = ".github/workflows/ci-dev.yaml"
with open(ci_dev_path, "r", encoding="utf-8") as f:
content = f.read()
old_path = (
"distro: ${{ env.distro }}"
)
new_path = (
"distro: ${{ env.distro }}\n"
" recipe-path: 'conda-recipe'"
)
updated_content = content.replace(old_path, new_path)
with open(ci_dev_path, "w", encoding="utf-8") as f:
f.write(updated_content)
EOF
- name: 'Update recipe file with pyproject.toml dependencies'
run: |
pip install --upgrade pyyaml
python - <<EOF
import os
import yaml
recipe_path = "conda-recipe/meta.yaml"
if not os.path.exists(recipe_path):
raise Exception(f"{recipe_path} not found.")
jinja_lines = []
with open(recipe_path, "r", encoding="utf-8") as fp:
for line in fp:
if line.strip().startswith("{%"):
continue
jinja_lines.append(line)
content = "".join(jinja_lines)
content = content.replace("{{ version }}", "0.0.dummy")
data = yaml.safe_load(content)
data["source"]["path"] = ".."
build_deps = ['setuptools', 'versioningit']
host_deps = ['setuptools', 'versioningit', 'wheel']
if 'build' not in data['requirements']:
data['requirements']['build'] = []
for dep in build_deps:
if dep not in data['requirements']['build']:
data['requirements']['build'].append(dep)
for dep in host_deps:
if dep not in data['requirements']['host']:
data['requirements']['host'].append(dep)
output = yaml.safe_dump(data, sort_keys=False).replace("0.0.dummy", "{{ PLUGIN_VERSION }}")
with open(recipe_path, "w", encoding="utf-8") as fp:
fp.write(output)
EOF
- name: 'Install and run copier'
run: |
pip install copier
copier copy \
--data project_name="$PROJECT_NAME" \
--data plugin_name="$PLUGIN_NAME" \
--data module_name="$MODULE_NAME" \
--data project_author_name="$PROJECT_AUTHOR_NAME" \
--data project_author_email="$PROJECT_AUTHOR_EMAIL" \
--data project_description="$PROJECT_DESCRIPTION" \
--data project_urls_homepage="$PROJECT_URLS_HOMEPAGE" \
--data project_urls_repository="$PROJECT_URLS_REPOSITORY" \
--data plugin_scripts="$PLUGIN_SCRIPTS" \
https://github.com/qiime2/q2-setup-template.git .
- name: 'Create pull request from copier changes'
uses: qiime2/create-pull-request@v5
with:
token: ${{ secrets. BOT_PAT }}
branch: automated/pyproject-toml-update
title: "setup.py -> pyproject.toml"
body: |
Transition from setup.py & friends to pyproject.toml
author: "q2d2 <[email protected]>"
committer: "q2d2 <[email protected]>"
commit-message: |
Transition from setup.py & friends to pyproject.toml