Exemplo n.º 1
0
def get_licenses(ctx):
    vendor_dir = _get_vendor_dir(ctx)
    log('Using vendor dir: %s' % vendor_dir)
    log('Downloading LICENSE files...')
    build_dir = vendor_dir / 'build'
    download_dir = TemporaryDirectory(prefix='pipenv-', suffix='-licenses')
    if build_dir.exists() and build_dir.is_dir():
        drop_dir(build_dir)

    ctx.run(
        'pip download -b {0} --no-binary=:all: --no-clean --no-deps -r {1}/vendor.txt -d {2}'
        .format(
            str(build_dir),
            str(vendor_dir),
            str(download_dir.name),
        ))
    for p in build_dir.glob('*/*LICENSE*'):
        parent = p.parent
        matches = [
            flat for flat in FLATTEN
            if parent.joinpath(flat).exists() or parent.name == flat
        ]
        egg_info_dir = [e for e in parent.glob('*.egg-info')]
        if any(matches):
            from pipenv.utils import pep423_name
            pkg = pep423_name(matches[0]).lower()
            pkg_name = pkg if parent.joinpath(
                pkg).exists() else parent.name.lower()
            target_file = '{0}.LICENSE'.format(pkg_name)
            target_file = vendor_dir / target_file
        elif egg_info_dir:
            egg_info_dir = egg_info_dir[0]
            pkg_name = egg_info_dir.stem.lower()
            target_file = vendor_dir / pkg_name / p.name.lower()
            if '.' in pkg_name:
                target_file = vendor_dir.joinpath(
                    *pkg_name.split('.')) / p.name
        else:
            target_dir = vendor_dir / parent.name
            if '.' in parent.name:
                target_dir = vendor_dir.joinpath(*parent.name.split('.'))
            target_file = target_dir / p.name.lower()
        mkdir_p(str(target_file.parent.absolute()))
        shutil.copyfile(str(p.absolute()), str(target_file.absolute()))
    drop_dir(build_dir)
    download_dir.cleanup()
Exemplo n.º 2
0
    def test_relative_paths(self):
        file_name = 'tablib-0.12.1.tar.gz'
        test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
        source_path = os.path.abspath(os.path.join(test_dir, 'test_artifacts', file_name))

        with PipenvInstance() as p:
            artifact_dir = 'artifacts'
            artifact_path = os.path.join(p.path, artifact_dir)
            mkdir_p(artifact_path)
            shutil.copy(source_path, os.path.join(artifact_path, file_name))
            # Test installing a relative path in a subdirectory
            c = p.pipenv('install {}/{}'.format(artifact_dir, file_name))
            key = [k for k in p.pipfile['packages'].keys()][0]
            dep = p.pipfile['packages'][key]

            assert 'path' in dep
            assert Path(os.path.join('.', artifact_dir, file_name)) == Path(dep['path'])
            assert c.return_code == 0
Exemplo n.º 3
0
def test_relative_paths(PipenvInstance, pypi, testsroot):
    file_name = "requests-2.19.1.tar.gz"
    source_path = os.path.abspath(os.path.join(testsroot, "test_artifacts", file_name))

    with PipenvInstance(pypi=pypi) as p:
        artifact_dir = "artifacts"
        artifact_path = os.path.join(p.path, artifact_dir)
        mkdir_p(artifact_path)
        shutil.copy(source_path, os.path.join(artifact_path, file_name))
        # Test installing a relative path in a subdirectory
        c = p.pipenv("install {}/{}".format(artifact_dir, file_name))
        assert c.return_code == 0
        key = next(k for k in p.pipfile["packages"].keys())
        dep = p.pipfile["packages"][key]

        assert "path" in dep
        assert Path(".", artifact_dir, file_name) == Path(dep["path"])
        assert c.return_code == 0
