Skip to content

GitHub Action formats our code with psf/black #1569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions .github/workflows/autoblack.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
# GitHub Action that uses Black to reformat the Python code in an incoming pull request.
# If all Python code in the pull request is complient with Black then this Action does nothing.
# Othewrwise, Black is run and its changes are committed back to the incoming pull request.
# GitHub Action that uses Black to reformat Python code (if needed) when doing a git push.
# If all Python code in the repo is complient with Black then this Action does nothing.
# Otherwise, Black is run and its changes are committed to the repo.
# https://github.com/cclauss/autoblack

name: autoblack
on: [pull_request]
name: autoblack_push
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
python-version: [3.7]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install psf/black
run: pip install black
- name: Run black --check .
run: black --check .
- name: If needed, commit black changes to the pull request
- uses: actions/setup-python@v1
- run: pip install black
- run: black --check .
- name: If needed, commit black changes to a new pull request
if: failure()
run: |
black .
git config --global user.name 'autoblack'
git config --global user.email 'cclauss@users.noreply.github.com'
git config --global user.name github-actions
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git checkout $GITHUB_HEAD_REF
git commit -am "fixup: Format Python code with psf/black"
git push
git commit -am "fixup! Format Python code with psf/black push"
git push --force origin HEAD:$GITHUB_REF
30 changes: 16 additions & 14 deletions ciphers/deterministic_miller_rabin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ def miller_rabin(n, allow_probable=False):
"A return value of True indicates a probable prime."
)
# array bounds provided by analysis
bounds = [2_047,
1_373_653,
25_326_001,
3_215_031_751,
2_152_302_898_747,
3_474_749_660_383,
341_550_071_728_321,
1,
3_825_123_056_546_413_051,
1,
1,
318_665_857_834_031_151_167_461,
3_317_044_064_679_887_385_961_981]
bounds = [
2_047,
1_373_653,
25_326_001,
3_215_031_751,
2_152_302_898_747,
3_474_749_660_383,
341_550_071_728_321,
1,
3_825_123_056_546_413_051,
1,
1,
318_665_857_834_031_151_167_461,
3_317_044_064_679_887_385_961_981,
]

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


if __name__ == '__main__':
if __name__ == "__main__":
test_miller_rabin()
15 changes: 7 additions & 8 deletions ciphers/diffie.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def find_primitive(n):
for r in range(1, n):
li = []
for x in range(n-1):
val = pow(r,x,n)
for x in range(n - 1):
val = pow(r, x, n)
if val in li:
break
li.append(val)
Expand All @@ -11,16 +11,15 @@ def find_primitive(n):


if __name__ == "__main__":
q = int(input('Enter a prime number q: '))
q = int(input("Enter a prime number q: "))
a = find_primitive(q)
a_private = int(input('Enter private key of A: '))
a_private = int(input("Enter private key of A: "))
a_public = pow(a, a_private, q)
b_private = int(input('Enter private key of B: '))
b_private = int(input("Enter private key of B: "))
b_public = pow(a, b_private, q)

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

print('The key value generated by A is: ', a_secret)
print('The key value generated by B is: ', b_secret)

print("The key value generated by A is: ", a_secret)
print("The key value generated by B is: ", b_secret)
4 changes: 2 additions & 2 deletions data_structures/binary_tree/basic_binary_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def display(tree): # In Order traversal of the tree


