You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+72-43Lines changed: 72 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,10 @@ Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Befo
10
10
11
11
We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that:
12
12
13
-
-your did your work - no plagiarism allowed
13
+
-You did your work - no plagiarism allowed
14
14
- Any plagiarized work will not be merged.
15
-
-your work will be distributed under [MIT License](License) once your pull request is merged
16
-
-you submitted work fulfils or mostly fulfils our styles and standards
15
+
-Your work will be distributed under [MIT License](License) once your pull request is merged
16
+
-You submitted work fulfils or mostly fulfils our styles and standards
17
17
18
18
**New implementation** is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity.
19
19
@@ -23,19 +23,38 @@ We are very happy that you consider implementing algorithms and data structure f
23
23
24
24
We appreciate any contribution, from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work.
25
25
26
+
Your contribution will be tested by our [automated testing on Travis CI](https://travis-ci.org/TheAlgorithms/Python/pull_requests) to save time and mental energy. After you have submitted your pull request, you should see the Travis tests start to run at the bottom of your submission page. If those tests fail, then click on the ___details___ button try to read through the Travis output to understand the failure. If you do not understand, please leave a comment on your submission page and a community member will try to help.
27
+
26
28
#### Coding Style
27
29
28
30
We want your work to be readable by others; therefore, we encourage you to note the following:
29
31
30
-
- Please write in Python 3.x.
32
+
- Please write in Python 3.7+. __print()__ is a function in Python 3 so __print "Hello"__ will _not_ work but __print("Hello")__ will.
33
+
34
+
- Please focus hard on naming of functions, classes, and variables. Help your reader by using __descriptive names__ that can help you to remove redundant comments.
35
+
- Single letter variable names are _old school_ so please avoid them unless their life only spans a few lines.
36
+
- Expand acronyms because __gcd()__ is hard to understand but __greatest_common_divisor()__ is not.
37
+
- Please follow the [Python Naming Conventions](https://pep8.org/#prescriptive-naming-conventions) so variable_names and function_names should be lower_case, CONSTANTS in UPPERCASE, ClassNames should be CamelCase, etc.
38
+
39
+
- We encourage the use of Python [f-strings](https://realpython.com/python-f-strings/#f-strings-a-new-and-improved-way-to-format-strings-in-python) where the make the code easier to read.
31
40
32
-
- If you know [PEP 8](https://www.python.org/dev/peps/pep-0008/) already, you will have no problem in coding style, though we do not follow it strictly. Read the remaining section and have fun coding!
41
+
- Please consider running [__psf/black__](https://github.com/python/black) on your Python file(s) before submitting your pull request. This is not yet a requirement but it does make your code more readable and automatically aligns it with much of [PEP 8](https://www.python.org/dev/peps/pep-0008/). There are other code formatters (autopep8, yapf) but the __black__ style is now the recommendation of the Python Core Team. To use it,
42
+
```bash
43
+
pip3 install black # only required the first time
44
+
black .
45
+
```
33
46
34
-
- Always use 4 spaces to indent.
47
+
- All submissions will need to pass the test __flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics__ before they will be accepted so if possible, try this test locally on your Python file(s) before submitting your pull request.
48
+
```bash
49
+
pip3 install flake8 # only required the first time
- Original code submission requires comments to describe your work.
53
+
- Original code submission require docstrings or comments to describe your work.
37
54
38
-
- More on comments and docstrings:
55
+
- More on docstrings and comments:
56
+
57
+
If you are using a Uncyclopedia article or some other source material to create your algorithm, please add the URL in a docstring or comment to help your reader.
39
58
40
59
The following are considered to be bad and may be requested to be improved:
41
60
@@ -45,80 +64,90 @@ We want your work to be readable by others; therefore, we encourage you to note
45
64
46
65
This is too trivial. Comments are expected to be explanatory. For comments, you can write them above, on or below a line of code, as long as you are consistent within the same piece of code.
47
66
48
-
*Sometimes, docstrings are avoided.* This will happen if you are using some editors and not careful with indentation:
67
+
We encourage you to put docstrings inside your functions but please pay attention to indentation of docstrings. The following is acceptable in this case:
49
68
50
69
```python
70
+
def sumab(a, b):
71
+
"""
72
+
This function returns the sum of two integers a and b
73
+
Return: a + b
51
74
"""
52
-
This function sums a and b
53
-
"""
54
-
defsum(a, b):
55
75
return a + b
56
76
```
57
77
58
-
However, if you insist to use docstrings, we encourage you to put docstrings inside functions. Also, please pay attention to indentation to docstrings. The following is acceptable in this case:
78
+
- Write tests (especially [__doctests__](https://docs.python.org/3/library/doctest.html)) to illustrate and verify your work. We highly encourage the use of _doctests on all functions_.
59
79
60
80
```python
61
81
def sumab(a, b):
62
82
"""
63
-
This function sums two integers a and b
64
-
Return: a + b
65
-
"""
83
+
This function returns the sum of two integers a and b
84
+
Return: a + b
85
+
>>> sum(2, 2)
86
+
4
87
+
>>> sum(-2, 3)
88
+
1
89
+
>>> sum(4.9, 6.1)
90
+
10.0
91
+
"""
66
92
return a + b
67
93
```
68
94
69
-
-`lambda`, `map`, `filter`, `reduce` and complicated list comprehension are welcome and acceptable to demonstrate the power of Python, as long as they are simple enough to read.
70
-
71
-
- This is arguable: **write comments** and assign appropriate variable names, so that the code is easy to read!
72
-
73
-
- Write tests to illustrate your work.
95
+
These doctests will be run by pytest as part of our automated testing so please try to run your doctests locally and make sure that they are found and pass:
96
+
```bash
97
+
python3 -m doctest -v my_submission.py
98
+
```
74
99
75
-
The following "testing" approaches are not encouraged:
100
+
The use of the Python builtin__input()__ functionis**not** encouraged:
76
101
77
102
```python
78
-
input('Enter your input:')
103
+
input('Enter your input:')
79
104
# Or even worse...
80
-
input=eval(raw_input("Enter your input: "))
105
+
input = eval(input("Enter your input: "))
81
106
```
82
107
83
-
Please write down your test case, like the following:
108
+
However, ifyour code uses __input()__ then we encourage you to gracefully deal with leading and trailing whitespace in user input by adding __.strip()__ as in:
84
109
85
110
```python
86
-
defsumab(a, b):
87
-
return a + b
88
-
# Write tests this way:
89
-
print(sumab(1,2)) # 1+2 = 3
90
-
print(sumab(6,4)) # 6+4 = 10
91
-
# Or this way:
92
-
print("1 + 2 = ", sumab(1,2)) # 1+2 = 3
93
-
print("6 + 4 = ", sumab(6,4)) # 6+4 = 10
111
+
starting_value = int(input("Please enter a starting value: ").strip())
94
112
```
113
+
114
+
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged forfunctionparameters and return values. Our automated testing will run [mypy](http://mypy-lang.org) so run that locally before making your submission.
115
+
```python
116
+
def sumab(a: int, b: int) --> int:
117
+
pass
118
+
```
119
+
120
+
- [__list comprehensions and generators__](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) are preferred over the use of `lambda`, `map`, `filter`, `reduce` but the important thing is to demonstrate the power of Python in code that is easy to read and maintain.
95
121
96
-
- Avoid importing external libraries for basic algorithms. Use those libraries for complicated algorithms.
122
+
- Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms.
123
+
124
+
- If you need a third party module that is not in the file __requirements.txt__, please add it to that file as part of your submission.
97
125
98
126
#### Other Standard While Submitting Your Work
99
127
100
-
- File extension for code should be `.py`.
128
+
- File extension forcode should be `.py`. Jupiter notebook files are acceptablein machine learning algorithms.
101
129
102
-
- Please file your work to let others use it in the future. Here are the examples that are acceptable:
130
+
- Please avoid creating new directories if at all possible. Try to fit your work into the existing directory structue.
103
131
104
-
- Camel cases
105
-
-`-` Hyphenated names
106
-
-`_` Underscore-separated names
132
+
- Strictly use snake_case (underscore_separated) in your file_name, as it will be easy to parse in future using scripts.
107
133
108
134
If possible, follow the standard *within* the folder you are submitting to.
109
135
110
136
- If you have modified/added code work, make sure the code compiles before submitting.
111
137
112
-
- If you have modified/added documentation work, make sure your language is concise and contains no grammar mistake.
138
+
- If you have modified/added documentation work, ensure your language is concise and contains no grammar errors.
139
+
140
+
- Do not update the README.md or DIRECTORY.md file which will be periodically autogenerated by our Travis CI processes.
113
141
114
142
- Add a corresponding explanation to [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation) (Optional but recommended).
115
143
144
+
- All submissions will be tested with [__mypy__](http://www.mypy-lang.org) so we encourage to add [__Python type hints__](https://docs.python.org/3/library/typing.html) where it makes sense to do so.
145
+
116
146
- Most importantly,
117
147
118
-
-**be consistent with this guidelines while submitting.**
0 commit comments