-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathcontributing.html
379 lines (347 loc) · 22.5 KB
/
contributing.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Licensed under the Apache 2.0 License -->
<link rel="stylesheet" type="text/css" href="_static/fonts/open-sans/stylesheet.css" />
<!-- Licensed under the SIL Open Font License -->
<link rel="stylesheet" type="text/css" href="_static/fonts/source-serif-pro/source-serif-pro.css" />
<link rel="stylesheet" type="text/css" href="_static/css/bootstrap.min.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contributing — jMetalPy 1.7.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="_static/guzzle.css?v=e05a0192" />
<link rel="stylesheet" type="text/css" href="_static/custom.css?v=9aa90875" />
<script src="_static/documentation_options.js?v=030dc6f6"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<link rel="author" title="About these documents" href="about.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="About" href="about.html" />
<link rel="prev" title="Single-objective problems" href="api/problem/singleobjective.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="about.html" title="About"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="api/problem/singleobjective.html" title="Single-objective problems"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">jMetalPy 1.7.0 documentation</a> »</li>
<li class="nav-item nav-item-this"><a href="">Contributing</a></li>
</ul>
</div>
<div class="container-wrapper">
<div id="mobile-toggle">
<a href="#"><span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span></a>
</div>
<div id="left-column">
<div class="sphinxsidebar"><a href="
index.html" class="text-logo">
<img src="_static/jmetalpy.png" class="img-fluid" alt="jMetalPy 1.7.0 documentation">
<br>
</a>
<div class="sidebar-block">
<div class="sidebar-wrapper">
Python version of the jMetal framework
</div>
</div>
<div class="sidebar-block">
<div class="sidebar-wrapper">
<h2>Table Of Contents</h2>
</div>
<div class="sidebar-toc">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="tutorials.html">Getting started</a></li>
<li class="toctree-l1"><a class="reference internal" href="multiobjective.algorithms.html">Multi-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="singleobjective.algorithms.html">Single-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="operators.html">Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="problems.html">Problems</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Contributing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#git-workflow">Git WorkFlow</a></li>
<li class="toctree-l2"><a class="reference internal" href="#pep8">PEP8!</a></li>
<li class="toctree-l2"><a class="reference internal" href="#object-oriented-programming">Object-oriented programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="#structure">Structure</a></li>
<li class="toctree-l2"><a class="reference internal" href="#python-3-6">Python 3.6</a></li>
<li class="toctree-l2"><a class="reference internal" href="#create-automatic-documentation-files-with-sphinx">Create automatic documentation files with Sphinx</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="about.html">About</a></li>
</ul>
</div>
</div>
<div class="sidebar-block">
<div class="sidebar-wrapper">
<h2>Contents</h2>
<div class="sidebar-localtoc">
<ul>
<li><a class="reference internal" href="#">Contributing</a><ul>
<li><a class="reference internal" href="#git-workflow">Git WorkFlow</a></li>
<li><a class="reference internal" href="#pep8">PEP8!</a></li>
<li><a class="reference internal" href="#object-oriented-programming">Object-oriented programming</a></li>
<li><a class="reference internal" href="#structure">Structure</a></li>
<li><a class="reference internal" href="#python-3-6">Python 3.6</a></li>
<li><a class="reference internal" href="#create-automatic-documentation-files-with-sphinx">Create automatic documentation files with Sphinx</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="sidebar-block">
<div class="sidebar-wrapper">
<div id="main-search">
<form class="form-inline" action="search.html" method="GET" role="form">
<div class="input-group">
<input name="q" type="text" class="form-control" placeholder="Search...">
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div>
</div>
</div>
<div id="right-column">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.html">Docs</a></li>
<li class="breadcrumb-item">Contributing</li>
</ol>
</nav>
<div class="document clearer body">
<section id="contributing">
<h1>Contributing<a class="headerlink" href="#contributing" title="Link to this heading">¶</a></h1>
<p>Contributions to the jMetalPy project are welcome.
Please, take into account the following guidelines (all developers should follow these guidelines):</p>
<section id="git-workflow">
<h2>Git WorkFlow<a class="headerlink" href="#git-workflow" title="Link to this heading">¶</a></h2>
<p>We have a set of branches on the remote Git server.
Some branches are temporary, and others are constant throughout the life of the repository.</p>
<ul class="simple">
<li><dl class="simple">
<dt>Branches always present in the repository:</dt><dd><ul>
<li><dl class="simple">
<dt><em>master</em>: You have the latest released to production, receive merges from the develop branch, or merge from a <em>hotfix</em> branch (emergency).</dt><dd><ul>
<li><p>Do I have to put a TAG when doing a merge from develop to master? yes</p></li>
<li><p>Do I have to put a TAG when doing a merge from a hotfix branch to master? yes</p></li>
<li><p>After merge from a hotfix to master, do I have to merge from master to develop? yes</p></li>
</ul>
</dd>
</dl>
</li>
<li><p><em>develop</em>: It is considered the “Next Release”, receives merges from branches of each developer, either corrections (<em>fix</em>) or new features (<em>feature</em>).</p></li>
</ul>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>Temporary branches:</dt><dd><ul>
<li><dl class="simple">
<dt><em>feature/<task-id>-<description></em>: When we are doing a development, we create a local branch with the prefix “feature/”, then only if there is a task id, we indicate it and we add a hyphen. The following we indicate a description according to the functionality that we are developing. The words are separated by hyphens.</dt><dd><ul>
<li><p>Where does this branch emerge? This branch always emerge from the develop branch</p></li>
<li><p>When I finish the development in my feature branch, which branch to merge into?: You always merge feature branch into develop branch</p></li>
</ul>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt><em>fix/<task-id>-<description></em>: When we are making a correction, we create a local branch with the prefix “fix/”, then only if there is a task id, we indicate it and we add a hyphen. The following we indicate a description according to the functionality that we are correcting. The words are separated by hyphens.</dt><dd><ul>
<li><p>Where does this branch emerge? This branch always emerge from the develop branch</p></li>
<li><p>When I finish the correction in my fix branch, which branch to merge into?: You always merge feature branch into develop branch</p></li>
</ul>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt><em>hotfix/<task-id>-<description></em>: When we are correcting an emergency incidence in production, we create a local branch with the prefix “hotfix/”, then only if there is a task id, we indicate it and we add a hyphen. The following we indicate a description according to the functionality that we are correcting. The words are separated by hyphens.</dt><dd><ul>
<li><p>Where does this branch emerge?: This branch always emerge from the master branch</p></li>
<li><p>When I finish the correction in my hotfix branch, which branch to merge into?: This branch always emerge from the master and develop branch</p></li>
</ul>
</dd>
</dl>
</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt>Steps to follow when you are creating or going to work on a branch of any kind (feature / fix / hotfix):</dt><dd><ol class="arabic simple">
<li><p>After you create your branch (feature / fix / hotfix) locally, upload it to the remote Git server. The integration system will verify your code from the outset.</p></li>
<li><p>Each time you commit, as much as possible, you send a push to the server. Each push will trigger the automated launch of the tests, etc.</p></li>
<li><p>Once the development is finished, having done a push to the remote Git server, and that the test phase has passed without problem, you create an <a class="reference external" href="https://help.github.com/articles/creating-a-pull-request/">pull request</a>.</p></li>
</ol>
</dd>
</dl>
</li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Do not forget to remove your branch (feature / fix / hotfix) once the merge has been made.</p>
</div>
<p>Some useful Git commands:</p>
<ul class="simple">
<li><p>git fetch –prune: Cleaning branches removed and bringing new branches</p></li>
</ul>
</section>
<section id="pep8">
<h2>PEP8!<a class="headerlink" href="#pep8" title="Link to this heading">¶</a></h2>
<p>It is really important to follow some standards when a team develops an application. If all team members format the code in the same format, then it is much easier to read the code. PEP8 is Python’s style guide. It’s a set of rules for how to format your Python code.</p>
<p>Some style rules:</p>
<ul class="simple">
<li><p>Package and module names: Modules should have short, <strong>all-lowercase</strong> names. Underscores can be used in the module name if it improves readability. Python packages should also have short, <strong>all-lowercase</strong> names, although the use of underscores is discouraged. In Python, a module is a file with the suffix ‘.py’.</p></li>
<li><p>Class names: Class names should normally use the <strong>CapWords</strong> convention.</p></li>
<li><p>Method names and instance variables: <strong>Lowercase with words separated by underscores</strong> as necessary to improve readability.</p></li>
</ul>
<p>There are many more style standards in PEP8 so, please, refer to <a class="reference external" href="https://www.python.org/dev/peps/pep-0008">PEP8 documentation</a>
. The most appropriate is to use an IDE that has support for PEP8. For example, <a class="reference external" href="https://www.jetbrains.com/pycharm/">PyCharm</a>.</p>
</section>
<section id="object-oriented-programming">
<h2>Object-oriented programming<a class="headerlink" href="#object-oriented-programming" title="Link to this heading">¶</a></h2>
<p><strong>Object-oriented programming should be the single programming paradigm used</strong>. Avoiding as far as possible, imperative and functional programming.</p>
<img alt="contributing/python_poo_programming.png" src="contributing/python_poo_programming.png" />
<img alt="contributing/python_functional_programming.png" src="contributing/python_functional_programming.png" />
<img alt="contributing/python_imperative_programming.png" src="contributing/python_imperative_programming.png" />
<p>In classes, we directly access the attributes, which are usually defined as public.</p>
<img alt="contributing/without_getter_setter.png" src="contributing/without_getter_setter.png" />
<p>Only when we want to <strong>implement additional logic in the accesses to the attributes</strong> we define getter/setter methods, but <strong>always by using the *property*</strong> annotation or the <strong>*property*</strong> function:</p>
<img alt="contributing/property_annotation.png" src="contributing/property_annotation.png" />
<img alt="contributing/property_functional.png" src="contributing/property_functional.png" />
<p>By using <strong>*property*</strong>, we continue to access the attributes directly:</p>
<img alt="contributing/good_access.png" src="contributing/good_access.png" />
<p>Do not use getter/setter methods without the <em>property</em> annotation or the <em>property</em> function:</p>
<img alt="contributing/with_getter_setter.png" src="contributing/with_getter_setter.png" />
<p>Since this way of accessing the attribute is not commonly used in Python:</p>
<img alt="contributing/bad_access.png" src="contributing/bad_access.png" />
</section>
<section id="structure">
<h2>Structure<a class="headerlink" href="#structure" title="Link to this heading">¶</a></h2>
<p>Python is not Java. In Java you cannot, by design, have more than one class in a file. In Python, you can do it.</p>
<p>In Python, <strong>it is appropriate to group several classes into a single .py file. For that reason, the .py files are called modules.</strong></p>
</section>
<section id="python-3-6">
<h2>Python 3.6<a class="headerlink" href="#python-3-6" title="Link to this heading">¶</a></h2>
<p>We <strong>always</strong> define types in the parameters of the arguments and the return value:</p>
<img alt="contributing/types_in_methods.png" src="contributing/types_in_methods.png" />
<p>We can define abstract classes (ABCs) in Python:</p>
<img alt="contributing/abstract.png" src="contributing/abstract.png" />
<p>In the case that we want to define an <strong>interface</strong> class, it is done in the same way. We just have to define all the methods of the class as abstract.</p>
<p>Example of use of generic types:</p>
<img alt="contributing/generic_types.png" src="contributing/generic_types.png" />
<p>In the code below, the IDE displays a <strong>warning</strong>, since although the 2nd parameter is a float type, which is a type allowed in the definition of the generic type X, it is not of the same type as the first, since the first 2 parameters must be of the same generic type (S):</p>
<img alt="contributing/instance_with_generic_types1_wearning.png" src="contributing/instance_with_generic_types1_wearning.png" />
<p>In the code below, the IDE displays a <strong>warning</strong>, since the 2nd parameter is a type not allowed in the definition of the generic type ( <em>TypeVar(‘S’, int, float)</em> ):</p>
<img alt="contributing/instance_with_generic_types2_wearning.png" src="contributing/instance_with_generic_types2_wearning.png" />
<p>When the class inherits from <em>Generic[…]</em>, the <strong>class is defined as generic</strong>. In this way we can indicate the types that will have the values of the generic types, when using the class as type. Look at the <em>add_car()</em> method of the <em>Parking</em> class.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The generic classes inherit from abc.ABCMeta, so they are abstract classes and <strong>abstract methods can be used</strong>.</p>
</div>
<img alt="contributing/generic_class1.png" src="contributing/generic_class1.png" />
<img alt="contributing/generic_class2.png" src="contributing/generic_class2.png" />
<p>In the code below, the IDE displays a <strong>warning</strong> in the call to the <em>add_car()</em> method when adding the car, since the 3rd parameter of the init must be a <em>str</em> type, as defined in the <em>add_car()</em> method of the <em>Parking</em> class.</p>
<img alt="contributing/instance_with_generic_class_wearning.png" src="contributing/instance_with_generic_class_wearning.png" />
<p>When inheriting from generic classes, some type variables could be fixed:</p>
<img alt="contributing/generic_types_fixed.png" src="contributing/generic_types_fixed.png" />
<p>Example of inheritance from non-generic class to generic class:</p>
<img alt="contributing/inheritance_non_generic_to_generic.png" src="contributing/inheritance_non_generic_to_generic.png" />
<p>Example of inheritance from generic class to another generic class:</p>
<img alt="contributing/inheritance_generic_to_generic.png" src="contributing/inheritance_generic_to_generic.png" />
</section>
<section id="create-automatic-documentation-files-with-sphinx">
<h2>Create automatic documentation files with Sphinx<a class="headerlink" href="#create-automatic-documentation-files-with-sphinx" title="Link to this heading">¶</a></h2>
<p>First, you need to know how to correctly document your code. It is <strong>important</strong> to follow these simple rules in order to automatically create good documentation for the project.</p>
<p>When you create a new module file (testDoc.py in this example), you should mention it using this format:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="sd">"""</span>
<span class="sd">.. module:: testDoc</span>
<span class="sd"> :platform: Unix, Windows</span>
<span class="sd"> :synopsis: A useful module indeed.</span>
<span class="sd">.. moduleauthor:: Andrew Carter <andrew@invalid.com></span>
<span class="sd">"""</span>
<span class="k">class</span> <span class="nc">testDoc</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""We use this as a public class example class.</span>
<span class="sd"> This class is ruled by the very trendy important method :func:`public_fn_with_sphinxy_docstring`.</span>
<span class="sd"> .. note::</span>
<span class="sd"> An example of intersphinx is this: you **cannot** use :mod:`pickle` on this class.</span>
<span class="sd"> """</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>This code snippet generates the following documentation:</p>
<img alt="contributing/class_header.png" src="contributing/class_header.png" />
<p>Now, you can document your methods using the following sintax:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">public_fn_with_sphinxy_docstring</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">state</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span>
<span class="w"> </span><span class="sd">"""This function does something.</span>
<span class="sd"> :param name: The name to use.</span>
<span class="sd"> :type name: str.</span>
<span class="sd"> :param state: Current state to be in.</span>
<span class="sd"> :type state: bool.</span>
<span class="sd"> :returns: int -- the return code.</span>
<span class="sd"> :raises: AttributeError, KeyError</span>
<span class="sd"> """</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">def</span> <span class="nf">public_fn_without_docstring</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">True</span>
</pre></div>
</div>
<p>And the produced output doc will be:</p>
<img alt="contributing/method_way_sphinx.png" src="contributing/method_way_sphinx.png" />
<p>As you may notice, if you don’t use any docstring, the method documentation will be empty.</p>
</section>
</section>
</div>
<div class="footer-relations">
<div class="float-left">
<a class="btn btn-outline btn-sm" href="api/problem/singleobjective.html" title="previous chapter (use the left arrow)">← Single-objective problems</a>
</div>
<div class="float-right">
<a class="btn btn-outline btn-sm" href="about.html" title="next chapter (use the right arrow)">About →</a>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="clearfix"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="about.html" title="About"
>next</a> |</li>
<li class="right" >
<a href="api/problem/singleobjective.html" title="Single-objective problems"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">jMetalPy 1.7.0 documentation</a> »</li>
<li class="nav-item nav-item-this"><a href="">Contributing</a></li>
</ul>
</div>
<script type="text/javascript">
$("#mobile-toggle a").click(function () {
$("#left-column").toggle();
});
</script>
<script type="text/javascript" src="_static/js/bootstrap.js"></script>
<div class="footer">
© Copyright 2019, Antonio Benítez-Hidalgo. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
</html>