Exemplo n.º 4
0
def test_relative_paths(PipenvInstance, pypi, testsroot):
    file_name = 'tablib-0.12.1.tar.gz'
    source_path = os.path.abspath(os.path.join(testsroot, 'test_artifacts', file_name))

    with PipenvInstance(pypi=pypi) as p:
        artifact_dir = 'artifacts'
        artifact_path = os.path.join(p.path, artifact_dir)
        mkdir_p(artifact_path)
        shutil.copy(source_path, os.path.join(artifact_path, file_name))
        # Test installing a relative path in a subdirectory
        c = p.pipenv('install {}/{}'.format(artifact_dir, file_name))
        assert c.return_code == 0
        key = next(k for k in p.pipfile['packages'].keys())
        dep = p.pipfile['packages'][key]

        assert 'path' in dep
        assert pathlib.Path('.', artifact_dir, file_name) == pathlib.Path(dep['path'])
        assert c.return_code == 0
def test_relative_paths(PipenvInstance, testsroot):
    file_name = "requests-2.19.1.tar.gz"
    source_path = os.path.abspath(os.path.join(testsroot, "test_artifacts", file_name))

    with PipenvInstance() as p:
        artifact_dir = "artifacts"
        artifact_path = os.path.join(p.path, artifact_dir)
        mkdir_p(artifact_path)
        shutil.copy(source_path, os.path.join(artifact_path, file_name))
        # Test installing a relative path in a subdirectory
        c = p.pipenv("install {}/{}".format(artifact_dir, file_name))
        assert c.return_code == 0
        key = next(k for k in p.pipfile["packages"].keys())
        dep = p.pipfile["packages"][key]

        assert "path" in dep
        assert Path(".", artifact_dir, file_name) == Path(dep["path"])
        assert c.return_code == 0
Exemplo n.º 6
0
    def test_relative_paths(self):
        file_name = 'tablib-0.12.1.tar.gz'
        test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
        source_path = os.path.abspath(os.path.join(test_dir, 'test_artifacts', file_name))

        with PipenvInstance() as p:
            artifact_dir = 'artifacts'
            artifact_path = os.path.join(p.path, artifact_dir)
            mkdir_p(artifact_path)
            shutil.copy(source_path, os.path.join(artifact_path, file_name))
            # Test installing a relative path in a subdirectory
            c = p.pipenv('install {}/{}'.format(artifact_dir, file_name))
            key = [k for k in p.pipfile['packages'].keys()][0]
            dep = p.pipfile['packages'][key]

            assert 'path' in dep
            assert Path(os.path.join('.', artifact_dir, file_name)) == Path(dep['path'])
            assert c.return_code == 0
def test_install_local_uri_special_character(PipenvInstance, testsroot):
    file_name = 'six-1.11.0+mkl-py2.py3-none-any.whl'
    source_path = os.path.abspath(
        os.path.join(testsroot, 'test_artifacts', file_name))
    with PipenvInstance() as p:
        artifact_dir = 'artifacts'
        artifact_path = os.path.join(p.path, artifact_dir)
        mkdir_p(artifact_path)
        shutil.copy(source_path, os.path.join(artifact_path, file_name))
        with open(p.pipfile_path, 'w') as f:
            contents = """
# Pre comment
[packages]
six = {{path = "./artifacts/{}"}}   
            """.format(file_name)
            f.write(contents.strip())
        c = p.pipenv('install')
        assert c.return_code == 0
        assert 'six' in p.lockfile['default']
Exemplo n.º 8
0
def test_install_local_uri_special_character(PipenvInstance, testsroot):
    file_name = "six-1.11.0+mkl-py2.py3-none-any.whl"
    source_path = os.path.abspath(os.path.join(testsroot, "test_artifacts", file_name))
    with PipenvInstance() as p:
        artifact_dir = "artifacts"
        artifact_path = os.path.join(p.path, artifact_dir)
        mkdir_p(artifact_path)
        shutil.copy(source_path, os.path.join(artifact_path, file_name))
        with open(p.pipfile_path, "w") as f:
            contents = """
# Pre comment
[packages]
six = {{path = "./artifacts/{}"}}
            """.format(
                file_name
            )
            f.write(contents.strip())
        c = p.pipenv("install")
        assert c.return_code == 0
        assert "six" in p.lockfile["default"]
