Allow jjb to be called as a module
Enable us to do `python -m jenkins_jobs ...` which avoids the need to install executable in user path. Tests cli execution on each supported python version. Uses default encoding workaround only on python2, where is needed. Change-Id: I4cd79fd51a8309d532e0e76723ecfbbda3e1ca6f Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
This commit is contained in:
parent
51a4ccab70
commit
92f28a591e
4
jenkins_jobs/__main__.py
Normal file
4
jenkins_jobs/__main__.py
Normal file
@ -0,0 +1,4 @@
|
||||
from jenkins_jobs.cli.entry import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -17,7 +17,6 @@ import io
|
||||
import os
|
||||
import logging
|
||||
import platform
|
||||
import sys
|
||||
|
||||
from stevedore import extension
|
||||
import yaml
|
||||
@ -27,9 +26,6 @@ from jenkins_jobs.config import JJBConfig
|
||||
from jenkins_jobs import utils
|
||||
from jenkins_jobs import version
|
||||
|
||||
if sys.version_info[0] != 2:
|
||||
from importlib import reload
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger()
|
||||
|
||||
@ -147,14 +143,15 @@ def main():
|
||||
|
||||
# utf-8 workaround for avoiding unicode errors in stdout/stderr
|
||||
# see https://stackoverflow.com/a/2001767/99834
|
||||
import codecs
|
||||
import sys
|
||||
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
|
||||
sys.stderr = codecs.getwriter('utf8')(sys.stderr)
|
||||
# end of workaround
|
||||
if sys.version_info[0] == 2:
|
||||
import codecs
|
||||
reload(sys) # noqa
|
||||
sys.setdefaultencoding('utf-8')
|
||||
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
|
||||
sys.stderr = codecs.getwriter('utf8')(sys.stderr)
|
||||
# end of workaround
|
||||
|
||||
argv = sys.argv[1:]
|
||||
jjb = JenkinsJobs(argv)
|
||||
|
8
tools/test-commands.sh
Executable file
8
tools/test-commands.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -exou pipefail
|
||||
|
||||
VAL1=$(jenkins-jobs --version 2>&1) || exit 1
|
||||
VAL2=$(python -m jenkins_jobs --version 2>&1) || exit 2
|
||||
|
||||
# we assure that both calling methods to get the same output
|
||||
[ "${VAL1}" == "${VAL2}" ] || exit 3
|
2
tox.ini
2
tox.ini
@ -18,6 +18,8 @@ deps = -r{toxinidir}/test-requirements.txt
|
||||
commands =
|
||||
- find . -type f -name "*.pyc" -delete
|
||||
- find . -type d -name "__pycache__" -delete
|
||||
# test that we can call jjb using both variants with same results
|
||||
bash {toxinidir}/tools/test-commands.sh
|
||||
stestr run --slowest {posargs}
|
||||
whitelist_externals =
|
||||
bash
|
||||
|
Loading…
Reference in New Issue
Block a user