Debian Jessie/Python 3.4 support for the most part (#6)

* automatically find the chroot binary on Debian, even if it is not
  in the user's PATH
* don't use subprocess.run anymore (remove related testcase, that explicitly
  checked for subprocess.run usage, and used recursive globbing, another
  post 3.4 Python feature, for the checks. A similar case can be added in the
  future, but right now it's more important to get Debian 3.4 working and all
  PRs are reviewed anyway.)
* pytest fixtures: don't use the newer "yield" feature, as this is only
  supported in a newer version of pytest, than provided on Debian Jessie

From manually testing, most stuff works in Debian Jessie. However, the
testsuite does not run through - creating an empty .tar.gz with Python
fails for some reason (this is done in test_apk_static.py).
This commit is contained in:
Oliver Smith 2017-05-29 20:38:11 +02:00
parent 3eafc5eb8a
commit 3b5d5d8086
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
10 changed files with 30 additions and 58 deletions

View File

@ -32,7 +32,7 @@ def executables_absolute_path():
"""
ret = {}
for binary in ["sh", "chroot"]:
path = shutil.which(binary)
path = shutil.which(binary, path=pmb.config.chroot_host_path)
if not path:
raise RuntimeError("Could not find the '" + binary +
"' executable. Make sure, that it is in" " your current user's PATH.")

View File

@ -75,6 +75,11 @@ chroot_path = ":".join([
"/bin"
])
# The PATH variable used on the host, to find the "chroot" and "sh"
# executables. As pmbootstrap runs as user, not as root, the location
# for the chroot executable may not be in the PATH (Debian).
chroot_host_path = os.environ["PATH"] + ":/usr/sbin/"
# Folders, that get mounted inside the chroot
# $WORK gets replaced with args.work
# $ARCH gets replaced with the chroot architecture (eg. x86_64, armhf)

View File

@ -32,20 +32,22 @@ def core(args, cmd, log_message, log, return_stdout, check=True):
ret = None
if log:
if return_stdout:
ret = subprocess.run(cmd, stdout=subprocess.PIPE,
check=check).stdout.decode('utf-8')
ret = subprocess.check_output(cmd).decode("utf-8")
args.logfd.write(ret)
else:
subprocess.run(cmd, stdout=args.logfd, stderr=args.logfd,
check=check)
subprocess.check_call(cmd, stdout=args.logfd,
stderr=args.logfd)
args.logfd.flush()
else:
logging.debug("*** output passed to pmbootstrap stdout, not" +
" to this log ***")
subprocess.run(cmd, check=check)
subprocess.check_call(cmd)
except subprocess.CalledProcessError as exc:
raise RuntimeError("Command failed: " + log_message) from exc
if check:
raise RuntimeError("Command failed: " + log_message) from exc
else:
pass
return ret

View File

@ -30,13 +30,13 @@ import pmb.parse.apkindex
@pytest.fixture
def args():
def args(request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "chroot"]
args = pmb.parse.arguments()
setattr(args, "logfd", open("/dev/null", "a+"))
yield args
args.logfd.close()
request.addfinalizer(args.logfd.close)
return args
def test_read_signature_info(tmpdir):

View File

@ -28,15 +28,15 @@ import pmb.aportgen
@pytest.fixture
def args(tmpdir):
def args(tmpdir, request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "chroot"]
args = pmb.parse.arguments()
setattr(args, "logfd", open("/dev/null", "a+"))
setattr(args, "_aports_real", args.aports)
args.aports = str(tmpdir)
yield args
args.logfd.close()
request.addfinalizer(args.logfd.close)
return args
def test_aportgen(args):

View File

@ -27,13 +27,13 @@ import pmb.aportgen
@pytest.fixture
def args(tmpdir):
def args(tmpdir, request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "chroot"]
args = pmb.parse.arguments()
setattr(args, "logfd", open("/dev/null", "a+"))
yield args
args.logfd.close()
request.addfinalizer(args.logfd.close)
return args
def test_build(args):

View File

@ -30,13 +30,12 @@ import pmb.helpers.git
@pytest.fixture
def args():
def args(request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "chroot"]
args = pmb.parse.arguments()
setattr(args, "logfd", open("/dev/null", "a+"))
yield args
args.logfd.close()
request.addfinalizer(args.logfd.close)
return args

View File

@ -29,13 +29,13 @@ import pmb.chroot.user
@pytest.fixture
def args():
def args(request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "chroot"]
args = pmb.parse.arguments()
setattr(args, "logfd", open("/dev/null", "a+"))
yield args
args.logfd.close()
request.addfinalizer(args.logfd.close)
return args
def test_shell_escape(args):

View File

@ -1,33 +0,0 @@
"""
Copyright 2017 Oliver Smith
This file is part of pmbootstrap.
pmbootstrap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pmbootstrap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import glob
def test_use_pmb_helpers_run_instead_of_subprocess_run():
src = os.path.abspath(os.path.dirname(__file__) + "/..")
files = glob.glob(src + "/pmb/**/*.py",
recursive=True) + glob.glob(src + "*.py")
okay = os.path.abspath(src + "/pmb/helpers/run.py")
for file in files:
with open(file, "r") as handle:
source = handle.read()
if file != okay and "subprocess.run" in source:
raise RuntimeError("File " + file + " use pmb.helpers.run.user()"
" instead of subprocess.run()!")

View File

@ -28,13 +28,12 @@ import pmb.helpers.git
@pytest.fixture
def args():
def args(request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "chroot"]
args = pmb.parse.arguments()
setattr(args, "logfd", open("/dev/null", "a+"))
yield args
args.logfd.close()
request.addfinalizer(args.logfd.close)
return args