Skip to content

Commit

Permalink
Add basic sanity checks and CI
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Borean <jborean93@gmail.com>
  • Loading branch information
jborean93 committed Oct 11, 2021
1 parent 9233801 commit b5cb6e5
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 295 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Test k5test
on:
push:
branches:
- main
paths-ignore:
- CODE_OF_CONDUCT.md
- K5TEST-LICENSE.txt
- LICENSE.txt
- README.md

pull_request:
branches:
- main
paths-ignore:
- CODE_OF_CONDUCT.md
- K5TEST-LICENSE.txt
- LICENSE.txt
- README.md

release:
types:
- published

schedule:
- cron: 0 9 * * *

jobs:
test:
name: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2

- name: Test
run: |
echo "::group::Installing Python Requirements"
python -m pip install --upgrade pip setuptools wheel
python -m pip install --requirement requirements-dev.txt
python -m pip install .
echo "::endgroup::"
echo "::group::Running Sanity Checks"
python -m black . --check
python -m isort . --check-only
echo "::endgroup::"
publish:
name: publish
needs:
- test

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2

- name: Build sdist and wheel
run: |
python -m pip install --upgrade pip setuptools wheel
python setup.py bdist_wheel --universal
python setup.py sdist
- name: Capture sdist and wheel
uses: actions/upload-artifact@v2
with:
name: k5test
path: dist/*

- name: Publish
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 21.9b0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.9.3
hooks:
- id: isort
36 changes: 18 additions & 18 deletions k5test/_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import sys
import subprocess
import sys


# general use
def get_output(*args, **kwargs):
res = subprocess.check_output(*args, shell=True, **kwargs)
decoded = res.decode('utf-8')
decoded = res.decode("utf-8")
return decoded.strip()


Expand All @@ -27,7 +27,7 @@ def import_gssapi_extension(name):
"""

try:
path = 'gssapi.raw.ext_{0}'.format(name)
path = "gssapi.raw.ext_{0}".format(name)
__import__(path)
return sys.modules[path]
except ImportError:
Expand All @@ -44,33 +44,31 @@ def find_plugin_dir():
return _PLUGIN_DIR

# if we've set a LD_LIBRARY_PATH, use that first
ld_path_raw = os.environ.get('LD_LIBRARY_PATH')
ld_path_raw = os.environ.get("LD_LIBRARY_PATH")
if ld_path_raw is not None:
# first, try assuming it's just a normal install

ld_paths = [path for path in ld_path_raw.split(':') if path]
ld_paths = [path for path in ld_path_raw.split(":") if path]

for ld_path in ld_paths:
if not os.path.exists(ld_path):
continue

_PLUGIN_DIR = _decide_plugin_dir(
_find_plugin_dirs_installed(ld_path))
_PLUGIN_DIR = _decide_plugin_dir(_find_plugin_dirs_installed(ld_path))
if _PLUGIN_DIR is None:
_PLUGIN_DIR = _decide_plugin_dir(
_find_plugin_dirs_src(ld_path))
_PLUGIN_DIR = _decide_plugin_dir(_find_plugin_dirs_src(ld_path))

if _PLUGIN_DIR is not None:
break

# if there was no LD_LIBRARY_PATH, or the above failed
if _PLUGIN_DIR is None:
lib_dir = os.path.join(get_output('krb5-config --prefix'), 'lib64')
lib_dir = os.path.join(get_output("krb5-config --prefix"), "lib64")
_PLUGIN_DIR = _decide_plugin_dir(_find_plugin_dirs_installed(lib_dir))

# /usr/lib64 seems only to be distinct on Fedora/RHEL/Centos family
if _PLUGIN_DIR is None:
lib_dir = os.path.join(get_output('krb5-config --prefix'), 'lib')
lib_dir = os.path.join(get_output("krb5-config --prefix"), "lib")
_PLUGIN_DIR = _decide_plugin_dir(_find_plugin_dirs_installed(lib_dir))

if _PLUGIN_DIR is not None:
Expand All @@ -97,23 +95,25 @@ def _decide_plugin_dir(dirs):

def _find_plugin_dirs_installed(search_path):
try:
options_raw = get_output('find %s/ -type d \( ! -executable -o ! -readable \) '
'-prune -o '
'-type d -path "*/krb5/plugins" -print' % search_path,
stderr=subprocess.STDOUT)
options_raw = get_output(
"find %s/ -type d \( ! -executable -o ! -readable \) "
"-prune -o "
'-type d -path "*/krb5/plugins" -print' % search_path,
stderr=subprocess.STDOUT,
)
except subprocess.CalledProcessError:
options_raw = None

if options_raw:
return options_raw.split('\n')
return options_raw.split("\n")
else:
return None


def _find_plugin_dirs_src(search_path):
options_raw = get_output('find %s/../ -type d -name plugins' % search_path)
options_raw = get_output("find %s/../ -type d -name plugins" % search_path)

if options_raw:
return options_raw.split('\n')
return options_raw.split("\n")
else:
return None
Loading

0 comments on commit b5cb6e5

Please sign in to comment.