Exemplo n.º 9
0
def update_safety(ctx):
    ignore_subdeps = ['pip', 'pip-egg-info', 'bin']
    ignore_files = ['pip-delete-this-directory.txt', 'PKG-INFO']
    vendor_dir = _get_patched_dir(ctx)
    log('Using vendor dir: %s' % vendor_dir)
    log('Downloading safety package files...')
    build_dir = vendor_dir / 'build'
    download_dir = TemporaryDirectory(prefix='pipenv-', suffix='-safety')
    if build_dir.exists() and build_dir.is_dir():
        drop_dir(build_dir)

    ctx.run(
        'pip download -b {0} --no-binary=:all: --no-clean -d {1} safety pyyaml'
        .format(
            str(build_dir),
            str(download_dir.name),
        ))
    safety_dir = build_dir / 'safety'
    yaml_build_dir = build_dir / 'pyyaml'
    main_file = safety_dir / '__main__.py'
    main_content = """
import sys
yaml_lib = 'yaml{0}'.format(sys.version_info[0])
locals()[yaml_lib] = __import__(yaml_lib)
sys.modules['yaml'] = sys.modules[yaml_lib]
from safety.cli import cli

# Disable insecure warnings.
import urllib3
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)

cli(prog_name="safety")
    """.strip()
    with open(str(main_file), 'w') as fh:
        fh.write(main_content)

    with ctx.cd(str(safety_dir)):
        ctx.run('pip install --no-compile --no-binary=:all: -t . .')
        safety_dir = safety_dir.absolute()
        yaml_dir = safety_dir / 'yaml'
        if yaml_dir.exists():
            version_choices = ['2', '3']
            version_choices.remove(str(sys.version_info[0]))
            mkdir_p(str(safety_dir / 'yaml{0}'.format(sys.version_info[0])))
            for fn in yaml_dir.glob('*.py'):
                fn.rename(
                    str(
                        safety_dir.joinpath(
                            'yaml{0}'.format(sys.version_info[0]), fn.name)))
            if version_choices[0] == '2':
                lib = yaml_build_dir / 'lib' / 'yaml'
            else:
                lib = yaml_build_dir / 'lib3' / 'yaml'
            shutil.copytree(
                str(lib.absolute()),
                str(safety_dir / 'yaml{0}'.format(version_choices[0])))
        requests_dir = safety_dir / 'requests'
        cacert = vendor_dir / 'requests' / 'cacert.pem'
        if not cacert.exists():
            from pipenv.vendor import requests
            cacert = Path(requests.certs.where())
        target_cert = requests_dir / 'cacert.pem'
        target_cert.write_bytes(cacert.read_bytes())
        ctx.run(
            "sed -i 's/r = requests.get(url=url, timeout=REQUEST_TIMEOUT, headers=headers)/r = requests.get(url=url, timeout=REQUEST_TIMEOUT, headers=headers, verify=False)/g' {0}"
            .format(str(safety_dir / 'safety' / 'safety.py')))
        for egg in safety_dir.glob('*.egg-info'):
            drop_dir(egg.absolute())
        for dep in ignore_subdeps:
            dep_dir = safety_dir / dep
            if dep_dir.exists():
                drop_dir(dep_dir)
        for dep in ignore_files:
            fn = safety_dir / dep
            if fn.exists():
                fn.unlink()
    zip_name = '{0}/safety'.format(str(vendor_dir))
    shutil.make_archive(zip_name,
                        format='zip',
                        root_dir=str(safety_dir),
                        base_dir='./')
    drop_dir(build_dir)
    download_dir.cleanup()
