Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hatch for pycalrissian + ci tests restore #7

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Build and Test
on:
# push:
# branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
- name: Install dependencies
run: |
# python -m pip install --upgrade pip
pip install hatch
- name: Cache Hatch
id: cache-hatch
uses: actions/cache@v3
with:
path: /home/runner/.local/share/hatch/env/virtual/
key: ${{ runner.os }}-hatch
- name: Build
run: hatch build
# - name: Test
# run: |
# hatch -e test run nose2 --verbose
62 changes: 62 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Publish to PyPI

on:
push:
branches: [ "main" ]
release:
types: [published]
pull_request:
branches: [develop, main]

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name: Install dependencies
run: |
# python -m pip install --upgrade pip
pip install hatch
- name: Build package
run: hatch build
# Install Minikube
- name: Install Minikube
run: |
sudo apt-get update -y
sudo apt-get install -y apt-transport-https
sudo curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# Start Minikube
- name: Start Minikube
run: |
minikube start --driver=docker --memory=6500
# Set and export KUBECONFIG path
- name: Set KUBECONFIG path
run: |
cp ~/.kube/config ~/.kube/kubeconfig-t2-dev.yaml
echo "KUBECONFIG=$HOME/.kube/config" >> $GITHUB_ENV
echo "CI_TEST_SKIP=1" >> $GITHUB_ENV
- name: Test package
run: hatch -e test run nose2 --verbose
- name: Publish package distributions to PyPI (main)
if: github.ref == 'refs/heads/main'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://upload.pypi.org/legacy/
- name: Publish package distributions to PyPI (develop)
if: github.ref == 'refs/heads/develop'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
41 changes: 0 additions & 41 deletions Jenkinsfile

This file was deleted.

