1
|
3 |
|
from datetime import date |
2
|
3 |
|
from pathlib import Path |
3
|
|
|
|
4
|
3 |
|
import bumpversion |
|
|
|
|
5
|
3 |
|
import pkg_resources |
6
|
3 |
|
from jinja2 import Template |
|
|
|
|
7
|
|
|
|
8
|
3 |
|
import changes |
9
|
3 |
|
from changes.config import BumpVersion |
10
|
3 |
|
from changes.models import Release |
11
|
3 |
|
from . import info, error, note |
12
|
3 |
|
from .status import status |
13
|
|
|
|
14
|
|
|
|
15
|
3 |
|
def stage(draft, release_name=None, release_description=None): |
16
|
3 |
|
repository, bumpversion_part, release_type, proposed_version = status() |
17
|
|
|
|
18
|
3 |
|
if not repository.changes_since_last_version: |
19
|
|
|
error("There aren't any changes to release!") |
20
|
|
|
return |
21
|
|
|
|
22
|
3 |
|
info('Staging [{}] release for version {}'.format( |
23
|
|
|
release_type, |
24
|
|
|
proposed_version |
25
|
|
|
)) |
26
|
|
|
|
27
|
3 |
|
bumpversion_arguments = ( |
28
|
|
|
BumpVersion.DRAFT_OPTIONS if draft |
29
|
|
|
else BumpVersion.STAGE_OPTIONS |
30
|
|
|
) |
31
|
3 |
|
bumpversion_arguments += [bumpversion_part] |
32
|
|
|
|
33
|
3 |
|
info('Running: bumpversion {}'.format( |
34
|
|
|
' '.join(bumpversion_arguments) |
35
|
|
|
)) |
36
|
|
|
|
37
|
3 |
|
try: |
38
|
3 |
|
bumpversion.main(bumpversion_arguments) |
39
|
|
|
except bumpversion.WorkingDirectoryIsDirtyException as err: |
40
|
|
|
error(err) |
41
|
|
|
raise |
42
|
|
|
|
43
|
3 |
|
info('Generating Release') |
44
|
|
|
# prepare context for changelog documentation |
45
|
3 |
|
project_labels = changes.project_settings.labels |
46
|
3 |
|
for label, properties in project_labels.items(): |
47
|
3 |
|
pull_requests_with_label = [ |
48
|
|
|
pull_request |
49
|
|
|
for pull_request in repository.changes_since_last_version |
50
|
|
|
if label in pull_request.labels |
51
|
|
|
] |
52
|
|
|
|
53
|
3 |
|
project_labels[label]['pull_requests'] = pull_requests_with_label |
54
|
|
|
|
55
|
3 |
|
release = Release( |
56
|
|
|
name=release_name, |
57
|
|
|
release_date=date.today().isoformat(), |
58
|
|
|
version=proposed_version, |
59
|
|
|
description=release_description, |
60
|
|
|
changes=project_labels, |
61
|
|
|
) |
62
|
|
|
|
63
|
3 |
|
info('Loading template...') |
64
|
|
|
# TODO: if project_settings.release_notes_template is None |
65
|
3 |
|
release_notes_template = pkg_resources.resource_string( |
66
|
|
|
changes.__name__, |
67
|
|
|
'templates/release_notes_template.md' |
68
|
|
|
).decode('utf8') |
69
|
|
|
|
70
|
3 |
|
release_notes = Template(release_notes_template).render(release=release) |
71
|
|
|
# TODO: jinja2.exceptions.UndefinedError |
72
|
|
|
|
73
|
3 |
|
releases_directory = Path(changes.project_settings.releases_directory) |
74
|
3 |
|
if not releases_directory.exists(): |
75
|
3 |
|
releases_directory.mkdir(parents=True) |
76
|
3 |
|
release_notes_path = releases_directory.joinpath( |
77
|
|
|
'{}.md'.format(release.version) |
78
|
|
|
) |
79
|
3 |
|
if not draft: |
80
|
3 |
|
release_notes_path.write_text(release_notes) |
|
|
|
|
81
|
|
|
else: |
82
|
|
|
note(release_notes) |
83
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.