-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add GPL check for PyPi packages for Linux (#40)
* test: add GPL check for PyPi packages for Linux * test: fix tests for data_runtime images (#38) * test: fix mount_root for data_runtime images * test: add skip mark if mount_root folder was not removed completely * test: mark test_detection_ssd_python for data_runtime images * fix: PEP8 and bandit issues Co-authored-by: Ilya Naumov <[email protected]>
- Loading branch information
1 parent
f7fbfe1
commit 63ff14a
Showing
6 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2019-2020 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import os | ||
import pathlib | ||
|
||
import pytest | ||
|
||
|
||
class TestPyPiDependencies: | ||
@pytest.mark.usefixtures('_is_image_os') | ||
@pytest.mark.parametrize('_is_image_os', ['ubuntu18', 'ubuntu20', 'centos7', 'centos8'], indirect=True) | ||
@pytest.mark.xfail(reason='47558 GPL Unidecode PyPi package as dependency for OMZ text_to_speech_demo') | ||
def test_gpl_pypi_deps(self, tester, image): | ||
root = pathlib.Path(os.path.realpath(__name__)).parent | ||
image_folder = image.replace('/', '_').replace(':', '_') | ||
pypi_log_folder = root / 'logs' / image_folder / 'pypi_deps' | ||
if not pypi_log_folder.exists(): | ||
pypi_log_folder.mkdir() | ||
kwargs = { | ||
'volumes': { | ||
root / 'tests' / 'resources' / 'pypi_deps': {'bind': '/tmp/pypi_deps', 'mode': 'rw'}, # nosec | ||
pypi_log_folder: {'bind': '/tmp/logs', 'mode': 'rw'}, # nosec | ||
}, | ||
} | ||
tester.test_docker_image( | ||
image, | ||
['/bin/bash -ac "python3 -m pip freeze 2>&1 | tee /tmp/logs/pypi_deps.log"', | ||
'/bin/bash -ac "python3 -m pip check 2>&1 | tee /tmp/logs/pypi_deps_check.log"', | ||
'python3 -m pip install pipdeptree', | ||
'/bin/bash -ac "python3 -m pipdeptree -e PyGObject 2>&1 | tee /tmp/logs/pypi_deps_tree.log"', | ||
'python3 -m pip install pip-licenses', | ||
'pip-licenses --output-file /tmp/logs/pypi_licenses.log', | ||
'pip-licenses -f json --output-file /tmp/logs/pypi_licenses.json', | ||
'python3 /tmp/pypi_deps/get_gpl_packages.py -f /tmp/logs/pypi_licenses.json ' | ||
'-l /tmp/logs/pypi_licenses_gpl.json', | ||
], | ||
self.test_gpl_pypi_deps.__name__, **kwargs, | ||
) | ||
|
||
@pytest.mark.usefixtures('_is_image_os', '_is_distribution') | ||
@pytest.mark.parametrize('_is_image_os', ['ubuntu18', 'ubuntu20', 'centos7', 'centos8'], indirect=True) | ||
@pytest.mark.parametrize('_is_distribution', ['dev', 'proprietary'], indirect=True) | ||
def test_gpl_pypi_deps_venv_tf2(self, tester, image): | ||
root = pathlib.Path(os.path.realpath(__name__)).parent | ||
image_folder = image.replace('/', '_').replace(':', '_') | ||
pypi_log_folder = root / 'logs' / image_folder / 'pypi_deps' | ||
if not pypi_log_folder.exists(): | ||
pypi_log_folder.mkdir() | ||
kwargs = { | ||
'volumes': { | ||
root / 'tests' / 'resources' / 'pypi_deps': {'bind': '/tmp/pypi_deps', 'mode': 'rw'}, # nosec | ||
pypi_log_folder: {'bind': '/tmp/logs', 'mode': 'rw'}, # nosec | ||
}, | ||
} | ||
tester.test_docker_image( | ||
image, | ||
['/bin/bash -ac "cd /opt/intel/venv_tf2 && . ./bin/activate && ' | ||
'python3 -m pip freeze 2>&1 | tee /tmp/logs/pypi_deps_tf2.log"', | ||
'/bin/bash -ac "cd /opt/intel/venv_tf2 && . ./bin/activate && ' | ||
'python3 -m pip check 2>&1 | tee /tmp/logs/pypi_deps_check_tf2.log"', | ||
'/bin/bash -ac "cd /opt/intel/venv_tf2 && . ./bin/activate && python3 -m pip install pipdeptree && ' | ||
'python3 -m pipdeptree -e PyGObject 2>&1 | tee /tmp/logs/pypi_deps_tree_tf2.log"', | ||
'/bin/bash -ac "cd /opt/intel/venv_tf2 && . ./bin/activate && python3 -m pip install pip-licenses && ' | ||
'pip-licenses --output-file /tmp/logs/pypi_licenses_tf2.log && ' | ||
'pip-licenses -f json --output-file /tmp/logs/pypi_licenses_tf2.json"', | ||
'python3 /tmp/pypi_deps/get_gpl_packages.py -f /tmp/logs/pypi_licenses_tf2.json ' | ||
'-l /tmp/logs/pypi_licenses_gpl_tf2.json', | ||
], | ||
self.test_gpl_pypi_deps_venv_tf2.__name__, **kwargs, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2019-2021 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""Check GPL/LGPL license for the installed PyPi packages | ||
""" | ||
import argparse | ||
import json | ||
import logging | ||
import sys | ||
|
||
parser = argparse.ArgumentParser(description='This is GPl/LGPL licenses checker for PyPi packages') | ||
parser.add_argument( | ||
'-f', | ||
'--file', | ||
metavar='PATH', | ||
required=True, | ||
help='JSON file with packages meta', | ||
) | ||
parser.add_argument( | ||
'-l', | ||
'--logs', | ||
metavar='PATH', | ||
required=False, | ||
default='pypi_licenses_gpl.json', | ||
help='Log file in json format', | ||
) | ||
|
||
logging.basicConfig(level='INFO') | ||
log = logging.getLogger(__name__) | ||
log.info('Start searching GPl/LGPL licenses in the installed PyPi packages ...') | ||
args = parser.parse_args() | ||
with open(args.file) as licenses_file: | ||
pkg_licenses = json.load(licenses_file) | ||
|
||
exit_code = 0 | ||
gpl_pkgs = [] | ||
for pkg in pkg_licenses: | ||
if 'GPL' in pkg['License']: | ||
gpl_pkgs.append(pkg) | ||
if 'LGPL' not in pkg['License']: | ||
log.error(f'GPL package was found in PyPi environment: {pkg}') | ||
exit_code = 1 | ||
log.debug(f'Found GPL/LGPL packages: {gpl_pkgs}') | ||
with open(args.logs, 'w') as gpl_licenses_file: | ||
json.dump(gpl_pkgs, gpl_licenses_file) | ||
log.info(f'See GPL/LGPL licenses in the json log: {args.logs}') | ||
|
||
if exit_code != 0: | ||
log.info('FAILED') | ||
else: | ||
log.info('PASSED') | ||
|
||
sys.exit(exit_code) |