Conditions | 9 |
Total Lines | 77 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | from datetime import date |
||
14 | def stage(draft, discard=False, release_name='', release_description=''): |
||
15 | discard = False |
||
16 | if discard: |
||
17 | info('Discarding currently staged release') |
||
18 | # modified_bumpversion_files = changes.project_settings.bumpversion.version_files_to_replace |
||
19 | # git_discard_files = modified_bumpversion_files |
||
20 | # git(['checkout', '--'] + git_discard_files) |
||
21 | # release_notes_path = Path(changes.project_settings.releases_directory).joinpath( |
||
22 | # '{}.md'.format(release.version) |
||
23 | # ) |
||
24 | # release_notes_path.remove() |
||
25 | |||
26 | repository = changes.project_settings.repository |
||
27 | bumpversion_part, release_type, proposed_version = changes_to_release_type(repository) |
||
28 | |||
29 | if not repository.changes_since_last_version: |
||
30 | error("There aren't any changes to release!") |
||
31 | return |
||
32 | |||
33 | info('Staging [{}] release for version {}'.format( |
||
34 | release_type, |
||
35 | proposed_version |
||
36 | )) |
||
37 | |||
38 | bumpversion_arguments = ( |
||
39 | BumpVersion.DRAFT_OPTIONS if draft |
||
40 | else BumpVersion.STAGE_OPTIONS |
||
41 | ) |
||
42 | bumpversion_arguments += [bumpversion_part] |
||
43 | |||
44 | info('Running: bumpversion {}'.format( |
||
45 | ' '.join(bumpversion_arguments) |
||
46 | )) |
||
47 | bumpversion.main(bumpversion_arguments) |
||
48 | |||
49 | info('Generating Release') |
||
50 | # prepare context for changelog documentation |
||
51 | project_labels = changes.project_settings.labels |
||
52 | for label, properties in project_labels.items(): |
||
53 | pull_requests_with_label = [ |
||
54 | pull_request |
||
55 | for pull_request in repository.changes_since_last_version |
||
56 | if label in pull_request.labels |
||
57 | ] |
||
58 | |||
59 | project_labels[label]['pull_requests'] = pull_requests_with_label |
||
60 | |||
61 | release = Release( |
||
62 | name=release_name, |
||
63 | release_date=date.today().isoformat(), |
||
64 | version=str(proposed_version), |
||
65 | description=release_description, |
||
66 | changes=project_labels, |
||
67 | ) |
||
68 | |||
69 | # TODO: if project_settings.release_notes_template is None |
||
70 | release_notes_template = pkg_resources.resource_string( |
||
71 | changes.__name__, |
||
72 | 'templates/release_notes_template.md' |
||
73 | ).decode('utf8') |
||
74 | |||
75 | release_notes = Template(release_notes_template).render(release=release) |
||
76 | |||
77 | releases_directory = Path(changes.project_settings.releases_directory) |
||
78 | if not releases_directory.exists(): |
||
79 | releases_directory.mkdir(parents=True) |
||
80 | |||
81 | release_notes_path = releases_directory.joinpath( |
||
82 | '{}.md'.format(release.version) |
||
83 | ) |
||
84 | |||
85 | if draft: |
||
86 | info('Would have created {}:'.format(release_notes_path)) |
||
87 | debug(release_notes) |
||
88 | else: |
||
89 | info('Writing release notes to {}'.format(release_notes_path)) |
||
90 | release_notes_path.write_text(release_notes, encoding='utf-8') |
||
91 |
Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.