Completed
Push — pyup-update-toml-0.9.2-to-0.9.... ( 3e288d )
by Michael
07:04 queued 06:58
created

install_from_pypi()   B

Complexity

Conditions 5

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7.0935

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
c 2
b 0
f 0
dl 0
loc 24
ccs 9
cts 16
cp 0.5625
crap 7.0935
rs 8.1671
1 3
import logging
2
3 3
from shutil import rmtree
4 3
from pathlib import Path
5
6 3
from changes import shell, util, venv, verification
7
8 3
log = logging.getLogger(__name__)
0 ignored issues
show
Coding Style Naming introduced by
The name log does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
9
10
11 3
def build_distributions(context):
12
    """Builds package distributions"""
13 3
    rmtree('dist', ignore_errors=True)
14
15 3
    build_package_command = 'python setup.py clean sdist bdist_wheel'
16 3
    result = shell.dry_run(build_package_command, context.dry_run)
17 3
    packages = Path('dist').files() if not context.dry_run else "nothing"
0 ignored issues
show
Bug introduced by
The Instance of Path does not seem to have a member named files.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
18
19 3
    if not result:
20
        raise Exception('Error building packages: %s' % result)
21
    else:
22 3
        log.info('Built %s' % ', '.join(packages))
23 3
    return packages
24
25
26
# tox
27 3
def install_package(context):
28
    """Attempts to install the sdist and wheel."""
29
30 3
    if not context.dry_run and build_distributions(context):
31
        with util.mktmpdir() as tmp_dir:
32
            venv.create_venv(tmp_dir=tmp_dir)
33
            for distribution in Path('dist').files():
0 ignored issues
show
Bug introduced by
The Instance of Path does not seem to have a member named files.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
34
                try:
35
                    venv.install(distribution, tmp_dir)
36
                    log.info('Successfully installed %s', distribution)
37
                    if context.test_command and verification.run_test_command(context.test_command):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (100/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
38
                        log.info('Successfully ran test command: %s',
39
                                 context.test_command)
40
                except Exception as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
41
                    raise Exception('Error installing distribution %s' % distribution, e)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (89/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
42
    else:
43 3
        log.info('Dry run, skipping installation')
44
45
46
# twine
47 3
def upload_package(context):
48
    """Uploads your project packages to pypi with twine."""
49
50 3
    if not context.dry_run and build_distributions(context):
51
        upload_args = 'twine upload '
52
        upload_args +=  ' '.join(Path('dist').files())
0 ignored issues
show
Coding Style introduced by
Exactly one space required after assignment
upload_args += ' '.join(Path('dist').files())
^^
Loading history...
Bug introduced by
The Instance of Path does not seem to have a member named files.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
53
        if context.pypi:
54
            upload_args += ' -r %s' % context.pypi
55
56
        upload_result = shell.dry_run(upload_args, context.dry_run)
57
        if not context.dry_run and not upload_result:
58
            raise Exception('Error uploading: %s' % upload_result)
59
        else:
60
            log.info('Successfully uploaded %s:%s', context.module_name, context.new_version)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (93/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
61
    else:
62 3
        log.info('Dry run, skipping package upload')
63
64
65 3
def install_from_pypi(context):
66
    """Attempts to install your package from pypi."""
67
68 3
    tmp_dir = venv.create_venv()
69 3
    install_cmd = '%s/bin/pip install %s' % (tmp_dir, context.module_name)
70
71 3
    package_index = 'pypi'
72 3
    if context.pypi:
73
        install_cmd += '-i %s' % context.pypi
74
        package_index = context.pypi
75
76 3
    try:
77 3
        result = shell.dry_run(install_cmd, context.dry_run)
78 3
        if not context.dry_run and not result:
79
            log.error('Failed to install %s from %s',
80
                      context.module_name, package_index)
81
        else:
82 3
            log.info('Successfully installed %s from %s',
83
                     context.module_name, package_index)
84
85
    except Exception as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
86
        error_msg = 'Error installing %s from %s' % (context.module_name, package_index)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (88/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
87
        log.exception(error_msg)
88
        raise Exception(error_msg, e)
89