Skip to content
This repository was archived by the owner on Apr 30, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:

install:
- sed -i "s/fedora-28-x86_64/fedora-${FEDORA}-x86_64/" mock.cfg
- sed -i "s/\$releasever/${FEDORA}/" mock.cfg # needed on rawhide
- sed -i "s|FROM fedora|FROM registry.fedoraproject.org/fedora:${FEDORA}|" Dockerfile
- docker build -t taskotron .

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM fedora

RUN dnf -y install --setopt=install_weak_deps=false --setopt=tsflags=nodocs \
--setopt=deltarpm=false python2-rpm python3-rpm tox python2-dnf \
python3-dnf mock --allowerasing --best && dnf clean all
--setopt=deltarpm=false --allowerasing --best \
mock tox python3-rpm python3-dnf && dnf clean all

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Tests

This task is covered with functional and integration tests.
You can run them using `tox <https://tox.readthedocs.io/>`__, but
you will need ``mock``, ``python{2,3}-rpm`` and ``python{2,3}-dnf`` installed.
you will need ``mock``, ``python3-rpm`` and ``python3-dnf`` installed.
For mock configuration see
`mock setup <https://github.com/rpm-software-management/mock/wiki#setup>`__
instructions. Use the following command to run the test suite::
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='taskotron-python-versions',
version='0.1.dev3',
version='0.1.dev4',
description=description,
long_description=long_description,
keywords='taskotron fedora python rpm',
Expand All @@ -29,7 +29,6 @@
'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Testing',
]
Expand Down
14 changes: 5 additions & 9 deletions taskotron_python_versions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ def file_contains(path, needle):
# let's optimize prematurely because practicality beats purity

# Memory-mapped file object behaving like bytearray
mmf = mmap.mmap(f.fileno(),
length=0, # = determine automatically
access=mmap.ACCESS_READ)
try:
with mmap.mmap(f.fileno(),
length=0, # = determine automatically
access=mmap.ACCESS_READ) as mmf:
return mmf.find(needle) != -1
finally:
# mmap context manager is Python 3 only
mmf.close()


class PackageException(Exception):
Expand Down Expand Up @@ -112,11 +108,11 @@ def nvr(self):

@property
def require_names(self):
return self.hdr[rpm.RPMTAG_REQUIRENAME]
return [r.decode() for r in self.hdr[rpm.RPMTAG_REQUIRENAME]]

@property
def require_nevrs(self):
return self.hdr[rpm.RPMTAG_REQUIRENEVRS]
return [r.decode() for r in self.hdr[rpm.RPMTAG_REQUIRENEVRS]]

@property
def files(self):
Expand Down
2 changes: 0 additions & 2 deletions taskotron_python_versions/python_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def task_python_usage(packages, koji_build, artifact):
log.debug('Checking {}'.format(package.filename))

for name in package.require_names:
name = name.decode()

if name in PYTHON_COMMAND:
log.error(
'{} requires {}'.format(package.filename, name))
Expand Down
2 changes: 0 additions & 2 deletions taskotron_python_versions/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def check_requires_naming_scheme(package, repoquery):
misnamed_requires = set()

for name in package.require_names:
name = name.decode()

if is_unversioned(name):
versioned = get_versioned_name(name, repoquery)

Expand Down
68 changes: 34 additions & 34 deletions taskotron_python_versions/two_three.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@


NEVRS_STARTS = {
2: (b'python(abi) = 2.',),
3: (b'python(abi) = 3.',)
2: ('python(abi) = 2.',),
3: ('python(abi) = 3.',)
}

NAME_STARTS = {
2: (
b'python-',
b'python2',
b'/usr/bin/python2',
b'libpython2',
b'pygtk2',
b'pygobject2',
b'pycairo',
b'py-',
'python-',
'python2',
'/usr/bin/python2',
'libpython2',
'pygtk2',
'pygobject2',
'pycairo',
'py-',
),
3: (
b'python3',
b'/usr/bin/python3',
b'libpython3',
b'system-python'
'python3',
'/usr/bin/python3',
'libpython3',
'system-python'
)
}

NAME_EXACTS = {
2: (
b'/usr/bin/python',
b'python',
'/usr/bin/python',
'python',
)
}

NAME_NOTS = (
b'python-rpm-macros',
b'python-srpm-macros',
b'python-sphinx-locale',
b'python-multilib-conf',
b'python-ldb-devel-common',
b'python-qt5-rpm-macros',
b'python-btchip-common',
b'python-matplotlib-data',
b'python-matplotlib-data-fonts',
b'python-cartopy-common',
b'python-django-bash-completion',
b'python-jupyter-filesystem',
b'python-pip-wheel',
b'python-setuptools-wheel',
b'python-wheel-wheel',
'python-rpm-macros',
'python-srpm-macros',
'python-sphinx-locale',
'python-multilib-conf',
'python-ldb-devel-common',
'python-qt5-rpm-macros',
'python-btchip-common',
'python-matplotlib-data',
'python-matplotlib-data-fonts',
'python-cartopy-common',
'python-django-bash-completion',
'python-jupyter-filesystem',
'python-pip-wheel',
'python-setuptools-wheel',
'python-wheel-wheel',
)


