Skip to content

Commit e0bb3cd

Browse files
authored
ver: bump version to 0.4.2 (#31)
* ver: bump version to 0.4.2 * docs(CHANGELOG): add CHANGELOG.md * docs: update dictionary * docs: update authors * feat(workflows): test wheels before release * fix(workflows): remove single-quotes in env files * chore(workflows): update triggers * chore: install torchopt in conda environment * chore(.gitignore): ignore wheelhouse * style: update pylint magic comments * chore(conda-recipe): add patchelf * chore(workflows): update triggers * feat: manylinux wheels * docs: update install instruction * chore(workflows): list wheels with size * chore(workflows): use pypa/gh-action-pypi-publish to upload packages * docs: add badges * fix(workflows): show wheels one-by-one * docs: update contribution guide line * chore(pyproject): use pyproject.toml * chore: support str for accelerated_op_available * chore(workflows): test wheels with CPU build of torch * docs: update CHANGELOG * fix(accelerated_op): skip checking op on cuda devices when CUDA is not available * chore: update conda-recipe.yaml * docs: update CHANGELOG * docs: update badges * chore: remove pip edit install in conda recipe
1 parent bdf1558 commit e0bb3cd

21 files changed

+475
-220
lines changed

.github/workflows/build.yml

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main # allow to trigger the workflow with tag push event
7+
pull_request:
8+
paths:
9+
- setup.py
10+
- setup.cfg
11+
- pyproject.toml
12+
- MANIFEST.in
13+
- CMakeLists.txt
14+
- include/**
15+
- src/**
16+
- torchopt/version.py
17+
- .github/workflow/build.yml
18+
release:
19+
types:
20+
- published
21+
# Allow to trigger the workflow manually
22+
workflow_dispatch:
23+
24+
permissions:
25+
contents: read
26+
27+
concurrency:
28+
group: "${{ github.workflow }}-${{ github.ref }}"
29+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
30+
31+
jobs:
32+
build:
33+
runs-on: ubuntu-18.04
34+
if: github.repository == 'metaopt/TorchOpt' && (github.event_name != 'push' || startsWith(github.ref, 'refs/tags/'))
35+
timeout-minutes: 45
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v3
39+
with:
40+
submodules: "recursive"
41+
fetch-depth: 1
42+
43+
- name: Set up Python 3.7
44+
id: py37
45+
uses: actions/setup-python@v4
46+
with:
47+
python-version: "3.7"
48+
update-environment: false
49+
50+
- name: Set up Python 3.8
51+
id: py38
52+
uses: actions/setup-python@v4
53+
with:
54+
python-version: "3.8"
55+
update-environment: false
56+
57+
- name: Set up Python 3.9
58+
id: py39
59+
uses: actions/setup-python@v4
60+
with:
61+
python-version: "3.9"
62+
update-environment: false
63+
64+
- name: Set up Python 3.10
65+
id: py310
66+
uses: actions/setup-python@v4
67+
with:
68+
python-version: "3.10"
69+
update-environment: false
70+
71+
- name: Set up Python executable paths
72+
run: |
73+
echo "${{ steps.py37.outputs.python-path }}" > .python-paths
74+
echo "${{ steps.py38.outputs.python-path }}" >> .python-paths
75+
echo "${{ steps.py39.outputs.python-path }}" >> .python-paths
76+
echo "${{ steps.py310.outputs.python-path }}" >> .python-paths
77+
78+
- name: Setup CUDA Toolkit
79+
uses: Jimver/cuda-toolkit@v0.2.7
80+
id: cuda-toolkit
81+
with:
82+
cuda: "11.6.2"
83+
method: network
84+
sub-packages: '["nvcc"]'
85+
- run: |
86+
CUDA_VERSION="${{steps.cuda-toolkit.outputs.cuda}}"
87+
echo "CUDA_VERSION=${CUDA_VERSION}" >> "${GITHUB_ENV}"
88+
TORCH_INDEX_URL="https://download.pytorch.org/whl/cu$(echo "${CUDA_VERSION}" | cut -d'.' -f-2 | tr -d '.')"
89+
echo "TORCH_INDEX_URL=${TORCH_INDEX_URL}" >> "${GITHUB_ENV}"
90+
91+
echo "Installed CUDA version is: ${CUDA_VERSION}"
92+
echo "CUDA install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}"
93+
nvcc -V
94+
echo "Torch index URL: ${TORCH_INDEX_URL}"
95+
96+
- name: Build sdist and wheels
97+
run: |
98+
DEFAULT_PYTHON="$(head -n 1 .python-paths)"
99+
100+
while read -r PYTHON; do
101+
echo "Building wheel with Python: ${PYTHON} ($("${PYTHON}" --version))"
102+
"${PYTHON}" -m pip install --upgrade pip setuptools wheel build
103+
"${PYTHON}" -m pip install --extra-index-url "${TORCH_INDEX_URL}" \
104+
-r requirements.txt
105+
if [[ "${PYTHON}" == "${DEFAULT_PYTHON}" ]]; then
106+
"${PYTHON}" -m build
107+
else
108+
"${PYTHON}" -m build --wheel
109+
fi
110+
done < .python-paths
111+
112+
- name: List built sdist and wheels
113+
run: |
114+
if [[ -n "$(find dist -maxdepth 0 -not -empty -print 2>/dev/null)" ]]; then
115+
echo "Built sdist and wheels:"
116+
ls -lh dist/
117+
else
118+
echo "No sdist and wheels are built."
119+
exit 1
120+
fi
121+
122+
- name: Audit and repair wheels
123+
run: |
124+
while read -r PYTHON; do
125+
PYVER="cp$("${PYTHON}" --version | cut -d ' ' -f2 | cut -d '.' -f-2 | tr -d '.')"
126+
echo "Audit and repair wheel for Python: ${PYTHON} (${PYVER})"
127+
LIBTORCH_PATH="$("${PYTHON}" -c 'import os, site; print(os.path.join(site.getsitepackages()[0], "torch", "lib"))')"
128+
"${PYTHON}" -m pip install --upgrade git+https://github.com/XuehaiPan/auditwheel.git@torchopt
129+
(
130+
export LD_LIBRARY_PATH="${LIBTORCH_PATH}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
131+
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
132+
"${PYTHON}" -m auditwheel show dist/torchopt-*-${PYVER}-*.whl &&
133+
"${PYTHON}" -m auditwheel repair --plat manylinux2014_x86_64 --wheel-dir wheelhouse dist/torchopt-*-${PYVER}-*.whl
134+
)
135+
done < .python-paths
136+
137+
rm dist/torchopt-*.whl
138+
mv wheelhouse/torchopt-*manylinux*.whl dist/
139+
140+
- name: List built sdist and wheels
141+
run: |
142+
if [[ -n "$(find dist -maxdepth 0 -not -empty -print 2>/dev/null)" ]]; then
143+
echo "Built sdist and wheels:"
144+
ls -lh dist/
145+
else
146+
echo "No sdist and wheels are built."
147+
exit 1
148+
fi
149+
150+
- name: Test sdist and wheels
151+
run: |
152+
DEFAULT_PYTHON="$(head -n 1 .python-paths)"
153+
while read -r PYTHON; do
154+
PYVER="cp$("${PYTHON}" --version | cut -d ' ' -f2 | cut -d '.' -f-2 | tr -d '.')"
155+
mkdir -p "temp-${PYVER}"
156+
pushd "temp-${PYVER}"
157+
if [[ "${PYTHON}" == "${DEFAULT_PYTHON}" ]]; then
158+
echo "Testing sdist with Python: ${PYTHON} (${PYVER})"
159+
"${PYTHON}" -m pip uninstall torch torchopt -y
160+
"${PYTHON}" -m pip install --extra-index-url https://download.pytorch.org/whl/cpu \
161+
../dist/torchopt-*.tar.gz
162+
"${PYTHON}" -c 'import torchopt'
163+
fi
164+
echo "Testing wheel with Python: ${PYTHON} (${PYVER})"
165+
"${PYTHON}" -m pip uninstall torch torchopt -y
166+
"${PYTHON}" -m pip install --extra-index-url https://download.pytorch.org/whl/cpu \
167+
../dist/torchopt-*-${PYVER}-*.whl
168+
"${PYTHON}" -c 'import torchopt'
169+
"${PYTHON}" -m pip uninstall torch torchopt -y
170+
popd
171+
done < .python-paths
172+
173+
- name: Check consistency between the package version and release tag
174+
if: startsWith(github.ref, 'refs/tags/')
175+
run: |
176+
RELEASE_TAG="${GITHUB_REF#refs/*/}"
177+
PACKAGE_VER="v$(python setup.py --version)"
178+
if [[ "${PACKAGE_VER}" != "${RELEASE_TAG}" ]]; then
179+
echo "package ver. (${PACKAGE_VER}) != release tag. (${RELEASE_TAG})"
180+
exit 1
181+
fi
182+
183+
- name: Publish to TestPyPI
184+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
185+
uses: pypa/gh-action-pypi-publish@v1.5.0
186+
with:
187+
user: __token__
188+
password: ${{ secrets.TESTPYPI_UPLOAD_TOKEN }}
189+
repository_url: https://test.pypi.org/legacy/
190+
verbose: true
191+
print_hash: true
192+
skip_existing: true
193+
194+
- name: Publish to PyPI
195+
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
196+
uses: pypa/gh-action-pypi-publish@v1.5.0
197+
with:
198+
user: __token__
199+
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
200+
verbose: true
201+
print_hash: true
202+
skip_existing: true

