Skip to content

Commit

Permalink
Merge pull request #22 from cedadev/add_pypi_pkg_build_GA
Browse files Browse the repository at this point in the history
Add Github Actions workflow that builds a PyPI package (and deploys it on PyPI if Github release) + simple test with barebones conda environment file
  • Loading branch information
valeriupredoi authored Nov 21, 2023
2 parents 25d8710 + 4b7f865 commit 9660d22
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/build-and-deploy-on-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: PyPi Build and Deploy 🐍📦

on:
release:
types: [published]
# use this for testing
push:
branches:
- main

jobs:
build-n-publish:
name: Build and publish MyProxyClient on PyPi
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/MyProxyClient/
# use the new Trusted Publishers feature
# details at https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
# to add a PyPI project to Trusted Publishers, see
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install pep517
run: >-
python -m
pip install
pep517
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
pep517.build
--source
--binary
--out-dir dist/
.
# - name: Publish distribution 📦 to Test PyP
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# repository-url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
38 changes: 38 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test

on:
push:
branches:
- main
schedule:
- cron: '0 0 * * *' # nightly

# Required shell entrypoint to have properly configured bash shell
defaults:
run:
shell: bash -l {0}

jobs:
linux:
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
fail-fast: false
name: Linux Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: myproxy
environment-file: environment-test.yml
python-version: ${{ matrix.python-version }}
miniforge-version: "latest"
miniforge-variant: Mambaforge
use-mamba: true
- run: conda --version
- run: python -V
- run: pip install -e .
- run: pytest tests/unit/test_simple.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
MyProxyClient.egg-info/
build/
dist/
__pycache__/
9 changes: 9 additions & 0 deletions environment-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: myproxy
channels:
- conda-forge
- nodefaults

dependencies:
- pip
- pytest
2 changes: 1 addition & 1 deletion myproxy/client/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class CaseSensitiveConfigParser(ConfigParser):
'''Subclass the SafeConfigParser - to preserve the original string case of
'''Subclass ConfigParser - to preserve the original string case of
config section names
'''
def optionxform(self, optionstr):
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools >= 40.6.0", "wheel", "setuptools_scm>=6.2"]
build-backend = "setuptools.build_meta"
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
version = '2.1.1',
description = 'MyProxy Client',
long_description = LONG_DESCR,
long_description_content_type='text/markdown',
author = 'Philip Kershaw',
author_email = 'Philip.Kershaw@stfc.ac.uk',
maintainer = 'Philip Kershaw',
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from myproxy.client import MyProxyClient


def test_members():
"""Test public method members of MyProxyClient."""
expected_members = [
'caCertDir', 'changePassphrase', 'destroy', 'getDelegation',
'getTrustRoots', 'hostname', 'info', 'locateClientCredentials',
'logon', 'openSSLConfFilePath', 'openSSLConfig', 'parseConfig',
'port', 'proxyCertLifetime', 'proxyCertMaxLifetime', 'put',
'readProxyFile', 'serverDN', 'setDefaultCACertDir',
'ssl_verification', 'store', 'writeProxyFile'
]
actual_members = dir(MyProxyClient)
for member in expected_members:
assert member in actual_members


def test_simple():
"""Test a simple instance of MyProxyClient."""
hostname = "example.com"
c = MyProxyClient(hostname=hostname, caCertDir="")
assert c.hostname == "example.com"
assert not c.caCertDir
assert c.proxyCertLifetime == 43200
assert not c.serverDN

0 comments on commit 9660d22

Please sign in to comment.