Expand Down Expand Up @@ -80,22 +80,22 @@ def check_two_three(package):
for nevr in package.require_nevrs:
for py_version, starts in NEVRS_STARTS.items():
if nevr.startswith(starts):
log.debug('Found dependency {}'.format(nevr.decode()))
log.debug('Found dependency {}'.format(nevr))
log.debug('Requires Python {}'.format(py_version))
py_versions[py_version] = nevr

for name in package.require_names:
for py_version, starts in NAME_STARTS.items():
if py_version not in py_versions:
if name.startswith(starts) and name not in NAME_NOTS:
log.debug('Found dependency {}'.format(name.decode()))
log.debug('Found dependency {}'.format(name))
log.debug('Requires Python {}'.format(py_version))
py_versions[py_version] = name

for py_version, exacts in NAME_EXACTS.items():
if py_version not in py_versions:
if name in exacts:
log.debug('Found dependency {}'.format(name.decode()))
log.debug('Found dependency {}'.format(name))
log.debug('Requires Python {}'.format(py_version))
py_versions[py_version] = name

Expand Down
18 changes: 6 additions & 12 deletions taskotron_python_versions/unversioned_shebangs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_problematic_files(archive, query):
"""Search for the files inside archive with the first line
matching given query. Some of the files can contain data, which
are not in the plain text format. Bytes are read from the file and
the shebang query has to be of the same type.
the shebang query is encoded as well. We only test for ASCII shebangs.
"""
problematic = set()
with libarchive.file_reader(archive) as a:
Expand All @@ -51,21 +51,15 @@ def get_problematic_files(archive, query):
first_line = next(entry.get_blocks(), '').splitlines()[0]
except IndexError:
continue # file is empty
if matches(first_line, query.encode()):
if matches(first_line, query.encode('ascii')):
problematic.add(entry.pathname.lstrip('.'))

return problematic


def shebang_to_require(shebang, use_bytes=True):
"""Convert shebang to the format of requirement.
If the use_bytes argument is set to False, executable path
is returned as a string instead of the default bytes type."""
executable_path = shebang.split()[0][2:]
if use_bytes:
return executable_path.encode()
else:
return executable_path
def shebang_to_require(shebang):
"""Convert shebang to the format of requirement."""
return shebang.split()[0][2:]


def get_scripts_summary(package):
Expand All @@ -79,7 +73,7 @@ def get_scripts_summary(package):
if shebang_to_require(shebang) in package.require_names:
log.debug('Package {} requires {}'.format(
package.filename, shebang_to_require(
shebang, use_bytes=False)))
shebang)))
problematic = get_problematic_files(package.path, shebang)
if problematic:
log.debug('{} shebang was found in scripts: {}'.format(
Expand Down
14 changes: 6 additions & 8 deletions test/functional/test_unversioned_shebangs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ def test_get_problematic_files(archive, query, expected):
assert get_problematic_files(gpkg_path(archive), query) == expected


@pytest.mark.parametrize(('shebang', 'use_bytes', 'expected'), (
("#!/foo", True, b"/foo"),
("#!/usr/bin/python", True, b"/usr/bin/python"),
("#!/usr/bin/env python", True, b"/usr/bin/env"),
("#!/usr/bin/python", False, "/usr/bin/python"),
("#!/usr/bin/env python", False, "/usr/bin/env"),
@pytest.mark.parametrize(('shebang', 'expected'), (
("#!/foo", "/foo"),
("#!/usr/bin/python", "/usr/bin/python"),
("#!/usr/bin/env python", "/usr/bin/env"),
))
def test_shebang_to_require(shebang, use_bytes, expected):
assert shebang_to_require(shebang, use_bytes) == expected
def test_shebang_to_require(shebang, expected):
assert shebang_to_require(shebang) == expected


@pytest.mark.parametrize(('glob', 'expected'), (
Expand Down
16 changes: 8 additions & 8 deletions tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
name: "{{ item }}"
state: latest
with_items:
- rpm-python
- python2-dnf
- python2-libarchive-c
- python-bugzilla
- libtaskotron-core
- libtaskotron-fedora
- python3-rpm
- python3-dnf
- python3-libarchive-c
- python3-bugzilla
- python3-libtaskotron
- taskotron-runner
register: dnf_output
# retry for network failures
retries: 3
Expand Down Expand Up @@ -66,13 +66,13 @@
- block:
- name: Download RPMs from Koji
shell: >
python2 download_rpms.py {{ taskotron_item }} {{ workdir.path }}
python3 download_rpms.py {{ taskotron_item }} {{ workdir.path }}
{{ test_arches | join(',') }}
&> {{ artifacts }}/test.log

- name: Run task
shell: >
python2 python_versions_check.py {{ taskotron_item }} {{ workdir.path }}
python3 python_versions_check.py {{ taskotron_item }} {{ workdir.path }}
{{ artifacts }} {{ testcase }} {{ test_arches | join(',') }}
&>> {{ artifacts }}/test.log
always:
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py3,integration,style
envlist = py3,integration,style
skipsdist = True

[testenv]
Expand All @@ -23,5 +23,5 @@ sitepackages = False
[testenv:style]
deps = flake8
basepython = python3
commands = python -m flake8 . --ignore=E402 --exclude=.git,__pycache__,.tox,.eggs,dist,build,mockroots
commands = python -m flake8 . --ignore=E402,W504 --exclude=.git,__pycache__,.tox,.eggs,dist,build,mockroots
sitepackages = False