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__) |
|
|
|
|
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" |
|
|
|
|
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(): |
|
|
|
|
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): |
|
|
|
|
38
|
|
|
log.info('Successfully ran test command: %s', |
39
|
|
|
context.test_command) |
40
|
|
|
except Exception as e: |
|
|
|
|
41
|
|
|
raise Exception('Error installing distribution %s' % distribution, e) |
|
|
|
|
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()) |
|
|
|
|
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) |
|
|
|
|
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: |
|
|
|
|
86
|
|
|
error_msg = 'Error installing %s from %s' % (context.module_name, package_index) |
|
|
|
|
87
|
|
|
log.exception(error_msg) |
88
|
|
|
raise Exception(error_msg, e) |
89
|
|
|
|
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.