Skip to content

Commit

Permalink
Merge pull request #192 from ctlearn-project/testalex
Browse files Browse the repository at this point in the history
CI&CD fixes
  • Loading branch information
nietootein authored Jun 17, 2024
2 parents fd06bef + e1fc13a commit cf4719a
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/conda/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
$PYTHON setup.py install --single-version-externally-managed --record=record.txt
2 changes: 2 additions & 0 deletions .github/conda/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
$PYTHON setup.py install --single-version-externally-managed --record=record.txt
4 changes: 4 additions & 0 deletions .github/conda/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python:
- 3.12
- 3.11
- 3.10
56 changes: 56 additions & 0 deletions .github/conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% set data = load_setup_py_data() %}

package:
name: ctlearn
version: {{ data.get('version') }}
source:
path: ../..

build:
#noarch: generic
number: 0

requirements:
build:
- python #==3.12
- numpy >=1.20
- setuptools
- astropy
- scipy
- jupyter
- ctapipe ==0.20.0
- pytables >=3.8
- pandas
host:
- python #==3.12
- numpy >=1.20
- astropy
- setuptools
- scipy
- jupyter
- ctapipe ==0.20.0
- pytables >=3.8
- pandas
run:
- python #==3.12
- numpy >=1.20
- jupyter
- setuptools
- astropy
- scipy
- ctapipe ==0.20.0
- pytables >=3.8
- pandas

test:
imports:
- ctlearn
about:
home: https://github.com/ctlearn-project/ctlearn/
license: BSD3-Clause
license_file: LICENSE
summary: Deep Learning for IACT Event Reconstruction.
extra:
recipe-maintainers:
- TjarkMiener
- nietootein
1 change: 1 addition & 0 deletions .github/versionBackup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.8.0
2 changes: 2 additions & 0 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ jobs:
run: |
conda install pytest
pytest
123 changes: 123 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Release CD

on:
release:
types: [published]

jobs:
pypi-publish:
name: Publish release to PyPI
environment:
name: pypi
url: https://pypi.org/project/ctlearn/
permissions:
id-token: write
strategy:
matrix:
os: [ubuntu-22.04]
pyv: ['3.10']
max-parallel: 5
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.pyv }}
run: |
conda install -y python=${{ matrix.pyv }}
- name: Add conda to system path
run: |
#$CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install dependencies
run: |
conda env update --file environment.yml --name base
- name: Get version
run: |
output=$(python ctlearn/versionScript.py)
echo "version=$output" >> $GITHUB_OUTPUT
id: step1

- name: Write
uses: 1arp/[email protected]
with:
path: '.'
isAbsolutePath: true
file: '.github/versionBackup.txt'
content: |
${{ steps.step1.outputs.version }}
- name: Push changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "rcervinoucm"
git status
git add .
git commit -m "version update" --allow-empty
git push -u origin master
- name: Build package
run: |
python setup.py sdist bdist_wheel # Could also be python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

condapublish:
strategy:
matrix:
os: [ubuntu-22.04]
pyv: ["3.10"]
max-parallel: 5
runs-on: ${{ matrix.os }}
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.pyv }}
run: |
conda install -y python=${{ matrix.pyv }}
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install dependencies
run: |
conda env update --file environment.yml --name base
sudo apt-get install python3-numpy
- name: Get version
run: |
output=$(python ctlearn/versionScript.py)
echo "version=$output" >> $GITHUB_OUTPUT
id: step1

- name: Write
uses: 1arp/[email protected]
with:
path: '.'
isAbsolutePath: true
file: '.github/versionBackup.txt'
content: |
${{ steps.step1.outputs.version }}
- name: Push changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "rcervinoucm"
git status
git add .
git commit -m "version update" --allow-empty
git push -u origin master
- name: publish-to-conda
uses: fcakyon/[email protected]
with:
subdir: '.github/conda'
anacondatoken: ${{ secrets.ANACONDA_TOKEN }}
31 changes: 20 additions & 11 deletions ctlearn/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
but being much more lightwheight
"""
from subprocess import check_output, CalledProcessError
import subprocess
from os import path, name, devnull, environ, listdir
from ast import literal_eval

Expand All @@ -44,11 +44,11 @@ def find_git_on_windows():
"""find the path to the git executable on windows"""
# first see if git is in the path
try:
check_output(["where", "/Q", "git"])
subprocess.check_output(["where", "/Q", "git"])
# if this command succeeded, git is in the path
return "git"
# catch the exception thrown if git was not found
except CalledProcessError:
except subprocess.CalledProcessError:
pass
# There are several locations git.exe may be hiding
possible_locations = []
Expand Down Expand Up @@ -78,17 +78,26 @@ def find_git_on_windows():
GIT_COMMAND = find_git_on_windows()


def get_git_describe_version(abbrev=7):
def get_git_describe_version():
"""return the string output of git desribe"""
try:
with open(devnull, "w") as fnull:
arguments = [GIT_COMMAND, "describe", "--tags", "--abbrev=%d" % abbrev]
return (
check_output(arguments, cwd=CURRENT_DIRECTORY, stderr=fnull)
.decode("ascii")
.strip()
)
except (OSError, CalledProcessError):
repo_url = "https://github.com/ctlearn-project/ctlearn"
output_lines = subprocess.check_output(
[
"git",
"ls-remote",
"--tags",
"--refs",
"--sort=version:refname",
repo_url,
],
encoding="utf-8",
).splitlines() #nosec
last_line_ref = output_lines[-1].rpartition("/")[-1]
return (last_line_ref)

except (OSError, subprocess.CalledProcessError):
return None


Expand Down
8 changes: 8 additions & 0 deletions ctlearn/versionScript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from version import get_version_pypi

def get_version():
return get_version_pypi()


if __name__ == "__main__":
print(get_version())
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from setuptools import setup, find_packages
from os import path
from ctlearn.version import *

def getVersionFromFile():
file = open(".github/versionBackup.txt").readlines()
for line in file:
for word in line.split():
return word

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()

setup(name='ctlearn',
version=get_version_pypi(),
version=getVersionFromFile(),
author="CTLearn Team",
author_email="[email protected]",
description='Deep learning analysis framework for Imaging Atmospheric Cherenkov Telescopes, especially the Cherenkov Telescope Array (CTA) and the MAGIC telescopes.',
Expand All @@ -21,7 +26,5 @@
'console_scripts': ['ctlearn=ctlearn.run_model:main',
'build_irf=ctlearn.build_irf:main'],
},
include_package_data=True,
dependencies=[],
dependency_links=[],
zip_safe=False)
zip_safe=True)

0 comments on commit cf4719a

Please sign in to comment.