Conditions | 5 |
Total Lines | 74 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 | # Copyright 2014 Diamond Light Source Ltd. |
||
33 | def create_plugin_template_downloads(savu_base_path): |
||
34 | """Inside plugin_examples/plugin_templates/general |
||
35 | If the file begins with 'plugin_template' then select it |
||
36 | Read the lines of the files docstring and set as a descriptor |
||
37 | """ |
||
38 | dev_file_path = f"{savu_base_path}doc/source/dev_guides/" |
||
39 | doc_template_file = f"{dev_file_path}dev_plugin_templates.rst" |
||
40 | |||
41 | # Populate dictionary with template class and template class docstring |
||
42 | docstring_text = create_template_class_dict(savu_base_path) |
||
43 | if docstring_text: |
||
44 | with open(doc_template_file, "w") as doc_template: |
||
45 | doc_template.write(".. _plugin_templates:\n") |
||
46 | doc_template.write("\n") |
||
47 | doc_template.write(f"Plugin templates {pdoc.set_underline(6 ,23)}") |
||
48 | doc_template.write("\n") |
||
49 | |||
50 | doc_name = "plugin_template1_with_detailed_notes" |
||
51 | detailed_template = docstring_text.get(doc_name) |
||
52 | |||
53 | if detailed_template: |
||
54 | docstring_text.pop(doc_name) |
||
55 | title = pdoc.convert_title(doc_name) |
||
56 | title, number = filter_template_numbers(title) |
||
57 | # Create the restructured text page for the plugin template |
||
58 | # python code |
||
59 | generate_template_files(doc_name, title) |
||
60 | inner_file_str = \ |
||
61 | "../../../plugin_examples/plugin_templates/general" |
||
62 | doc_template.write(f"{title}{pdoc.set_underline(3 ,66)}") |
||
63 | doc_template.write( |
||
64 | "\nA template to create a simple plugin " |
||
65 | "that takes one dataset as input and returns " |
||
66 | "a similar dataset as output" |
||
67 | ) |
||
68 | doc_template.write("\n") |
||
69 | doc_template.write( |
||
70 | """ |
||
71 | .. list-table:: |
||
72 | :widths: 10 |
||
73 | |||
74 | * - :ref:`""" |
||
75 | + doc_name |
||
76 | + """` |
||
77 | |||
78 | """ |
||
79 | ) |
||
80 | doc_template.write(f"Further Examples{pdoc.set_underline(3 ,66)}") |
||
81 | # Begin the table layout |
||
82 | doc_template.write( |
||
83 | """ |
||
84 | .. list-table:: |
||
85 | :widths: 10 90 |
||
86 | :header-rows: 1 |
||
87 | |||
88 | * - Link |
||
89 | - Description""" |
||
90 | ) |
||
91 | |||
92 | for doc_name, doc_str in docstring_text.items(): |
||
93 | title = pdoc.convert_title(doc_name) |
||
94 | title, number = filter_template_numbers(title) |
||
95 | desc_str = doc_str["desc"] |
||
96 | # Create a link to the restructured text page view of |
||
97 | # the python code for the template |
||
98 | doc_template.write("\n * - :ref:`" + doc_name + "`") |
||
99 | # The template description from the docstring |
||
100 | doc_template.write("\n - " + desc_str) |
||
101 | doc_template.write("\n") |
||
102 | # Create the restructured text page for the plugin template |
||
103 | # python code |
||
104 | generate_template_files(doc_name, title) |
||
105 | |||
106 | doc_template.write("\n") |
||
107 | |||
219 |