Exemplo n.º 10
0
def update_safety(ctx):
    ignore_subdeps = ['pip', 'pip-egg-info', 'bin']
    ignore_files = ['pip-delete-this-directory.txt', 'PKG-INFO']
    vendor_dir = _get_patched_dir(ctx)
    log('Using vendor dir: %s' % vendor_dir)
    log('Downloading safety package files...')
    build_dir = vendor_dir / 'build'
    download_dir = TemporaryDirectory(prefix='pipenv-', suffix='-safety')
    if build_dir.exists() and build_dir.is_dir():
        drop_dir(build_dir)

    ctx.run(
        'pip download -b {0} --no-binary=:all: --no-clean -d {1} safety pyyaml'.format(
            str(build_dir), str(download_dir.name),
        )
    )
    safety_dir = build_dir / 'safety'
    yaml_build_dir = build_dir / 'pyyaml'
    main_file = safety_dir / '__main__.py'
    main_content = """
import sys
yaml_lib = 'yaml{0}'.format(sys.version_info[0])
locals()[yaml_lib] = __import__(yaml_lib)
sys.modules['yaml'] = sys.modules[yaml_lib]
from safety.cli import cli

# Disable insecure warnings.
import urllib3
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)

cli(prog_name="safety")
    """.strip()
    with open(str(main_file), 'w') as fh:
        fh.write(main_content)

    with ctx.cd(str(safety_dir)):
        ctx.run('pip install --no-compile --no-binary=:all: -t . .')
        safety_dir = safety_dir.absolute()
        yaml_dir = safety_dir / 'yaml'
        if yaml_dir.exists():
            version_choices = ['2', '3']
            version_choices.remove(str(sys.version_info[0]))
            mkdir_p(str(safety_dir / 'yaml{0}'.format(sys.version_info[0])))
            for fn in yaml_dir.glob('*.py'):
                fn.rename(str(safety_dir.joinpath('yaml{0}'.format(sys.version_info[0]), fn.name)))
            if version_choices[0] == '2':
                lib = yaml_build_dir / 'lib' / 'yaml'
            else:
                lib = yaml_build_dir / 'lib3' / 'yaml'
            shutil.copytree(str(lib.absolute()), str(safety_dir / 'yaml{0}'.format(version_choices[0])))
        requests_dir = safety_dir / 'requests'
        cacert = vendor_dir / 'requests' / 'cacert.pem'
        if not cacert.exists():
            from pipenv.vendor import requests
            cacert = Path(requests.certs.where())
        target_cert = requests_dir / 'cacert.pem'
        target_cert.write_bytes(cacert.read_bytes())
        ctx.run("sed -i 's/r = requests.get(url=url, timeout=REQUEST_TIMEOUT, headers=headers)/r = requests.get(url=url, timeout=REQUEST_TIMEOUT, headers=headers, verify=False)/g' {0}".format(str(safety_dir / 'safety' / 'safety.py')))
        for egg in safety_dir.glob('*.egg-info'):
            drop_dir(egg.absolute())
        for dep in ignore_subdeps:
            dep_dir = safety_dir / dep
            if dep_dir.exists():
                drop_dir(dep_dir)
        for dep in ignore_files:
            fn = safety_dir / dep
            if fn.exists():
                fn.unlink()
    zip_name = '{0}/safety'.format(str(vendor_dir))
    shutil.make_archive(zip_name, format='zip', root_dir=str(safety_dir), base_dir='./')
    drop_dir(build_dir)
    download_dir.cleanup()
