Skip to content

Commit 5df8aec

Browse files
authored
GitHub Action formats our code with psf/black (TheAlgorithms#1569)
* GitHub Action formats our code with psf/black @poyea Your review please. * fixup! Format Python code with psf/black push
1 parent 52cf668 commit 5df8aec

25 files changed

+543
-420
lines changed

.github/workflows/autoblack.yml

+13-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
1-
# GitHub Action that uses Black to reformat the Python code in an incoming pull request.
2-
# If all Python code in the pull request is complient with Black then this Action does nothing.
3-
# Othewrwise, Black is run and its changes are committed back to the incoming pull request.
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 complient with Black then this Action does nothing.
3+
# Otherwise, Black is run and its changes are committed to the repo.
44
# https://github.com/cclauss/autoblack
55

6-
name: autoblack
7-
on: [pull_request]
6+
name: autoblack_push
7+
on: [push]
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11-
strategy:
12-
max-parallel: 1
13-
matrix:
14-
python-version: [3.7]
1511
steps:
1612
- uses: actions/checkout@v1
17-
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v1
19-
with:
20-
python-version: ${{ matrix.python-version }}
21-
- name: Install psf/black
22-
run: pip install black
23-
- name: Run black --check .
24-
run: black --check .
25-
- name: If needed, commit black changes to the pull request
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
2617
if: failure()
2718
run: |
2819
black .
29-
git config --global user.name 'autoblack'
30-
git config --global user.email 'cclauss@users.noreply.github.com'
20+
git config --global user.name github-actions
21+
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
3122
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
32-
git checkout $GITHUB_HEAD_REF
33-
git commit -am "fixup: Format Python code with psf/black"
34-
git push
23+
git commit -am "fixup! Format Python code with psf/black push"
24+
git push --force origin HEAD:$GITHUB_REF

ciphers/deterministic_miller_rabin.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,21 @@ def miller_rabin(n, allow_probable=False):
4141
"A return value of True indicates a probable prime."
4242
)
4343
# array bounds provided by analysis
44-
bounds = [2_047,
45-
1_373_653,
46-
25_326_001,
47-
3_215_031_751,
48-
2_152_302_898_747,
49-
3_474_749_660_383,
50-
341_550_071_728_321,
51-
1,
52-
3_825_123_056_546_413_051,
53-
1,
54-
1,
55-
318_665_857_834_031_151_167_461,
56-
3_317_044_064_679_887_385_961_981]
44+
bounds = [
45+
2_047,
46+
1_373_653,
47+
25_326_001,
48+
3_215_031_751,
49+
2_152_302_898_747,
50+
3_474_749_660_383,
51+
341_550_071_728_321,
52+
1,
53+
3_825_123_056_546_413_051,
54+
1,
55+
1,
56+
318_665_857_834_031_151_167_461,
57+
3_317_044_064_679_887_385_961_981,
58+
]
5759

5860
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
5961
for idx, _p in enumerate(bounds, 1):
@@ -131,5 +133,5 @@ def test_miller_rabin():
131133
# upper limit for probabilistic test
132134

133135

134-
if __name__ == '__main__':
136+
if __name__ == "__main__":
135137
test_miller_rabin()

ciphers/diffie.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
def find_primitive(n):
22
for r in range(1, n):
33
li = []
4-
for x in range(n-1):
5-
val = pow(r,x,n)
4+
for x in range(n - 1):
5+
val = pow(r, x, n)
66
if val in li:
77
break
88
li.append(val)
@@ -11,16 +11,15 @@ def find_primitive(n):
1111

1212

1313
if __name__ == "__main__":
14-
q = int(input('Enter a prime number q: '))
14+
q = int(input("Enter a prime number q: "))
1515
a = find_primitive(q)
16-
a_private = int(input('Enter private key of A: '))
16+
a_private = int(input("Enter private key of A: "))
1717
a_public = pow(a, a_private, q)
18-
b_private = int(input('Enter private key of B: '))
18+
b_private = int(input("Enter private key of B: "))
1919
b_public = pow(a, b_private, q)
2020

2121
a_secret = pow(b_public, a_private, q)
2222
b_secret = pow(a_public, b_private, q)
2323

24-
print('The key value generated by A is: ', a_secret)
25-
print('The key value generated by B is: ', b_secret)
26-
24+
print("The key value generated by A is: ", a_secret)
25+
print("The key value generated by B is: ", b_secret)

data_structures/binary_tree/basic_binary_tree.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def display(tree): # In Order traversal of the tree
2222

2323