def depth_of_tree(
tree
tree,
): # This is the recursive function to find the depth of binary tree.
if tree is None:
return 0
Expand All @@ -36,7 +36,7 @@ def depth_of_tree(


def is_full_binary_tree(
tree
tree,
): # This functions returns that is it full binary tree or not?
if tree is None:
return True
Expand Down
1 change: 0 additions & 1 deletion data_structures/binary_tree/treap.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def main():
args = input()

print("good by!")



if __name__ == "__main__":
Expand Down
7 changes: 4 additions & 3 deletions data_structures/heap/min_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ def sift_down(self, idx, array):

if smallest != idx:
array[idx], array[smallest] = array[smallest], array[idx]
self.idx_of_element[array[idx]], self.idx_of_element[
array[smallest]
] = (
(
self.idx_of_element[array[idx]],
self.idx_of_element[array[smallest]],
) = (
self.idx_of_element[array[smallest]],
self.idx_of_element[array[idx]],
)
Expand Down
4 changes: 1 addition & 3 deletions data_structures/linked_list/doubly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def insertHead(self, x):
def deleteHead(self):
temp = self.head
self.head = self.head.next # oldHead <--> 2ndElement(head)
self.head.previous = (
None
) # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
if self.head is None:
self.tail = None # if empty linked list
return temp
Expand Down
5 changes: 2 additions & 3 deletions data_structures/linked_list/from_sequence.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Recursive Prorgam to create a Linked List from a sequence and
# print a string representation of it.


class Node:
def __init__(self, data=None):
self.data = data
Expand All @@ -17,7 +18,6 @@ def __repr__(self):
return string_rep



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



list_data = [1,3,5,32,44,12,43]
list_data = [1, 3, 5, 32, 44, 12, 43]
print(f"List: {list_data}")
print("Creating Linked List from List.")
linked_list = make_linked_list(list_data)
Expand Down
6 changes: 3 additions & 3 deletions data_structures/linked_list/print_reverse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Program to print the elements of a linked list in reverse


class Node:
def __init__(self, data=None):
self.data = data
Expand All @@ -16,7 +17,6 @@ def __repr__(self):
return string_rep



def make_linked_list(elements_list):
"""Creates a Linked List from the elements of the given sequence
(list/tuple) and returns the head of the Linked List."""
Expand All @@ -34,6 +34,7 @@ def make_linked_list(elements_list):
current = current.next
return head


def print_reverse(head_node):
"""Prints the elements of the given Linked List in reverse order"""

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



list_data = [14,52,14,12,43]
list_data = [14, 52, 14, 12, 43]
linked_list = make_linked_list(list_data)
print("Linked List:")
print(linked_list)
Expand Down
3 changes: 2 additions & 1 deletion dynamic_programming/longest_increasing_subsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def longest_subsequence(array: List[int]) -> List[int]: # This function is recu
return temp_array
else:
return longest_subseq


if __name__ == "__main__":
import doctest

doctest.testmod()
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#############################
from typing import List


def CeilIndex(v, l, r, key):
while r - l > 1:
m = (l + r) // 2
Expand Down Expand Up @@ -49,4 +50,5 @@ def LongestIncreasingSubsequenceLength(v: List[int]) -> int:

if __name__ == "__main__":
import doctest

doctest.testmod()
1 change: 1 addition & 0 deletions dynamic_programming/max_sub_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def max_sub_array(nums: List[int]) -> int:
import time
import matplotlib.pyplot as plt
from random import randint

inputs = [10, 100, 1000, 10000, 50000, 100000, 200000, 300000, 400000, 500000]
tim = []
for i in inputs:
Expand Down
4 changes: 2 additions & 2 deletions file_transfer/send_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import socket # Import socket module

ONE_CONNECTION_ONLY = (
True
) # Set this to False if you wish to continuously accept connections
True # Set this to False if you wish to continuously accept connections
)

filename = "mytext.txt"
port = 12312 # Reserve a port for your service.
Expand Down
6 changes: 4 additions & 2 deletions maths/ceil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ def ceil(x) -> int:
>>> 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))
True
"""
return x if isinstance(x, int) or x - int(x) == 0 else int(x + 1) if x > 0 else int(x)
return (
x if isinstance(x, int) or x - int(x) == 0 else int(x + 1) if x > 0 else int(x)
)


if __name__ == '__main__':
if __name__ == "__main__":
import doctest

doctest.testmod()
2 changes: 1 addition & 1 deletion maths/factorial_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def factorial(input_number: int) -> int:
return result


if __name__ == '__main__':
if __name__ == "__main__":
import doctest

doctest.testmod()
2 changes: 1 addition & 1 deletion maths/factorial_recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def factorial(n: int) -> int:
return 1 if n == 0 or n == 1 else n * factorial(n - 1)


if __name__ == '__main__':
if __name__ == "__main__":
import doctest

doctest.testmod()
6 changes: 4 additions & 2 deletions maths/floor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ def floor(x) -> int:
>>> 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))
True
"""
return x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
return (
x if isinstance(x, int) or x - int(x) == 0 else int(x) if x > 0 else int(x - 1)
)


if __name__ == '__main__':
if __name__ == "__main__":
import doctest

doctest.testmod()
2 changes: 1 addition & 1 deletion maths/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
>>> gaussian(2523, mu=234234, sigma=3425)
0.0
"""
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-(x - mu) ** 2 / 2 * sigma ** 2)
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-((x - mu) ** 2) / 2 * sigma ** 2)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion maths/perfect_square.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def perfect_square(num: int) -> bool:
return math.sqrt(num) * math.sqrt(num) == num


if __name__ == '__main__':
if __name__ == "__main__":
import doctest

doctest.testmod()
Loading