Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #109 Replace print statements with logger #113

Merged
merged 12 commits into from
Nov 13, 2018
16 changes: 10 additions & 6 deletions auditwheel/main_addtag.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from os.path import basename, exists, join, abspath
from .policy import (load_policies, get_policy_name, get_priority_by_name,
POLICY_PRIORITY_HIGHEST)
import logging


logger = logging.getLogger(__name__)


def configure_parser(sub_parsers):
Expand Down Expand Up @@ -30,12 +34,12 @@ def execute(args, p):
parsed_fname = WHEEL_INFO_RE(basename(args.WHEEL_FILE))
in_fname_tags = parsed_fname.groupdict()['plat'].split('.')

print('%s recieves the following tag: "%s".' % (basename(args.WHEEL_FILE),
wheel_abi.overall_tag))
print('Use ``auditwheel show`` for more details')
logger.info('%s recieves the following tag: "%s".',
basename(args.WHEEL_FILE), wheel_abi.overall_tag)
logger.info('Use ``auditwheel show`` for more details')

if wheel_abi.overall_tag in in_fname_tags:
print('No tags to be added. Exiting.')
logger.info('No tags to be added. Exiting.')
return 1

# todo: move more of this logic to separate file
Expand All @@ -46,12 +50,12 @@ def execute(args, p):
try:
out_wheel = add_platforms(ctx, [wheel_abi.overall_tag])
except WheelToolsError as e:
print('\n%s.' % str(e), file=sys.stderr)
logger.exception('\n%s.', repr(e))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

return 1

if out_wheel:
# tell context manager to write wheel on exit with
# the proper output directory
ctx.out_wheel = join(args.WHEEL_DIR, basename(out_wheel))
print('\nUpdated wheel written to %s' % out_wheel)
logger.info('\nUpdated wheel written to %s', out_wheel)
return 0
6 changes: 5 additions & 1 deletion auditwheel/main_lddtree.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import logging

logger = logging.getLogger(__name__)

def configure_subparser(sub_parsers):
help = 'Analyze a single ELF file (similar to ``ldd``).'
p = sub_parsers.add_parser('lddtree', help=help, description=help)
Expand All @@ -9,4 +13,4 @@ def execute(args, p):
import json
from .lddtree import lddtree

print(json.dumps(lddtree(args.file), indent=4))
logger.info(json.dumps(lddtree(args.file), indent=4))
6 changes: 4 additions & 2 deletions auditwheel/main_repair.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from os.path import isfile, exists, abspath, basename
from .policy import (load_policies, get_policy_name, get_priority_by_name,
POLICY_PRIORITY_HIGHEST)
import logging

logger = logging.getLogger(__name__)

def configure_parser(sub_parsers):
policy_names = [p['name'] for p in load_policies()]
Expand Down Expand Up @@ -48,7 +50,7 @@ def execute(args, p):
if find_executable('patchelf') is None:
p.error('cannot find the \'patchelf\' tool, which is required')

print('Repairing %s' % basename(args.WHEEL_FILE))
logger.info('Repairing %s', basename(args.WHEEL_FILE))

if not exists(args.WHEEL_DIR):
os.makedirs(args.WHEEL_DIR)
Expand Down Expand Up @@ -77,4 +79,4 @@ def execute(args, p):
update_tags=args.UPDATE_TAGS)

if out_wheel is not None:
print('\nFixed-up wheel written to %s' % out_wheel)
logger.info('\nFixed-up wheel written to %s', out_wheel)
13 changes: 4 additions & 9 deletions auditwheel/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import platform as _platform_module
from typing import Optional
from os.path import join, dirname, abspath
import logging

logger = logging.getLogger(__name__)