Exemplo n.º 11
0
def jira_viz(jira_test_coverages):
    '''generate the charts according to the input JiraTestCoverage object'''
    for jira_test_coverage in jira_test_coverages:
        # make figure and assign axis objects
        fig = plt.figure(figsize=(6.6, 5.5))
        ax1 = fig.add_subplot(111)
        fig.subplots_adjust(wspace=0)

        # pie chart parameters
        ratios = []
        labels = []

        total_issues_count = len(jira_test_coverage.issue_keys)
        if total_issues_count > 0:
            no_case_needed_issues = jira_test_coverage.test_coverage_issues.get(TestCoverage.No_Case_Needed.name, set())
            junit_issues = jira_test_coverage.test_coverage_issues.get(TestCoverage.Covered_by_Junit.name, set())
            tuj_issues = jira_test_coverage.test_coverage_issues.get(TestCoverage.Covered_by_Tuj.name, set())
            manual_case_issues = jira_test_coverage.test_coverage_issues.get(TestCoverage.Covered_by_manualCases.name,
                                                                             set())
            no_label_issues = jira_test_coverage.test_coverage_issues.get(TestCoverage.No_Label.name, set())

            junit_issues_only = junit_issues - tuj_issues - manual_case_issues
            tuj_issues_only = tuj_issues - junit_issues - manual_case_issues
            manual_case_issues_only = manual_case_issues - junit_issues - tuj_issues
            junit_tuj_issues_only = junit_issues & tuj_issues - manual_case_issues
            junit_manual_case_issues_only = junit_issues & manual_case_issues - tuj_issues
            tuj_manual_case_issues_only = tuj_issues & manual_case_issues - junit_issues
            junit_tuj_manual_case_issues = junit_issues & tuj_issues & manual_case_issues

            if len(no_label_issues) > 0:
                ratios.append(len(no_label_issues) / total_issues_count)
                labels.append(f'{TestCoverage.No_Label.value}({len(no_label_issues)})')
            if len(no_case_needed_issues) > 0:
                ratios.append(len(no_case_needed_issues) / total_issues_count)
                labels.append(f'{TestCoverage.No_Case_Needed.value}({len(no_case_needed_issues)})')
            if len(junit_issues_only) > 0:
                ratios.append(len(junit_issues_only) / total_issues_count)
                labels.append(f'{TestCoverage.Covered_by_Junit.value}({len(junit_issues_only)})')
            if len(tuj_issues_only) > 0:
                ratios.append(len(tuj_issues_only) / total_issues_count)
                labels.append(f'{TestCoverage.Covered_by_Tuj.value}({len(tuj_issues_only)})')
            if len(manual_case_issues_only) > 0:
                ratios.append(len(manual_case_issues_only) / total_issues_count)
                labels.append(f'{TestCoverage.Covered_by_manualCases.value}({len(manual_case_issues_only)})')
            if len(junit_tuj_issues_only) > 0:
                ratios.append(len(junit_tuj_issues_only) / total_issues_count)
                labels.append(
                    f'{TestCoverage.Covered_by_Junit.value}+{TestCoverage.Covered_by_Tuj.value}({len(junit_tuj_issues_only)})')
            if len(junit_manual_case_issues_only) > 0:
                ratios.append(len(junit_manual_case_issues_only) / total_issues_count)
                labels.append(
                    f'{TestCoverage.Covered_by_Junit.value}+{TestCoverage.Covered_by_manualCases.value}({len(junit_manual_case_issues_only)})')
            if len(tuj_manual_case_issues_only) > 0:
                ratios.append(len(tuj_manual_case_issues_only) / total_issues_count)
                labels.append(
                    f'{TestCoverage.Covered_by_Tuj.value}+{TestCoverage.Covered_by_manualCases.value}({len(tuj_manual_case_issues_only)})')
            if len(junit_tuj_manual_case_issues) > 0:
                ratios.append(len(junit_tuj_manual_case_issues) / total_issues_count)
                labels.append(
                    f'{TestCoverage.Covered_by_Junit.value}+{TestCoverage.Covered_by_Tuj.value}+{TestCoverage.Covered_by_manualCases.value}({len(junit_tuj_manual_case_issues)})')

        explode = []
        for i in range(0, len(labels)):
            if i < len(labels) - 1:
                explode.append(0)
            else:
                explode.append(0.1)

        # rotate so that first wedge is split by the x-axis
        angle = -180 * ratios[0]
        ax1.pie(ratios, autopct='%1.2f%%', startangle=angle,
                labels=labels, explode=explode)
        ax1.set_title(
            f'{jira_test_coverage.sprint_name}\n{jira_test_coverage.start_date.strftime("%Y-%m-%d")} ~ {jira_test_coverage.end_date.strftime("%Y-%m-%d")}\nTotal Jira Issue: {len(jira_test_coverage.issue_keys)}',
            fontsize=12)

        # save the charts
        out_dir = f'{jira_test_coverage.sprint_id}'
        mkdir_p(out_dir)
        plt.savefig('{}/test_coverage_1.png'.format(out_dir))