.github/workflows/lint.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ on:
99
permissions:
1010
contents: read
1111

12+
concurrency:
13+
group: "${{ github.workflow }}-${{ github.ref }}"
14+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
15+
1216
jobs:
1317
lint:
1418
runs-on: ubuntu-latest
1519
timeout-minutes: 30
1620
steps:
17-
- name: Cancel previous run
18-
uses: styfle/cancel-workflow-action@0.10.0
19-
with:
20-
access_token: ${{ github.token }}
21-
2221
- name: Checkout
2322
uses: actions/checkout@v3
2423
with:
@@ -40,9 +39,9 @@ jobs:
4039
sub-packages: '["nvcc"]'
4140
- run: |
4241
CUDA_VERSION="${{steps.cuda-toolkit.outputs.cuda}}"
43-
echo "CUDA_VERSION='${CUDA_VERSION}'" >> "${GITHUB_ENV}"
42+
echo "CUDA_VERSION=${CUDA_VERSION}" >> "${GITHUB_ENV}"
4443
TORCH_INDEX_URL="https://download.pytorch.org/whl/cu$(echo "${CUDA_VERSION}" | cut -d'.' -f-2 | tr -d '.')"
45-
echo "TORCH_INDEX_URL='${TORCH_INDEX_URL}'" >> "${GITHUB_ENV}"
44+
echo "TORCH_INDEX_URL=${TORCH_INDEX_URL}" >> "${GITHUB_ENV}"
4645
4746
echo "Installed CUDA version is: ${CUDA_VERSION}"
4847
echo "CUDA install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}"