_sys_map = {'linux2': 'linux',
'linux': 'linux',
Expand All @@ -25,17 +28,9 @@
# Windows probably, but there's not much reason to inspect foreign package
# that won't run on the platform.
if platform != 'linux':
print('Error: This tool only supports Linux', file=sys.stderr)
logger.critical('Error: This tool only supports Linux')
sys.exit(1)

# if linkage != 'ELF':
# print(
# ('Error: This tool only supports platforms that use the ELF '
# 'executable and linker format.'),
# file=sys.stderr)
# sys.exit(1)


def get_arch_name():
if _platform_module.machine() in non_x86_linux_machines:
return _platform_module.machine()
Expand Down
8 changes: 6 additions & 2 deletions auditwheel/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from subprocess import check_call, check_output, CalledProcessError
from distutils.spawn import find_executable
from typing import Optional
import logging

from .policy import get_replace_platforms
from .wheeltools import InWheelCtx, add_platforms
Expand All @@ -16,6 +17,9 @@
from .hashfile import hashfile


logger = logging.getLogger(__name__)


@functools.lru_cache()
def verify_patchelf():
"""This function looks for the ``patchelf`` external binary in the PATH,
Expand Down Expand Up @@ -129,7 +133,7 @@ def copylib(src_path, dest_dir):
if os.path.exists(dest_path):
return new_soname, dest_path

print('Grafting: %s -> %s' % (src_path, dest_path))
logger.info('Grafting: %s -> %s', src_path, dest_path)
rpaths = elf_read_rpaths(src_path)
shutil.copy2(src_path, dest_path)

Expand All @@ -147,5 +151,5 @@ def copylib(src_path, dest_dir):

def patchelf_set_rpath(fn, libdir):
rpath = pjoin('$ORIGIN', relpath(libdir, dirname(fn)))
print('Setting RPATH: %s to "%s"' % (fn, rpath))
logger.info('Setting RPATH: %s to "%s"', fn, rpath)
check_call(['patchelf', '--force-rpath', '--set-rpath', rpath, fn])
1 change: 0 additions & 1 deletion auditwheel/tmpdirs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
''' Contexts for *with* statement providing temporary directories
'''
from __future__ import division, print_function, absolute_import
import os
import shutil
from tempfile import template, mkdtemp
Expand Down
19 changes: 11 additions & 8 deletions auditwheel/wheeltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import hashlib
import csv
from itertools import product
import logging

from wheel.util import urlsafe_b64encode, open_for_csv, native # type: ignore
from wheel.pkginfo import read_pkg_info, write_pkg_info # type: ignore
Expand All @@ -19,6 +20,9 @@
from .tools import unique_by_index, zip2dir, dir2zip


logger = logging.getLogger(__name__)


class WheelToolsError(Exception):
pass

Expand Down Expand Up @@ -189,7 +193,6 @@ def add_platforms(wheel_ctx, platforms, remove_platforms=()):

info_fname = pjoin(_dist_info_dir(wheel_ctx.path), 'WHEEL')
info = read_pkg_info(info_fname)

# Check what tags we have
if wheel_ctx.out_wheel is not None:
out_dir = dirname(wheel_ctx.out_wheel)
Expand All @@ -201,7 +204,7 @@ def add_platforms(wheel_ctx, platforms, remove_platforms=()):
parsed_fname = WHEEL_INFO_RE(wheel_fname)
fparts = parsed_fname.groupdict()
original_fname_tags = fparts['plat'].split('.')
print('Previous filename tags:', ', '.join(original_fname_tags))
logger.info('Previous filename tags:', ', '.join(original_fname_tags))
fname_tags = {tag for tag in original_fname_tags
if tag not in remove_platforms}
fname_tags |= set(platforms)
Expand All @@ -213,9 +216,9 @@ def add_platforms(wheel_ctx, platforms, remove_platforms=()):
definitely_not_purelib = True

if fname_tags != original_fname_tags:
print('New filename tags:', ', '.join(fname_tags))
logger.info('New filename tags:', ', '.join(fname_tags))
else:
print('No filename tags change needed.')
logger.info('No filename tags change needed.')

wheel_base, ext = splitext(wheel_fname)
fparts['plat'] = '.'.join(fname_tags)
Expand All @@ -224,7 +227,7 @@ def add_platforms(wheel_ctx, platforms, remove_platforms=()):
out_wheel = pjoin(out_dir, out_wheel_fname)

in_info_tags = [tag for name, tag in info.items() if name == 'Tag']
print('Previous WHEEL info tags:', ', '.join(in_info_tags))
logger.info('Previous WHEEL info tags:', ', '.join(in_info_tags))
# Python version, C-API version combinations
pyc_apis = ['-'.join(tag.split('-')[:2]) for tag in in_info_tags]
# unique Python version, C-API version combinations
Expand All @@ -243,10 +246,10 @@ def add_platforms(wheel_ctx, platforms, remove_platforms=()):

if definitely_not_purelib:
info['Root-Is-Purelib'] = 'False'
print('Changed wheel type to Platlib')
logger.info('Changed wheel type to Platlib')

print('New WHEEL info tags:', ', '.join(info.get_all('Tag')))
logger.info('New WHEEL info tags:', ', '.join(info.get_all('Tag')))
write_pkg_info(info_fname, info)
else:
print('No WHEEL info change needed.')
logger.info('No WHEEL info change needed.')
return out_wheel
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ packages = auditwheel
[entry_points]
console_scripts =
auditwheel = auditwheel.main:main

[tool:pytest]
log_cli = true
log_cli_level = 20
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest
pytest>=3.4
jsonschema
numpy
pypatchelf
21 changes: 10 additions & 11 deletions tests/test_manylinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import shutil
import warnings
from distutils.spawn import find_executable
import logging


logger = logging.getLogger(__name__)


VERBOSE = True
ENCODING = 'utf-8'
MANYLINUX_IMAGE_ID = 'quay.io/pypa/manylinux1_x86_64'
DOCKER_CONTAINER_NAME = 'auditwheel-test-manylinux'
Expand All @@ -33,19 +37,16 @@ def docker_start(image, volumes={}, env_variables={}):
"""
# Make sure to use the latest public version of the docker image
cmd = ['docker', 'pull', image]
if VERBOSE:
print("$ " + " ".join(cmd))
logger.info("$ " + " ".join(cmd))
output = check_output(cmd).decode(ENCODING).strip()
if VERBOSE:
print(output)
logger.info(output)
cmd = ['docker', 'run', '-d']
for guest_path, host_path in sorted(volumes.items()):
cmd.extend(['-v', '%s:%s' % (host_path, guest_path)])
for name, value in sorted(env_variables.items()):
cmd.extend(['-e', '%s=%s' % (name, value)])
cmd.extend([image, 'sleep', '10000'])
if VERBOSE:
print("$ " + " ".join(cmd))
logger.info("$ " + " ".join(cmd))
return check_output(cmd).decode(ENCODING).strip()


Expand All @@ -54,11 +55,9 @@ def docker_exec(container_id, cmd):
if isinstance(cmd, str):
cmd = cmd.split()
cmd = ['docker', 'exec', container_id] + cmd
if VERBOSE:
print("$ " + " ".join(cmd))
logger.info("$ " + " ".join(cmd))
output = check_output(cmd).decode(ENCODING)
if VERBOSE:
print(output)
logger.info(output)
return output


Expand Down