Skip to content

Commit f6e2864

Browse files
Merge pull request #1 from TheAlgorithms/master
Updated my fork repo
2 parents 4617aa7 + 9eb50cc commit f6e2864

File tree

419 files changed

+16397
-15744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

419 files changed

+16397
-15744
lines changed

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[report]
2+
sort = Cover
3+
omit =
4+
.env/*

.github/workflows/autoblack.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# GitHub Action that uses Black to reformat Python code (if needed) when doing a git push.
2+
# If all Python code in the repo is compliant with Black then this Action does nothing.
3+
# Otherwise, Black is run and its changes are committed to the repo.
4+
# https://github.com/cclauss/autoblack
5+
6+
name: autoblack_push
7+
on: [push]
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v1
13+
- uses: actions/setup-python@v1
14+
- run: pip install black
15+
- run: black --check .
16+
- name: If needed, commit black changes to a new pull request
17+
if: failure()
18+
run: |
19+
black .
20+
git config --global user.name github-actions
21+
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
22+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
23+
git commit -am "fixup! Format Python code with psf/black push"
24+
git push --force origin HEAD:$GITHUB_REF
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The objective of this GitHub Action is to update the DIRECTORY.md file (if needed)
2+
# when doing a git push
3+
name: directory_writer
4+
on: [push]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
- uses: actions/setup-python@v1
11+
with:
12+
python-version: 3.x
13+
- name: Update DIRECTORY.md
14+
run: |
15+
scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md
16+
git config --global user.name github-actions
17+
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
18+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
19+
git commit -am "updating DIRECTORY.md" || true
20+
git push --force origin HEAD:$GITHUB_REF || true

.github/workflows/stale.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Mark stale issues and pull requests
2+
on:
3+
schedule:
4+
- cron: "0 0 * * *"
5+
jobs:
6+
stale:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/stale@v1
10+
with:
11+
repo-token: ${{ secrets.GITHUB_TOKEN }}
12+
stale-issue-message: 'Stale issue message'
13+
stale-pr-message: 'Stale pull request message'
14+
stale-issue-label: 'no-issue-activity'
15+
stale-pr-label: 'no-pr-activity'

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
language: python
2-
dist: xenial # required for Python >= 3.7
32
python: 3.7
43
cache: pip
54
before_install: pip install --upgrade pip setuptools
65
install: pip install -r requirements.txt
76
before_script:
87
- black --check . || true
9-
- flake8 . --count --select=E9,F4,F63,F7,F82 --show-source --statistics
8+
- flake8 . --count --select=E101,E9,F4,F63,F7,F82,W191 --show-source --statistics
109
script:
1110
- scripts/validate_filenames.py # no uppercase, no spaces, in a directory
1211
- mypy --ignore-missing-imports .
13-
- pytest . --doctest-modules
12+
- pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=. .
1413
after_success:
15-
- scripts/build_directory_md.py > DIRECTORY.md
16-
- cat DIRECTORY.md
14+
- scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md

CONTRIBUTING.md

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,45 @@ We are very happy that you consider implementing algorithms and data structure f
2323

2424
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.
2525

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+
2628
#### Coding Style
2729

2830
We want your work to be readable by others; therefore, we encourage you to note the following:
2931

30-
- Please write in Python 3.x.
31-
- Please consider running [__python/black__](https://github.com/python/black) on your Python file(s) before submitting your pull request. This is not a requirement but it does make your code more readable. There are other code formatters (autopep8, yapf) but the __black__ style is now the recommendation of the Python core team. To use it,
32-
```bash
33-
pip3 install black # only required the first time
34-
black my-submission.py
35-
```
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+
- 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.
34+
- Single letter variable names are _old school_ so please avoid them unless their life only spans a few lines.
35+
- Expand acronyms because __gcd()__ is hard to understand but __greatest_common_divisor()__ is not.
36+
- 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.
37+
38+
39+
40+
- 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.
41+
42+
43+
44+
- 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,
45+
46+
```bash
47+
pip3 install black # only required the first time
48+
black .
49+
```
3650

3751
- 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.
3852

39-
- 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!
53+
```bash
54+
pip3 install flake8 # only required the first time
55+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
56+
```
57+
58+
4059

41-
- Always use 4 spaces to indent.
60+
- Original code submission require docstrings or comments to describe your work.
4261

43-
- Original code submission requires comments to describe your work.
62+
- More on docstrings and comments:
4463

45-
- More on comments and docstrings:
64+
If you are using a Wikipedia article or some other source material to create your algorithm, please add the URL in a docstring or comment to help your reader.
4665

4766
The following are considered to be bad and may be requested to be improved:
4867

@@ -52,88 +71,90 @@ We want your work to be readable by others; therefore, we encourage you to note
5271

5372
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.
5473

55-
*Sometimes, docstrings are avoided.* This will happen if you are using some editors and not careful with indentation:
74+
We encourage you to put docstrings inside your functions but please pay attention to indentation of docstrings. The following is acceptable in this case:
5675

5776
```python
77+
def sumab(a, b):
78+
"""
79+
This function returns the sum of two integers a and b
80+
Return: a + b
5881
"""
59-
This function sums a and b
60-
"""
61-
def sum(a, b):
6282
return a + b
6383
```
6484

65-
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:
85+
- 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_.
6686

6787
```python
6888
def sumab(a, b):
6989
"""
70-
This function sums two integers a and b
71-
Return: a + b
90+
This function returns the sum of two integers a and b
91+
Return: a + b
92+
>>> sumab(2, 2)
93+
4
94+
>>> sumab(-2, 3)
95+
1
96+
>>> sumab(4.9, 5.1)
97+
10.0
7298
"""
7399
return a + b
74100
```
75101

76-
- `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.
102+
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:
77103

78-
- This is arguable: **write comments** and assign appropriate variable names, so that the code is easy to read!
79-
80-
- Write tests to illustrate your work.
104+
```bash
105+
python3 -m doctest -v my_submission.py
106+
```
81107

82-
The following "testing" approaches are **not** encouraged:
108+
The use of the Python builtin __input()__ function is **not** encouraged:
83109

84110
```python
85111
input('Enter your input:')
86112
# Or even worse...
87113
input = eval(input("Enter your input: "))
88114
```
89115

90-
However, if your code uses __input()__ then we encourage you to gracefully deal with leading and trailing whitespace in user input by adding __.strip()__ to the end as in:
116+
However, if your code uses __input()__ then we encourage you to gracefully deal with leading and trailing whitespace in user input by adding __.strip()__ as in:
91117

92118
```python
93119
starting_value = int(input("Please enter a starting value: ").strip())
94120
```
95121

96-
Please write down your test case, like the following:
122+
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](http://mypy-lang.org) so run that locally before making your submission.
97123

98124
```python
99-
def sumab(a, b):
100-
return a + b
101-
# Write tests this way:
102-
print(sumab(1, 2)) # 1+2 = 3
103-
print(sumab(6, 4)) # 6+4 = 10
104-
# Or this way:
105-
print("1 + 2 = ", sumab(1, 2)) # 1+2 = 3
106-
print("6 + 4 = ", sumab(6, 4)) # 6+4 = 10
125+
def sumab(a: int, b: int) --> int:
126+
pass
107127
```
108128

109-
Better yet, if you know how to write [__doctests__](https://docs.python.org/3/library/doctest.html), please consider adding them.
129+
130+
131+
- [__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.
132+
133+
110134

111135
- Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms.
136+
- 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.
112137

113138
#### Other Standard While Submitting Your Work
114139

115140
- File extension for code should be `.py`. Jupiter notebook files are acceptable in machine learning algorithms.
141+
- Strictly use snake_case (underscore_separated) in your file_name, as it will be easy to parse in future using scripts.
142+
- Please avoid creating new directories if at all possible. Try to fit your work into the existing directory structure.
143+
- If possible, follow the standard *within* the folder you are submitting to.
116144

117-
- Strictly use snake case (underscore separated) in your file name, as it will be easy to parse in future using scripts.
118145

119-
If possible, follow the standard *within* the folder you are submitting to.
120146

121147
- If you have modified/added code work, make sure the code compiles before submitting.
122-
123148
- If you have modified/added documentation work, ensure your language is concise and contains no grammar errors.
124-
125149
- Do not update the README.md or DIRECTORY.md file which will be periodically autogenerated by our Travis CI processes.
126-
127150
- Add a corresponding explanation to [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation) (Optional but recommended).
128-
129151
- 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.
130152

131-
- Most importantly,
132153

154+
155+
- Most importantly,
133156
- **Be consistent in the use of these guidelines when submitting.**
134157
- **Join** [Gitter](https://gitter.im/TheAlgorithms) **now!**
135158
- Happy coding!
136159

137-
138-
139160
Writer [@poyea](https://github.com/poyea), Jun 2019.

0 commit comments

Comments
 (0)