.github/workflows/release.yml

-98
This file was deleted.

.github/workflows/tests.yml

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,30 @@ on:
55
branches:
66
- main
77
pull_request:
8+
paths:
9+
- setup.py
10+
- setup.cfg
11+
- pyproject.toml
12+
- MANIFEST.in
13+
- CMakeLists.txt
14+
- include/**
15+
- src/**
16+
- tests/**
17+
- torchopt/**
18+
- .github/workflows/tests.yml
819

920
permissions:
1021
contents: read
1122

23+
concurrency:
24+
group: "${{ github.workflow }}-${{ github.ref }}"
25+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
26+
1227
jobs:
1328
test:
1429
runs-on: ubuntu-latest
1530
timeout-minutes: 30
1631
steps:
17-
- name: Cancel previous run
18-
uses: styfle/cancel-workflow-action@0.10.0
19-
with:
20-
access_token: ${{ github.token }}
21-
2232
- name: Checkout
2333
uses: actions/checkout@v3
2434
with:
@@ -40,9 +50,9 @@ jobs:
4050
sub-packages: '["nvcc"]'
4151
- run: |
4252
CUDA_VERSION="${{steps.cuda-toolkit.outputs.cuda}}"
43-
echo "CUDA_VERSION='${CUDA_VERSION}'" >> "${GITHUB_ENV}"
53+
echo "CUDA_VERSION=${CUDA_VERSION}" >> "${GITHUB_ENV}"
4454
TORCH_INDEX_URL="https://download.pytorch.org/whl/cu$(echo "${CUDA_VERSION}" | cut -d'.' -f-2 | tr -d '.')"
45-
echo "TORCH_INDEX_URL='${TORCH_INDEX_URL}'" >> "${GITHUB_ENV}"
55+
echo "TORCH_INDEX_URL=${TORCH_INDEX_URL}" >> "${GITHUB_ENV}"
4656
4757
echo "Installed CUDA version is: ${CUDA_VERSION}"
4858
echo "CUDA install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}"

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ parts/
2121
sdist/
2222
var/
2323
wheels/
24+
wheelhouse/
2425
share/python-wheels/
2526
*.egg-info/
2627
.installed.cfg
@@ -169,7 +170,7 @@ cython_debug/
169170
.LSOverride
170171

171172
# Icon must end with two \r
172-
Icon
173+
Icon
173174

174175
# Thumbnails
175176
._*

0 commit comments

Comments
 (0)