Skip to content

Commit c796ba5

Browse files
authored
Auto update conda package (#104)
* add conda install to readme * test pip and conda installs * fix yml * update CI config * checkout version not latest * test and update version in package test * v * conda channels * no 3? * ci config * activate? * pytest not python -m * isntall and run in one run * no [python -m * shell? * test packages weekly * Revert "test packages weekly" This reverts commit 62f4a86. * run tests in PyPI zip * -O * folder name has version * requirements * Start writing conda auto updater * Conda updating script * only test weekly * no need to cd twice
1 parent 382be84 commit c796ba5

File tree

8 files changed

+204
-6
lines changed

8 files changed

+204
-6
lines changed

++version.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,21 @@
4141
with open("symfem/version.py", "w") as f:
4242
f.write(f'"""Version number."""\n\nversion = "{new_version_str}"\n')
4343

44+
# .github/workflows/test-packages.yml
45+
new_test = ""
46+
url = "https://pypi.io/packages/source/s/symfem/symfem-"
47+
with open(".github/workflows/test-packages.yml") as f:
48+
for line in f:
49+
if "ref:" in line:
50+
new_test += line.split("ref:")[0]
51+
new_test += f"ref: v{new_version_str}\n"
52+
elif url in line:
53+
new_test += line.split(url)[0]
54+
new_test += f"{url}{new_version_str}.tar.gz\n"
55+
elif "cd symfem-" in line:
56+
new_test += line.split("cd symfem-")[0]
57+
new_test += f"cd symfem-{new_version_str}\n"
58+
else:
59+
new_test += line
60+
4461
print(f"Updated version to {new_version_str}")

.github/scripts/conda.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import json
2+
import sys
3+
import github
4+
import urllib.request
5+
6+
access_key = sys.argv[-1]
7+
8+
git = github.Github(access_key)
9+
10+
symfem = git.get_repo("mscroggs/symfem")
11+
branch = symfem.get_branch("main")
12+
13+
version = symfem.get_contents("VERSION", branch.commit.sha).decoded_content.decode()
14+
15+
with urllib.request.urlopen(f"https://pypi.org/pypi/symfem/{version}/json") as f:
16+
data = json.load(f)
17+
18+
for file in data["releases"][version]:
19+
if file["packagetype"] == "sdist":
20+
hash = file["digests"]["sha256"]
21+
22+
print(hash)
23+
24+
upstream_feedstock = git.get_repo("conda-forge/symfem-feedstock")
25+
upstream_branch = upstream_feedstock.get_branch("master")
26+
27+
fork = git.get_user().create_fork(upstream_feedstock)
28+
29+
u = git.get_user()
30+
31+
for repo in u.get_repos():
32+
if repo.full_name.startswith("symfembot/symfem-feedstock"):
33+
repo.delete()
34+
35+
fork = git.get_user().create_fork(upstream_feedstock)
36+
branch = fork.get_branch("master")
37+
38+
old_meta = fork.get_contents("recipe/meta.yaml", branch.commit.sha)
39+
40+
old_meta_lines = old_meta.decoded_content.decode().split("\n")
41+
new_meta_lines = []
42+
for line in old_meta_lines:
43+
if line.startswith("{% version"):
44+
new_meta_lines.append(f"{{% set version = \"{version}\" %}}")
45+
elif "sha256" in line:
46+
newline = line.split("sha256")[0]
47+
newline += f"sha256: {hash}"
48+
new_meta_lines.append(newline)
49+
else:
50+
new_meta_lines.append(line)
51+
52+
new_meta_lines += ["TEST", ""]
53+
54+
fork.update_file("recipe/meta.yaml", "Update version", "\n".join(new_meta_lines), sha=old_meta.sha)
55+
56+
upstream_feedstock.create_pull(title=f"Update version to {version}",
57+
body="", base="master", head="symfembot:master")

.github/workflows/check-version-numbers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
- name: Install PyGitHub
1515
run: pip3 install PyGitHub
1616
- name: Check version number and make release if necessary
17-
run: python .github/scripts/version.py ${{ secrets.symfembot_github_token }} ${{ steps.get_version.outputs.VERSION }}
17+
run: python .github/scripts/version.py ${{ secrets.symfembot_github_token }}

.github/workflows/push-to-pypi.yml renamed to .github/workflows/push-packages.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- 'v*'
88

99
jobs:
10-
build-n-publish:
10+
pypi:
1111
name: Build and publish to PyPI
1212
runs-on: ubuntu-20.04
1313
steps:
@@ -27,10 +27,21 @@ jobs:
2727
with:
2828
password: ${{ secrets.pypi_password }}
2929

30-
trigger-read-the-docs:
30+
read-the-docs:
3131
name: Trigger Read the Docs build
3232
runs-on: ubuntu-20.04
3333
steps:
3434
- uses: actions/checkout@master
3535
- name: Trigger Read the Docs build
3636
run: python .github/scripts/trigger_rtd_build.py ${{ secrets.RTDS_TOKEN }}
37+
38+
conda:
39+
name: Open conda-forge PR
40+
needs: pypi
41+
runs-on: ubuntu-20.04
42+
steps:
43+
- uses: actions/checkout@master
44+
- name: Install PyGitHub
45+
run: pip3 install PyGitHub requests
46+
- name: Open PR to update conda package
47+
run: python .github/scripts/conda.py ${{ secrets.conda_github_token }}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: 🧪📦 Test packages
2+
3+
on:
4+
schedule:
5+
- cron: "0 7 * * 1"
6+
7+
jobs:
8+
run-tests-with-pip:
9+
name: Run tests with Symfem installed from pip
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: [3.7, 3.8]
14+
steps:
15+
- name: Set up Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- uses: actions/checkout@v2
20+
with:
21+
ref: v2021.7.5
22+
name: Get latest Symfem version
23+
- run: rm -rf symfem VERSION
24+
name: Remove downloaded symfem
25+
- run: python3 -m pip install symfem
26+
name: Install Symfem
27+
- run: pip install pytest
28+
name: Install pytest
29+
- run: python3 -m pytest test/
30+
name: Run unit tests
31+
- run: python3 -m pytest demo/test_demos.py
32+
name: Run demos
33+
34+
run-tests-with-conda:
35+
name: Run tests with Symfem installed from conda-forge
36+
runs-on: ubuntu-latest
37+
strategy:
38+
matrix:
39+
python-version: [3.7, 3.8]
40+
steps:
41+
- uses: conda-incubator/setup-miniconda@v2
42+
with:
43+
auto-update-conda: true
44+
python-version: ${{ matrix.python-version }}
45+
activate-environment: symfem
46+
- uses: actions/checkout@v2
47+
with:
48+
ref: v2021.7.5
49+
name: Get latest Symfem version
50+
- run: rm -rf symfem VERSION
51+
name: Remove downloaded symfem
52+
- run: |
53+
conda config --add channels conda-forge
54+
conda config --set channel_priority strict
55+
conda install symfem
56+
conda install pytest
57+
pytest test/
58+
pytest demo/test_demos.py
59+
shell: bash -l {0}
60+
name: Install Symfem and run tests
61+
62+
run-test-with-pypi-zip:
63+
name: Run tests with Symfem downloaded from PyPI
64+
runs-on: ubuntu-latest
65+
strategy:
66+
matrix:
67+
python-version: [3.7, 3.8]
68+
steps:
69+
- name: Set up Python
70+
uses: actions/setup-python@v2
71+
with:
72+
python-version: ${{ matrix.python-version }}
73+
- run: |
74+
wget -O symfem.tar.gz https://pypi.io/packages/source/s/symfem/symfem-2021.7.5.tar.gz
75+
tar -xvzf symfem.tar.gz
76+
name: Download and unpack latest version of Symfem
77+
- run: pip install pytest sympy numpy
78+
name: Install pytest, sympy and numpy
79+
- run: |
80+
cd symfem-2021.7.5
81+
python3 -m pytest test/
82+
python3 -m pytest demo/test_demos.py
83+
name: Run tests and demos

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,28 @@ Symfem is a symbolic finite element definition library, that can be used to
1010
symbolically evaluate the basis functions of a finite element space.
1111

1212
## Installing Symfem
13+
### Installing from repo
1314
Symfem can be installed by downloading the [GitHub repo](https://github.com/mscroggs/symfem)
1415
and running:
1516

1617
```bash
1718
python3 setup.py install
1819
```
1920

20-
Alternatively, the latest stable release can be installed by running:
21+
### Installing using pip
22+
The latest release of Symfem can be installed by running:
2123

2224
```bash
2325
pip3 install symfem
2426
```
2527

28+
### Installing using conda
29+
The latest release of Symfem can be installed by running:
30+
31+
```bash
32+
conda install symfem
33+
```
34+
2635
## Testing Symfem
2736
To run the Symfem unit tests, clone the repository and run:
2837

setup.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,28 @@
1818
symbolically evaluate the basis functions of a finite element space.
1919
2020
## Installing Symfem
21+
### Installing from repo
2122
Symfem can be installed by downloading the [GitHub repo](https://github.com/mscroggs/symfem)
2223
and running:
2324
2425
```bash
2526
python3 setup.py install
2627
```
2728
28-
Alternatively, the latest stable release can be installed by running:
29+
### Installing using pip
30+
The latest release of Symfem can be installed by running:
2931
3032
```bash
3133
pip3 install symfem
3234
```
3335
36+
### Installing using conda
37+
The latest release of Symfem can be installed by running:
38+
39+
```bash
40+
conda install symfem
41+
```
42+
3443
## Testing Symfem
3544
To run the Symfem unit tests, clone the repository and run:
3645
@@ -46,7 +55,8 @@
4655
You can find information about how to contribute to Symfem [here](CONTRIBUTING.md).
4756
"""
4857

49-
data_files = ["LICENSE", ("test", ["test/__init__.py", "test/utils.py", "test/conftest.py"])]
58+
data_files = ["LICENSE", "requirements.txt",
59+
("test", ["test/__init__.py", "test/utils.py", "test/conftest.py"])]
5060

5161
if __name__ == "__main__":
5262
setuptools.setup(

test/test_docs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ def test_version_numbers():
109109
with open(os.path.join(root, "symfem/version.py")) as f:
110110
assert f.read().split('version = "')[1].split('"')[0] == version
111111

112+
# .github/workflows/test-packages.yml
113+
url = "https://pypi.io/packages/source/s/symfem/symfem-"
114+
with open(os.path.join(root, ".github/workflows/test-packages.yml")) as f:
115+
for line in f:
116+
if "ref:" in line:
117+
assert line.split("ref:")[1].strip() == "v" + version
118+
elif url in line:
119+
assert line.split(url)[1].split(".tar.gz")[0] == version
120+
elif "cd symfem-" in line:
121+
assert line.split("cd symfem-")[1].strip() == version
122+
112123

113124
def test_requirements():
114125
root = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")

0 commit comments

Comments
 (0)