Skip to content

Commit

Permalink
Merge pull request #36 from potassco:WIP_conda-publish
Browse files Browse the repository at this point in the history
Include Workflow to Publish to Conda
  • Loading branch information
stephanzwicknagl authored Dec 13, 2023
2 parents 326e564 + 7238d69 commit b05409c
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 2 deletions.
83 changes: 83 additions & 0 deletions .github/conda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python
'''
Simple script to call conda build with the current revision and version.
'''

import argparse
import subprocess
import json
from re import match
import os

NAME = 'viasp'

def get_build_number(channels, version):
'''
Get the next build number.
'''
try:
pkgs = json.loads(subprocess.check_output(['conda', 'search', '--json', '-c', channels[0], NAME]))
except subprocess.CalledProcessError:
pkgs = {NAME: []}


build_number = -1
for pkg in pkgs.get(NAME, []):
if pkg['channel'].find(channels[0]) >= 0 and pkg["version"] == version:
build_number = max(build_number, pkg['build_number'])

return build_number + 1

def run():
'''
Compile and upload conda packages.
'''

parser = argparse.ArgumentParser(description='Build conda packages.')
parser.add_argument('--release', action='store_true', help='Build release packages.')
parser.add_argument('--package', type=str, help='Package to build. (frontend, backend, or viasp)', default='frontend')
args = parser.parse_args()
if args.release:
label = None
channels = ['potassco']
else:
label = "dev"
channels = ['potassco/label/dev', 'potassco']

path = 'viasp-dash'
if args.package == 'backend':
path = 'viasp-backend'
channels.extend(['conda-forge'])
elif args.package == 'viasp':
path = 'viasp'
channels.extend(['conda-forge', 'stephanzwicknagl/label/dev']) # change this to wherever the viasp-dash and viasp-backend are hosted

version = None
with open('setup.cfg') as fh:
for line in fh:
m = match(r'''[ ]*version[ ]*=[ ]*([0-9]+\.[0-9]+\.[0-9]+)(\.post[0-9]+)?''', line)
if m is not None:
version = m.group(1)
assert version is not None
build_number = get_build_number(channels, version)

build_env = os.environ.copy()
build_env.pop("BUILD_RELEASE", "1" if args.release else None)
build_env["VERSION_NUMBER"] = version
build_env["BUILD_NUMBER"] = str(build_number)
if 'GITHUB_SHA' in os.environ:
build_env["BUILD_REVISION"] = os.environ['GITHUB_SHA']

recipe_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conda', path)
options = ['conda', 'build']
if label is not None:
options.extend(['--label', label])

for c in channels:
options.extend(['-c', c])
options.append(recipe_path)

subprocess.check_call(options, env=build_env)

if __name__ == '__main__':
run()
48 changes: 48 additions & 0 deletions .github/conda/viasp-backend/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% set name = "viasp-backend" %}
{% set version = environ.get('VERSION_NUMBER') %}
{% set dev = not environ.get('BUILD_RELEASE', false) %}
{% set revision = environ.get('GITHUB_SHA', 'wip') %}
{% set build = environ.get('BUILD_NUMBER', "0") %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
path: ../../../backend

build:
noarch: python
script: python -m pip install --no-deps --ignore-installed .
number: {{ build }}
entry_points:
['viasp_server = viasp.__main__:backend',
'viasp = viasp.__main__:start']

requirements:
host:
- python >=3.7
- setuptools >=42
- wheel
- pip
run:
- python >=3.7
- networkx >=2.4
- flask ==2.2.0
- werkzeug ==2.2.2
- clingo >=5.6.0
- flask-cors >=3.0
- requests >=2.26.0
- igraph >=0.8
- numpy
- clingraph

about:
home: https://github.com/potassco/viasp
summary: The backend for the viasp package.
license: MIT
license_file: LICENCE.md

extra:
recipe-maintainers:
- stephanzwicknagl
39 changes: 39 additions & 0 deletions .github/conda/viasp-dash/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% set name = "viasp-dash" %}
{% set version = "2.0.2" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
path: ../../../frontend

build:
noarch: python
script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation
number: 0

requirements:
host:
- python
- pip
run:
- python
- dash >=2

test:
imports:
- viasp_dash
commands:
- pip check
requires:
- pip

about:
summary: The dash frontend for the viasp package.
license: MIT
license_file: LICENCE.md

extra:
recipe-maintainers:
- stephanzwicknagl
44 changes: 44 additions & 0 deletions .github/conda/viasp/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% set name = "viasp" %}
{% set version = "2.0.2" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
path: ../../..

build:
noarch: python
script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation
number: {{ build }}

requirements:
host:
- python >=3.7
- setuptools >=42
- wheel
- pip
run:
- python >=3.7
- viasp-backend
- viasp-dash
- jupyter-server-proxy
- clingraph
- python-graphviz

test:
imports:
- viasp
- viasp_server

about:

home: https://github.com/potassco/viasp
summary: a visualization tool for clingo.
license: MIT
license_file: LICENCE.md

extra:
recipe-maintainers:
- stephanzwicknagl
112 changes: 112 additions & 0 deletions .github/workflows/publish_conda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Deploy conda packages

on:
workflow_dispatch:
inputs:
frontend:
type: boolean
required: true
description: Publish frontend of main HEAD
backend:
type: boolean
required: true
description: Publish backend of main HEAD

jobs:
backend:
name: Publish backend
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: recursive

- name: setup miniconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: 3.11
activate-environment: build

- name: Install prerequisites
run: |
conda config --set anaconda_upload yes
conda install conda-build anaconda-client
- name: print info
shell: pwsh
run: |
conda info
conda list
- name: publish conda package backend
shell: pwsh
run: |
python .github/conda.py --package backend
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}

frontend:
name: Publish frontend
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: recursive

- name: setup miniconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: 3.11
activate-environment: build

- name: Install prerequisites
run: |
conda config --set anaconda_upload yes
conda install conda-build anaconda-client
- name: print info
shell: pwsh
run: |
conda info
conda list
- name: publish conda package frontend
shell: pwsh
run: |
python .github/conda.py --package frontend
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}

wrapper:
needs: [ frontend, backend ]
name: Publish container
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: recursive

- name: setup miniconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: 3.11
activate-environment: build

- name: Install prerequisites
run: |
conda config --set anaconda_upload yes
conda install conda-build anaconda-client
- name: print info
shell: pwsh
run: |
conda info
conda list
- name: publish conda package wrapper
shell: pwsh
run: |
python .github/conda.py --package viasp
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
File renamed without changes.
21 changes: 21 additions & 0 deletions backend/LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Luis Glaser, Stephan Zwicknagl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 0 additions & 1 deletion backend/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ install_requires =
Werkzeug==2.2.2
clingo>=5.6.0
flask-cors>=3.0
clingox>=1.0.0
requests>=2.26.0
igraph>=0.8
numpy
Expand Down
21 changes: 21 additions & 0 deletions frontend/LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Luis Glaser, Stephan Zwicknagl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ flask>=2.0,<=2.2.5
Werkzeug==2.2.2
networkx>=2.6
pytest>=6.2.4
clingox>=1.0.0
requests
dash
flask-cors
Expand Down

0 comments on commit b05409c

Please sign in to comment.