Compare commits

...

2 commits

Author SHA1 Message Date
Benjamin Renard
bc276b9845 Add build package and Woodpecker CI stuff 2022-04-27 17:12:00 +02:00
Benjamin Renard
252f9a87ac tests: fix oracle test_truncate 2022-04-27 17:11:02 +02:00
5 changed files with 159 additions and 42 deletions

4
.gitignore vendored
View file

@ -2,3 +2,7 @@
*~ *~
mylib.egg-info mylib.egg-info
venv* venv*
build
dist
deb_dist
mylib-*.tar.gz

33
.woodpecker.yml Normal file
View file

@ -0,0 +1,33 @@
pipelines:
test:
image: debian
commands:
- apt update
- apt -y upgrade
- apt install -y python3-all python3-dev python3-pip python3-venv build-essential pkg-config libsystemd-dev libldap2-dev libsasl2-dev libpq-dev libmariadb-dev wget unzip
- wget -O /opt/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip
- unzip -d /opt /opt/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip
- echo /opt/instantclient_* > /etc/ld.so.conf.d/oracle-instantclient.conf
- ldconfig
- python3 -m venv venv
- source venv/bin/activate
- python3 -m pip install -e ".[dev]"
- python3 -m pytest tests
build:
image: debian
commands:
- apt update
- apt -y upgrade
- apt -y install --no-install-recommends git sed python3-all python3-dev python3-pip python3-venv dpkg-dev build-essential debhelper dh-python bash-completion lsb-release
- ./build.sh
- rm -fr deb_dist/python3-mylib-*
publish:
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_token
base_url: https://gitea.zionetrix.net
files: dist/* deb_dist/*
checksum:
- md5
- sha512

80
build.sh Executable file
View file

@ -0,0 +1,80 @@
#!/bin/bash
# Enter source directory
cd $( dirname $0 )
# Clean previous build
rm -fr dist deb_dist
# Set version in pyproject.toml
VERSION="$( git describe --tags )"
sed -i "s/^version *=.*$/version = '$VERSION'/" setup.py
if [ -d venv ]
then
VENV=$( realpath venv )
TEMP_VENV=0
else
# Install stdeb in temporary venv
VENV=$(mktemp -d)
echo "Create a temporary virtualenv in $VENV to install build dependencies..."
TEMP_VENV=1
python3 -m venv $VENV
$VENV/bin/python3 -m pip install stdeb GitPython wheel
fi
# Build wheel package
$VENV/bin/python3 setup.py bdist_wheel
# Check gitdch is installed
GITDCH=$(which gitdch)
set -e
if [ -z "$GITDCH" ]
then
TMP_GITDCH=$(mktemp -d)
echo "Temporary install gitdch in $TMP_GITDCH"
git clone https://gitea.zionetrix.net/bn8/gitdch.git $TMP_GITDCH/gitdch
GITDCH=$TMP_GITDCH/gitdch/gitdch
else
TMP_GITDCH=""
fi
# Build debian source package
$VENV/bin/python3 setup.py --command-packages=stdeb.command sdist_dsc \
--package3 "python3-mylib" \
--maintainer "Benjamin Renard <brenard@zionetrix.net>" \
--compat 10 \
--section net \
--forced-upstream-version "$VERSION"
# Keep only debian package directory and orig.tar.gz archive
find deb_dist/ -maxdepth 1 -type f ! -name '*.orig.tar.gz' -delete
# Enter in debian package directory
cd deb_dist/mylib-$VERSION
# Generate EE debian codename
DEBIAN_CODENAME=$( lsb_release -c -s )
[ $( lsb_release -r -s ) -ge 9 ] && DEBIAN_CODENAME="${DEBIAN_CODENAME}-ee"
# Generate debian changelog using generate_debian_changelog.py
$VENV/bin/python3 $GITDCH \
--package-name mylib \
--version "${VERSION}" \
--code-name $DEBIAN_CODENAME \
--output debian/changelog \
--path ../../ \
--verbose
# Add custom package name for dependencies
cat << EOF > debian/py3dist-overrides
cx_oracle python3-cx-oracle
EOF
[ $TEMP_VENV -eq 1 ] && rm -fr $VENV
# Clean temporary gitdch installation
[ -n "$TMP_GITDCH" ] && rm -fr $TMP_GITDCH
# Build debian package
dpkg-buildpackage --no-sign

View file

@ -1,57 +1,57 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
from setuptools import find_packages from setuptools import find_packages
from setuptools import setup from setuptools import setup
here = os.path.abspath(os.path.dirname(__file__)) extras_require={
with open(os.path.join(here, 'README.md')) as f: 'dev': [
README = f.read() 'pytest',
'mocker',
'pytest-mock',
'pylint',
],
'config': [
'argcomplete',
'keyring',
'systemd-python',
],
'ldap': [
'python-ldap',
'python-dateutil',
'pytz',
],
'email': [
'mako',
],
'pgsql': [
'psycopg2',
],
'oracle': [
'cx_Oracle',
],
'mysql': [
'mysqlclient',
],
}
install_requires = ['progressbar']
for extra, deps in extras_require.items():
if extra != 'dev':
install_requires.extend(deps)
version = '0.1'
setup( setup(
name="mylib", name="mylib",
version='0.0', version=version,
long_description=README, description='A set of helpers small libs to make common tasks easier in my script development',
classifiers=[ classifiers=[
'Programming Language :: Python', 'Programming Language :: Python',
], ],
install_requires=[ install_requires=install_requires,
'progressbar', extras_require=extras_require,
],
extras_require={
'dev': [
'pytest',
'mocker',
'pytest-mock',
'pylint',
],
'config': [
'configparser',
'argcomplete',
'keyring',
'systemd-python',
],
'ldap': [
'python-ldap',
'python-dateutil',
'pytz',
],
'email': [
'email3',
'mako',
],
'pgsql': [
'psycopg2',
],
'oracle': [
'cx_Oracle',
],
'mysql': [
'mysqlclient',
],
},
author='Benjamin Renard', author='Benjamin Renard',
author_email='brenard@zionetrix.net', author_email='brenard@zionetrix.net',
url='https://gogs.zionetrix.net/bn8/python-mylib', url='https://gogs.zionetrix.net/bn8/python-mylib',

View file

@ -307,7 +307,7 @@ def test_delete_just_try(mocker, test_oracledb):
def test_truncate(mocker, test_oracledb): def test_truncate(mocker, test_oracledb):
mocker.patch( mocker.patch(
'mylib.oracle.OracleDB.doSQL', 'mylib.oracle.OracleDB.doSQL',
generate_mock_doSQL('TRUNCATE "mytable"', None) generate_mock_doSQL('TRUNCATE TABLE "mytable"', None)
) )
assert test_oracledb.truncate('mytable') assert test_oracledb.truncate('mytable')