Skip to content

Commit 2ece20a

Browse files
authored
Add Anaconda publishing (#26)
* Create conda.yml * Add formatting script * Add conda publishing automation * Increment version
1 parent 60b6a8e commit 2ece20a

File tree

7 files changed

+155
-6
lines changed

7 files changed

+155
-6
lines changed

.github/workflows/format.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# GitHub Action that uses Black to reformat the Python code in an incoming pull request.
2+
# If all Python code in the pull request is compliant with Black then this Action does nothing.
3+
# Otherwise, Black is run and its changes are committed back to the incoming pull request.
4+
5+
name: Format
6+
7+
on:
8+
push:
9+
branches: [ main ]
10+
pull_request:
11+
12+
jobs:
13+
format:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Set up Python
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: 3.x
21+
- name: Install Black
22+
run: pip install black
23+
- name: Run black --check .
24+
run: black --check .
25+
- name: If needed, commit black changes to the pull request
26+
if: failure()
27+
run: |
28+
black .
29+
git config --global user.name 'formatting'
30+
git config --global user.email 'mikeheddes@users.noreply.github.com'
31+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
32+
git checkout $GITHUB_HEAD_REF
33+
git commit -am "Format Python code"
34+
git push

.github/workflows/publish.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ permissions:
1616
contents: read
1717

1818
jobs:
19-
deploy:
20-
19+
pypi:
2120
runs-on: ubuntu-latest
22-
2321
steps:
2422
- uses: actions/checkout@v3
2523
- name: Set up Python
2624
uses: actions/setup-python@v3
2725
with:
28-
python-version: '3.x'
26+
python-version: 3.x
2927
- name: Install dependencies
3028
run: |
3129
python -m pip install --upgrade pip
@@ -38,3 +36,26 @@ jobs:
3836
uses: pypa/gh-action-pypi-publish@master
3937
with:
4038
password: ${{ secrets.PYPI_PASSWORD }}
39+
40+
anaconda:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v3
44+
- name: Set up Python
45+
uses: actions/setup-python@v3
46+
with:
47+
python-version: 3.x
48+
- name: Add conda to system path
49+
run: |
50+
# $CONDA is an environment variable pointing to the root of the miniconda directory
51+
echo $CONDA/bin >> $GITHUB_PATH
52+
- name: Install dependencies
53+
run: |
54+
conda install -y anaconda-client conda-build conda-verify
55+
- name: Publish distribution to Anaconda
56+
with:
57+
subdir: 'conda'
58+
anacondatoken: ${{ secrets.ANACONDA_TOKEN }}
59+
platforms: 'win osx linux'
60+
run: >-
61+
./scripts/conda_publish.sh

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Testing
1+
name: Test
22

33
on:
44
push:

conda/conda_build_config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
python:
2+
- 3.6
3+
- 3.7
4+
- 3.8
5+
- 3.9
6+
- 3.10

conda/meta.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{% set data = load_setup_py_data() %}
2+
3+
package:
4+
name: hdc
5+
version: {{ data['version'] }}
6+
7+
source:
8+
path: ..
9+
10+
build:
11+
number: 0
12+
script: python setup.py install --single-version-externally-managed --record=record.txt
13+
14+
requirements:
15+
build:
16+
- python>=3.6
17+
- torch
18+
- pandas
19+
20+
run:
21+
- python>=3.6
22+
- torch
23+
- pandas
24+
25+
test:
26+
imports:
27+
- hdc
28+
29+
about:
30+
home: {{ data['url'] }}
31+
license: {{ data['license'] }}
32+
summary: {{ data['description'] }}

scripts/conda_publish.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
set -o pipefail
5+
6+
go_to_build_dir() {
7+
if [ ! -z $INPUT_SUBDIR ]; then
8+
cd $INPUT_SUBDIR
9+
fi
10+
}
11+
12+
check_if_setup_file_exists() {
13+
if [ ! -f setup.py ]; then
14+
echo "setup.py must exist in the directory that is being packaged and published."
15+
exit 1
16+
fi
17+
}
18+
19+
check_if_meta_yaml_file_exists() {
20+
if [ ! -f meta.yaml ]; then
21+
echo "meta.yaml must exist in the directory that is being packaged and published."
22+
exit 1
23+
fi
24+
}
25+
26+
build_package(){
27+
# Build for Linux
28+
conda build -c conda-forge -c pytorch --output-folder . .
29+
30+
# Convert to other platforms: OSX, WIN
31+
if [[ $INPUT_PLATFORMS == *"osx"* ]]; then
32+
conda convert -p osx-64 linux-64/*.tar.bz2
33+
fi
34+
if [[ $INPUT_PLATFORMS == *"win"* ]]; then
35+
conda convert -p win-64 linux-64/*.tar.bz2
36+
fi
37+
}
38+
39+
upload_package(){
40+
export ANACONDA_API_TOKEN=$INPUT_ANACONDATOKEN
41+
if [[ $INPUT_PLATFORMS == *"osx"* ]]; then
42+
anaconda upload --label main osx-64/*.tar.bz2
43+
fi
44+
if [[ $INPUT_PLATFORMS == *"linux"* ]]; then
45+
anaconda upload --label main linux-64/*.tar.bz2
46+
fi
47+
if [[ $INPUT_PLATFORMS == *"win"* ]]; then
48+
anaconda upload --label main win-64/*.tar.bz2
49+
fi
50+
}
51+
52+
check_if_setup_file_exists
53+
go_to_build_dir
54+
check_if_meta_yaml_file_exists
55+
build_package
56+
upload_package

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="hdc",
10-
version="0.5.0",
10+
version="0.5.1",
1111
description="Python library for Hyperdimensional Computing",
1212
long_description=open("README.md").read(),
1313
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)