1 change: 1 addition & 0 deletions pycalrissian/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "0.7.1"
2 changes: 2 additions & 0 deletions pycalrissian/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def monitor(
self.runtime_context.batch_v1_api.delete_namespaced_job(
namespace=self.runtime_context.namespace,
name=self.namespaced_job_name,
timeout=wall_time,
)
return

Expand All @@ -232,6 +233,7 @@ def monitor(
self.runtime_context.batch_v1_api.delete_namespaced_job(
namespace=self.runtime_context.namespace,
name=self.namespaced_job_name,
timeout=wall_time,
)
return

Expand Down
7 changes: 3 additions & 4 deletions pycalrissian/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,17 @@ def copy_to_volume(
try:
for source_path in source_paths:
print(f"copy {source_path} to {destination_path}")
'''
"""
helper_pod.copy_to_volume(
src_path=source_path,
dest_path=os.path.join(
destination_path,
os.path.basename(source_path),
),
)
'''
"""
helper_pod.copy_to_volume_using_kubectl(
src_path=source_path,
dest_path=destination_path
src_path=source_path, dest_path=destination_path
)
finally:
helper_pod.dismiss()
Expand Down
86 changes: 86 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[build-system]
requires = ["hatchling","setuptools", "wheel", "build"]
build-backend = "hatchling.build"

[project]
name = "pycalrissian"
dynamic = ["version"]
description = "pycalrissian"
readme = "README.md"
requires-python = ">=3.8"
keywords = ["pycalrissian", "kubernetes"]
license = "EUPL-1.0"
authors = [
{ name = "Terradue", email = "[email protected]" },
]

classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"loguru",
"typing-extensions==4.8.0",
"kubernetes==28.1.0",
"cwltool==3.1.20240708091337",
"setuptools==70.0.0"
]

[project.urls]
Homepage = "https://github.com/Terradue/pycalrissian"

[tool.hatch.version]
path = "pycalrissian/__about__.py"

[tool.hatch.build.targets.sdist]
include = [
"pycalrissian/*",
"docs/*",
"test/*"
]

[tool.hatch.envs.types]
extra-dependencies = [
"loguru",
"typing",
"kubernetes==28.1.0",
]

[tool.coverage.run]
source_pkgs = ["pycalrissian", "tests"]
branch = true
parallel = true
omit = [
"pycalrissian/__about__.py",
]

[tool.coverage.paths]
pycalrissian = ["pycalrissian"]
tests = ["tests"]

[tool.hatch.envs.default]
skip-install = false
dependencies = [
"nose2",
"coverage",
"loguru",
"typing-extensions==4.8.0",
"kubernetes==28.1.0",
"cwltool==3.1.20240708091337",
"setuptools==70.0.0"
]

## [project.scripts]
## pycalrissian = "pycalrissian/__init__"

[tool.hatch.envs.test.scripts]
test = "hatch run nose2"
testv = "hatch run nose2 --verbose"
cov = ["coverage run --source=pycalrissian -m nose2", "coverage report"]
2 changes: 1 addition & 1 deletion tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pycalrissian.context import CalrissianContext

os.environ["KUBECONFIG"] = "/home/mambauser/.kube/kubeconfig-t2-dev.yaml"
os.environ["KUBECONFIG"] = "~/.kube/kubeconfig-t2-dev.yaml"


class TestCalrissianContext(unittest.TestCase):
Expand Down
15 changes: 10 additions & 5 deletions tests/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pycalrissian.execution import CalrissianExecution
from pycalrissian.job import CalrissianJob

os.environ["KUBECONFIG"] = "/home/mambauser/.kube/kubeconfig-t2-dev.yaml"
os.environ["KUBECONFIG"] = "~/.kube/kubeconfig-t2-dev.yaml"


class TestCalrissianExecution(unittest.TestCase):
Expand Down Expand Up @@ -49,6 +49,7 @@ def setUpClass(cls):
def tearDown(cls):
cls.session.dispose()

@unittest.skipIf(os.getenv("CI_TEST_SKIP") == "1", "Test is skipped via env variable")
def test_simple_job(self):

with open("tests/simple.cwl", "r") as stream:
Expand All @@ -75,7 +76,7 @@ def test_simple_job(self):

execution.submit()

execution.monitor(interval=5)
execution.monitor(interval=5, wall_time=360)

print(f"complete {execution.is_complete()}")
print(f"succeeded {execution.is_succeeded()}")
Expand All @@ -84,6 +85,7 @@ def test_simple_job(self):

self.assertTrue(execution.is_succeeded())

@unittest.skipIf(os.getenv("CI_TEST_SKIP") == "1", "Test is skipped via env variable")
def test_wrong_docker_pull_job(self):
"""tests the imagepullbackoff state of a pod, the job is killed"""
with open("tests/wrong_docker_pull.cwl", "r") as stream:
Expand All @@ -110,11 +112,12 @@ def test_wrong_docker_pull_job(self):

execution.submit()

execution.monitor(interval=5, grace_period=60)
execution.monitor(interval=5, grace_period=60, wall_time=120)

print(f"killed {execution.killed}")
self.assertFalse(execution.is_succeeded())

@unittest.skipIf(os.getenv("CI_TEST_SKIP") == "1", "Test is skipped via env variable")
def test_high_reqs_job(self):
"""tests the high reqs for RAM and cores, the job is killed"""
with open("tests/high_reqs.cwl", "r") as stream:
Expand All @@ -141,11 +144,12 @@ def test_high_reqs_job(self):

execution.submit()

execution.monitor(interval=5, grace_period=60)
execution.monitor(interval=5, grace_period=60, wall_time=120)

print(f"killed {execution.killed}")
self.assertFalse(execution.is_succeeded())

@unittest.skipIf(os.getenv("CI_TEST_SKIP") == "1", "Test is skipped via env variable")
def test_wall_time_reached_job(self):
"""tests wall time reached, the job is killed"""
with open("tests/sleep.cwl", "r") as stream:
Expand Down Expand Up @@ -174,6 +178,7 @@ def test_wall_time_reached_job(self):
print(f"killed {execution.killed}")
self.assertFalse(execution.is_succeeded())

@unittest.skipIf(os.getenv("CI_TEST_SKIP") == "1", "Test is skipped via env variable")
def test_wall_time_not_reached_job(self):
"""tests wall time reached, the job is killed"""
with open("tests/sleep.cwl", "r") as stream:
Expand All @@ -197,6 +202,6 @@ def test_wall_time_not_reached_job(self):

execution.submit()

execution.monitor(interval=15, grace_period=30, wall_time=180)
execution.monitor(interval=15, grace_period=30, wall_time=120)

self.assertTrue(execution.is_succeeded())
Loading
Loading