From 9016fe192fdd3121b6cb20eafeed2dd9154848eb Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 29 Sep 2020 03:11:04 +0530 Subject: [PATCH] Fix imports for all namespace packages (#2506) * Fix imports as they're namespace packages * Fix import for scripts/validate_filenames.py * Fix path in doctest --- ciphers/affine_cipher.py | 2 +- ciphers/elgamal_key_generator.py | 4 ++-- ciphers/rsa_cipher.py | 2 +- ciphers/rsa_key_generator.py | 4 ++-- ciphers/transposition_cipher_encrypt_decrypt_file.py | 2 +- data_structures/hashing/double_hash.py | 4 ++-- data_structures/hashing/hash_table.py | 2 +- data_structures/hashing/hash_table_with_linked_list.py | 2 +- data_structures/hashing/quadratic_probing.py | 2 +- data_structures/linked_list/deque_doubly.py | 4 ++-- data_structures/queue/circular_queue.py | 6 +++--- data_structures/queue/priority_queue_using_list.py | 4 ++-- geodesy/lamberts_ellipsoidal_distance.py | 2 +- greedy_method/test_knapsack.py | 2 +- linear_algebra/src/test_linear_algebra.py | 2 +- scripts/validate_filenames.py | 5 ++++- searches/simulated_annealing.py | 2 +- 17 files changed, 27 insertions(+), 24 deletions(-) diff --git a/ciphers/affine_cipher.py b/ciphers/affine_cipher.py index 5d77cfef3..70e695de5 100644 --- a/ciphers/affine_cipher.py +++ b/ciphers/affine_cipher.py @@ -1,7 +1,7 @@ import random import sys -import cryptomath_module as cryptomath +from . import cryptomath_module as cryptomath SYMBOLS = ( r""" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`""" diff --git a/ciphers/elgamal_key_generator.py b/ciphers/elgamal_key_generator.py index 1b387751b..5848e7e70 100644 --- a/ciphers/elgamal_key_generator.py +++ b/ciphers/elgamal_key_generator.py @@ -2,8 +2,8 @@ import os import random import sys -import cryptomath_module as cryptoMath -import rabin_miller as rabinMiller +from . import cryptomath_module as cryptoMath +from . import rabin_miller as rabinMiller min_primitive_root = 3 diff --git a/ciphers/rsa_cipher.py b/ciphers/rsa_cipher.py index 371966b83..fad0d6e60 100644 --- a/ciphers/rsa_cipher.py +++ b/ciphers/rsa_cipher.py @@ -1,7 +1,7 @@ import os import sys -import rsa_key_generator as rkg +from . import rsa_key_generator as rkg DEFAULT_BLOCK_SIZE = 128 BYTE_SIZE = 256 diff --git a/ciphers/rsa_key_generator.py b/ciphers/rsa_key_generator.py index 5514c6991..315928d4b 100644 --- a/ciphers/rsa_key_generator.py +++ b/ciphers/rsa_key_generator.py @@ -2,8 +2,8 @@ import os import random import sys -import cryptomath_module as cryptoMath -import rabin_miller as rabinMiller +from . import cryptomath_module as cryptoMath +from . import rabin_miller as rabinMiller def main(): diff --git a/ciphers/transposition_cipher_encrypt_decrypt_file.py b/ciphers/transposition_cipher_encrypt_decrypt_file.py index 71e7c4608..45aab0561 100644 --- a/ciphers/transposition_cipher_encrypt_decrypt_file.py +++ b/ciphers/transposition_cipher_encrypt_decrypt_file.py @@ -2,7 +2,7 @@ import os import sys import time -import transposition_cipher as transCipher +from . import transposition_cipher as transCipher def main(): diff --git a/data_structures/hashing/double_hash.py b/data_structures/hashing/double_hash.py index 1007849c5..57b1ffff4 100644 --- a/data_structures/hashing/double_hash.py +++ b/data_structures/hashing/double_hash.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -from hash_table import HashTable -from number_theory.prime_numbers import check_prime, next_prime +from .hash_table import HashTable +from .number_theory.prime_numbers import check_prime, next_prime class DoubleHash(HashTable): diff --git a/data_structures/hashing/hash_table.py b/data_structures/hashing/hash_table.py index 6e03be95b..fd9e6eec1 100644 --- a/data_structures/hashing/hash_table.py +++ b/data_structures/hashing/hash_table.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from number_theory.prime_numbers import next_prime +from .number_theory.prime_numbers import next_prime class HashTable: diff --git a/data_structures/hashing/hash_table_with_linked_list.py b/data_structures/hashing/hash_table_with_linked_list.py index 94934e37b..fe838268f 100644 --- a/data_structures/hashing/hash_table_with_linked_list.py +++ b/data_structures/hashing/hash_table_with_linked_list.py @@ -1,6 +1,6 @@ from collections import deque -from hash_table import HashTable +from .hash_table import HashTable class HashTableWithLinkedList(HashTable): diff --git a/data_structures/hashing/quadratic_probing.py b/data_structures/hashing/quadratic_probing.py index 06f3ced49..0930340a3 100644 --- a/data_structures/hashing/quadratic_probing.py +++ b/data_structures/hashing/quadratic_probing.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -from hash_table import HashTable +from .hash_table import HashTable class QuadraticProbing(HashTable): diff --git a/data_structures/linked_list/deque_doubly.py b/data_structures/linked_list/deque_doubly.py index c6ee2ed27..b93fb8c40 100644 --- a/data_structures/linked_list/deque_doubly.py +++ b/data_structures/linked_list/deque_doubly.py @@ -112,7 +112,7 @@ class LinkedDeque(_DoublyLinkedBase): ... IndexError: remove_first from empty list >>> d.add_first('A') # doctest: +ELLIPSIS - >> d.remove_first() 'A' >>> d.is_empty() @@ -132,7 +132,7 @@ class LinkedDeque(_DoublyLinkedBase): ... IndexError: remove_first from empty list >>> d.add_first('A') # doctest: +ELLIPSIS - >> d.remove_last() 'A' >>> d.is_empty() diff --git a/data_structures/queue/circular_queue.py b/data_structures/queue/circular_queue.py index 229a67ebb..93a6ef805 100644 --- a/data_structures/queue/circular_queue.py +++ b/data_structures/queue/circular_queue.py @@ -17,7 +17,7 @@ class CircularQueue: >>> len(cq) 0 >>> cq.enqueue("A") # doctest: +ELLIPSIS - >> len(cq) 1 """ @@ -48,11 +48,11 @@ class CircularQueue: This function insert an element in the queue using self.rear value as an index >>> cq = CircularQueue(5) >>> cq.enqueue("A") # doctest: +ELLIPSIS - >> (cq.size, cq.first()) (1, 'A') >>> cq.enqueue("B") # doctest: +ELLIPSIS - >> (cq.size, cq.first()) (2, 'A') """ diff --git a/data_structures/queue/priority_queue_using_list.py b/data_structures/queue/priority_queue_using_list.py index 0ba4e88cd..c5cf26433 100644 --- a/data_structures/queue/priority_queue_using_list.py +++ b/data_structures/queue/priority_queue_using_list.py @@ -59,7 +59,7 @@ class FixedPriorityQueue: >>> fpq.dequeue() Traceback (most recent call last): ... - priority_queue_using_list.UnderFlowError: All queues are empty + data_structures.queue.priority_queue_using_list.UnderFlowError: All queues are empty >>> print(fpq) Priority 0: [] Priority 1: [] @@ -141,7 +141,7 @@ class ElementPriorityQueue: >>> epq.dequeue() Traceback (most recent call last): ... - priority_queue_using_list.UnderFlowError: The queue is empty + data_structures.queue.priority_queue_using_list.UnderFlowError: The queue is empty >>> print(epq) [] """ diff --git a/geodesy/lamberts_ellipsoidal_distance.py b/geodesy/lamberts_ellipsoidal_distance.py index 4a318265e..bf8f1b9a5 100644 --- a/geodesy/lamberts_ellipsoidal_distance.py +++ b/geodesy/lamberts_ellipsoidal_distance.py @@ -1,6 +1,6 @@ from math import atan, cos, radians, sin, tan -from haversine_distance import haversine_distance +from .haversine_distance import haversine_distance def lamberts_ellipsoidal_distance( diff --git a/greedy_method/test_knapsack.py b/greedy_method/test_knapsack.py index f3ae624ea..5e277a921 100644 --- a/greedy_method/test_knapsack.py +++ b/greedy_method/test_knapsack.py @@ -1,6 +1,6 @@ import unittest -import greedy_knapsack as kp +from . import greedy_knapsack as kp class TestClass(unittest.TestCase): diff --git a/linear_algebra/src/test_linear_algebra.py b/linear_algebra/src/test_linear_algebra.py index 668ffe858..6eba3a163 100644 --- a/linear_algebra/src/test_linear_algebra.py +++ b/linear_algebra/src/test_linear_algebra.py @@ -8,7 +8,7 @@ This file contains the test-suite for the linear algebra library. """ import unittest -from lib import Matrix, Vector, axpy, squareZeroMatrix, unitBasisVector, zeroVector +from .lib import Matrix, Vector, axpy, squareZeroMatrix, unitBasisVector, zeroVector class Test(unittest.TestCase): diff --git a/scripts/validate_filenames.py b/scripts/validate_filenames.py index f09c1527c..e75bf6c18 100755 --- a/scripts/validate_filenames.py +++ b/scripts/validate_filenames.py @@ -1,7 +1,10 @@ #!/usr/bin/env python3 import os -from build_directory_md import good_file_paths +try: + from .build_directory_md import good_file_paths +except ImportError: + from build_directory_md import good_file_paths filepaths = list(good_file_paths()) assert filepaths, "good_file_paths() failed!" diff --git a/searches/simulated_annealing.py b/searches/simulated_annealing.py index 8535e5419..2aa980be7 100644 --- a/searches/simulated_annealing.py +++ b/searches/simulated_annealing.py @@ -2,7 +2,7 @@ import math import random -from hill_climbing import SearchProblem +from .hill_climbing import SearchProblem def simulated_annealing(