2424
def depth_of_tree(
25-
tree
25+
tree,
2626
): # This is the recursive function to find the depth of binary tree.
2727
if tree is None:
2828
return 0
@@ -36,7 +36,7 @@ def depth_of_tree(
3636

3737

3838
def is_full_binary_tree(
39-
tree
39+
tree,
4040
): # This functions returns that is it full binary tree or not?
4141
if tree is None:
4242
return True

data_structures/binary_tree/treap.py

-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def main():
172172
args = input()
173173

174174
print("good by!")
175-
176175

177176

178177
if __name__ == "__main__":

data_structures/heap/min_heap.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ def sift_down(self, idx, array):
7777

7878
if smallest != idx:
7979
array[idx], array[smallest] = array[smallest], array[idx]
80-
self.idx_of_element[array[idx]], self.idx_of_element[
81-
array[smallest]
82-
] = (
80+
(
81+
self.idx_of_element[array[idx]],
82+
self.idx_of_element[array[smallest]],
83+
) = (
8384
self.idx_of_element[array[smallest]],
8485
self.idx_of_element[array[idx]],
8586
)

data_structures/linked_list/doubly_linked_list.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def insertHead(self, x):
2323
def deleteHead(self):
2424
temp = self.head
2525
self.head = self.head.next # oldHead <--> 2ndElement(head)
26-
self.head.previous = (
27-
None
28-
) # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
26+
self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
2927
if self.head is None:
3028
self.tail = None # if empty linked list
3129
return temp

data_structures/linked_list/from_sequence.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Recursive Prorgam to create a Linked List from a sequence and
22
# print a string representation of it.
33

4+
45
class Node:
56
def __init__(self, data=None):
67
self.data = data
@@ -17,7 +18,6 @@ def __repr__(self):
1718
return string_rep
1819

1920

20-
2121
def make_linked_list(elements_list):
2222
"""Creates a Linked List from the elements of the given sequence
2323
(list/tuple) and returns the head of the Linked List."""
@@ -36,8 +36,7 @@ def make_linked_list(elements_list):
3636
return head
3737

3838

39-
40-
list_data = [1,3,5,32,44,12,43]
39+
list_data = [1, 3, 5, 32, 44, 12, 43]
4140
print(f"List: {list_data}")
4241
print("Creating Linked List from List.")
4342
linked_list = make_linked_list(list_data)

data_structures/linked_list/print_reverse.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Program to print the elements of a linked list in reverse
22

3+
34
class Node:
45
def __init__(self, data=None):
56
self.data = data
@@ -16,7 +17,6 @@ def __repr__(self):
1617
return string_rep
1718

1819

19-
2020
def make_linked_list(elements_list):
2121
"""Creates a Linked List from the elements of the given sequence
2222
(list/tuple) and returns the head of the Linked List."""
@@ -34,6 +34,7 @@ def make_linked_list(elements_list):
3434
current = current.next
3535
return head
3636

37+
3738
def print_reverse(head_node):
3839
"""Prints the elements of the given Linked List in reverse order"""
3940

@@ -46,8 +47,7 @@ def print_reverse(head_node):
4647
print(head_node.data)
4748

4849

49-
50-
list_data = [14,52,14,12,43]
50+
list_data = [14, 52, 14, 12, 43]
5151
linked_list = make_linked_list(list_data)
5252
print("Linked List:")
5353
print(linked_list)

dynamic_programming/longest_increasing_subsequence.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ def longest_subsequence(array: List[int]) -> List[int]: # This function is recu
4848
return temp_array
4949
else:
5050
return longest_subseq
51-
51+
5252

5353
if __name__ == "__main__":
5454
import doctest
55+
5556
doctest.testmod()

dynamic_programming/longest_increasing_subsequence_o(nlogn).py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#############################
77
from typing import List
88

9+
910
def CeilIndex(v, l, r, key):
1011
while r - l > 1:
1112
m = (l + r) // 2
@@ -49,4 +50,5 @@ def LongestIncreasingSubsequenceLength(v: List[int]) -> int:
4950

5051
if __name__ == "__main__":
5152
import doctest
53+
5254
doctest.testmod()

dynamic_programming/max_sub_array.py

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def max_sub_array(nums: List[int]) -> int:
7575
import time
7676
import matplotlib.pyplot as plt
7777
from random import randint
78+
7879
inputs = [10, 100, 1000, 10000, 50000, 100000, 200000, 300000, 400000, 500000]
7980
tim = []
8081
for i in inputs:

file_transfer/send_file.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import socket # Import socket module
33

44
ONE_CONNECTION_ONLY = (
5-
True
6-
) # Set this to False if you wish to continuously accept connections
5+
True # Set this to False if you wish to continuously accept connections
6+
)
77

88
filename = "mytext.txt"
99
port = 12312 # Reserve a port for your service.

maths/ceil.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ def ceil(x) -> int:
99
>>> all(ceil(n) == math.ceil(n) for n in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
1010
True
1111
"""
12-
return x if isinstance(x, int) or x - int(x) == 0 else int(x + 1) if x > 0 else int(x)
12+
return (
13+
x if isinstance(x, int) or x - int(x) == 0 else int(x + 1) if x > 0 else int(x)
14+
)
1315

1416

15-
if __name__ == '__main__':
17+
if __name__ == "__main__":
1618
import doctest
1719

1820
doctest.testmod()

maths/factorial_python.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def factorial(input_number: int) -> int:
2828
return result
2929

3030

31-
if __name__ == '__main__':
31+
if __name__ == "__main__":
3232
import doctest
3333

3434
doctest.testmod()

maths/factorial_recursive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def factorial(n: int) -> int:
2424
return 1 if n == 0 or n == 1 else n * factorial(n - 1)
2525

2626

27-
if __name__ == '__main__':
27+
if __name__ == "__main__":
2828
import doctest
2929

3030
doctest.testmod()

maths/floor.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ def floor(x) -> int:
99
>>> all(floor(n) == math.floor(n) for n in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000))
1010
True
1111
"""
12-
return x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
12+
return (
13+
x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
14+
)
1315

1416

15-
if __name__ == '__main__':
17+
if __name__ == "__main__":
1618
import doctest
1719

1820
doctest.testmod()

maths/gaussian.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
5050
>>> gaussian(2523, mu=234234, sigma=3425)
5151
0.0
5252
"""
53-
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-(x - mu) ** 2 / 2 * sigma ** 2)
53+
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-((x - mu) ** 2) / 2 * sigma ** 2)
5454

5555

5656
if __name__ == "__main__":

maths/perfect_square.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def perfect_square(num: int) -> bool:
2121
return math.sqrt(num) * math.sqrt(num) == num
2222

2323

24-
if __name__ == '__main__':
24+
if __name__ == "__main__":
2525
import doctest
2626

2727
doctest.testmod()

0 commit comments

Comments
 (0)