Skip to content

Commit 51e83c5

Browse files
committed
Added dependency free makefile for mformatting
1 parent 2e021bf commit 51e83c5

Some content is hidden

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

49 files changed

+403
-229
lines changed

makefile

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# REDNAFI
2+
# This only works with embedded venv not virtualenv
3+
# Install venv: python3.8 -m venv venv
4+
# Activate venv: source venv/bin/activate
5+
6+
# Usage (line =black line length, path = action path, ignore= exclude folders)
7+
# ------
8+
# make pylinter [make pylinter line=88 path=.]
9+
# make pyupgrade
10+
11+
path := .
12+
line := 88
13+
ignore := *env
14+
15+
all:
16+
@echo
17+
18+
.PHONY: checkvenv
19+
checkvenv:
20+
# raises error if environment is not active
21+
ifeq ("$(VIRTUAL_ENV)","")
22+
@echo "Venv is not activated!"
23+
@echo "Activate venv first."
24+
@echo
25+
exit 1
26+
endif
27+
28+
.PHONY: pyupgrade
29+
pyupgrade: checkvenv
30+
# checks if pip-tools is installed
31+
ifeq ("$(wildcard venv/bin/pip-compile)","")
32+
@echo "Installing Pip-tools..."
33+
@pip install pip-tools
34+
endif
35+
36+
ifeq ("$(wildcard venv/bin/pip-sync)","")
37+
@echo "Installing Pip-tools..."
38+
@pip install pip-tools
39+
endif
40+
41+
# pip-tools
42+
@pip-compile --upgrade requirements-dev.txt
43+
@pip-compile --upgrade requirements.txt
44+
@pip-sync requirements-dev.txt requirements.txt
45+
46+
47+
.PHONY: pylinter
48+
pylinter: checkvenv
49+
# checks if black is installed
50+
ifeq ("$(wildcard venv/bin/black)","")
51+
@echo "Installing Black..."
52+
@pip install black
53+
endif
54+
55+
# checks if isort is installed
56+
ifeq ("$(wildcard venv/bin/isort)","")
57+
@echo "Installing Isort..."
58+
@pip install isort
59+
endif
60+
61+
# checks if flake8 is installed
62+
ifeq ("$(wildcard venv/bin/flake8)","")
63+
@echo -e "Installing flake8..."
64+
@pip install flake8
65+
@echo
66+
endif
67+
68+
# black
69+
@echo "Applying Black"
70+
@echo "----------------\n"
71+
@black --line-length $(line) --exclude $(ignore) $(path)
72+
@echo
73+
74+
# isort
75+
@echo "Applying Isort"
76+
@echo "----------------\n"
77+
@isort --atomic --profile black $(path)
78+
@echo
79+
80+
# flake8
81+
@echo "Applying Flake8"
82+
@echo "----------------\n"
83+
@flake8 --max-line-length "$(line)" \
84+
--max-complexity "18" \
85+
--select "B,C,E,F,W,T4,B9" \
86+
--ignore "E203,E266,E501,W503,F403,F401,E402" \
87+
--exclude ".git,__pycache__,old, build, \
88+
dist, venv" $(path)

patterns/behavioral/chain_of_responsibility.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from abc import ABC, abstractmethod
2222
from typing import Callable, Optional, Tuple, TypeVar
2323

24-
2524
T = TypeVar("T")
2625

2726

@@ -115,4 +114,5 @@ def main():
115114

116115
if __name__ == "__main__":
117116
import doctest
117+
118118
doctest.testmod(optionflags=doctest.ELLIPSIS)

patterns/behavioral/chaining_method.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def __init__(self, name, action):
44
self.action = action
55

66
def do_action(self):
7-
print(self.name, self.action.name, end=' ')
7+
print(self.name, self.action.name, end=" ")
88
return self.action
99

1010

@@ -13,11 +13,11 @@ def __init__(self, name):
1313
self.name = name
1414

1515
def amount(self, val):
16-
print(val, end=' ')
16+
print(val, end=" ")
1717
return self
1818

1919
def stop(self):
20-
print('then stop')
20+
print("then stop")
2121

2222

2323
def main():
@@ -29,6 +29,7 @@ def main():
2929
"""
3030

3131

32-
if __name__ == '__main__':
32+
if __name__ == "__main__":
3333
import doctest
34+
3435
doctest.testmod()

patterns/behavioral/iterator.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ def main():
4040

4141
if __name__ == "__main__":
4242
import doctest
43+
4344
doctest.testmod()

patterns/behavioral/iterator_alt.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
class NumberWords:
1010
"""Counts by word numbers, up to a maximum of five"""
11+
1112
_WORD_MAP = (
12-
'one',
13-
'two',
14-
'three',
15-
'four',
16-
'five',
13+
"one",
14+
"two",
15+
"three",
16+
"four",
17+
"five",
1718
)
1819

1920
def __init__(self, start, stop):
@@ -33,6 +34,7 @@ def __next__(self): # this makes the class an Iterator
3334

3435
# Test the iterator
3536

37+
3638
def main():
3739
"""
3840
# Counting to two...

patterns/behavioral/mediator.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def main():
4545
"""
4646

4747

48-
if __name__ == '__main__':
48+
if __name__ == "__main__":
4949
import doctest
50+
5051
doctest.testmod()

patterns/behavioral/memento.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
Provides the ability to restore an object to its previous state.
66
"""
77

8-
from copy import copy
9-
from copy import deepcopy
8+
from copy import copy, deepcopy
109

1110

1211
def memento(obj, deep=False):
@@ -67,14 +66,14 @@ def __init__(self, value):
6766
self.value = value
6867

6968
def __repr__(self):
70-
return '<%s: %r>' % (self.__class__.__name__, self.value)
69+
return "<%s: %r>" % (self.__class__.__name__, self.value)
7170

7271
def increment(self):
7372
self.value += 1
7473

7574
@Transactional
7675
def do_stuff(self):
77-
self.value = '1111' # <- invalid value
76+
self.value = "1111" # <- invalid value
7877
self.increment() # <- will fail and rollback
7978

8079

@@ -134,4 +133,5 @@ def main():
134133

135134
if __name__ == "__main__":
136135
import doctest
136+
137137
doctest.testmod(optionflags=doctest.ELLIPSIS)

patterns/behavioral/observer.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def notify(self, modifier=None):
3131

3232

3333
class Data(Subject):
34-
def __init__(self, name=''):
34+
def __init__(self, name=""):
3535
Subject.__init__(self)
3636
self.name = name
3737
self._data = 0
@@ -48,12 +48,14 @@ def data(self, value):
4848

4949
class HexViewer:
5050
def update(self, subject):
51-
print('HexViewer: Subject {} has data 0x{:x}'.format(subject.name, subject.data))
51+
print(
52+
"HexViewer: Subject {} has data 0x{:x}".format(subject.name, subject.data)
53+
)
5254

5355

5456
class DecimalViewer:
5557
def update(self, subject):
56-
print('DecimalViewer: Subject %s has data %d' % (subject.name, subject.data))
58+
print("DecimalViewer: Subject %s has data %d" % (subject.name, subject.data))
5759

5860

5961
def main():
@@ -97,4 +99,5 @@ def main():
9799

98100
if __name__ == "__main__":
99101
import doctest
102+
100103
doctest.testmod()

patterns/behavioral/publish_subscribe.py

+1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ def main():
8989

9090
if __name__ == "__main__":
9191
import doctest
92+
9293
doctest.testmod()

patterns/behavioral/registry.py

+1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ def main():
4242

4343
if __name__ == "__main__":
4444
import doctest
45+
4546
doctest.testmod(optionflags=doctest.ELLIPSIS)

patterns/behavioral/specification.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def __init__(self, one, other):
4747
self._other = other
4848

4949
def is_satisfied_by(self, candidate):
50-
return bool(self._one.is_satisfied_by(candidate) and self._other.is_satisfied_by(candidate))
50+
return bool(
51+
self._one.is_satisfied_by(candidate)
52+
and self._other.is_satisfied_by(candidate)
53+
)
5154

5255

5356
class OrSpecification(CompositeSpecification):
@@ -59,7 +62,10 @@ def __init__(self, one, other):
5962
self._other = other
6063

6164
def is_satisfied_by(self, candidate):
62-
return bool(self._one.is_satisfied_by(candidate) or self._other.is_satisfied_by(candidate))
65+
return bool(
66+
self._one.is_satisfied_by(candidate)
67+
or self._other.is_satisfied_by(candidate)
68+
)
6369

6470

6571
class NotSpecification(CompositeSpecification):
@@ -84,7 +90,7 @@ def is_satisfied_by(self, candidate):
8490

8591
class SuperUserSpecification(CompositeSpecification):
8692
def is_satisfied_by(self, candidate):
87-
return getattr(candidate, 'super_user', False)
93+
return getattr(candidate, "super_user", False)
8894

8995

9096
def main():
@@ -105,6 +111,7 @@ def main():
105111
"""
106112

107113

108-
if __name__ == '__main__':
114+
if __name__ == "__main__":
109115
import doctest
116+
110117
doctest.testmod()

patterns/behavioral/state.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def main():
8383
"""
8484

8585

86-
if __name__ == '__main__':
86+
if __name__ == "__main__":
8787
import doctest
88+
8889
doctest.testmod()

patterns/behavioral/strategy.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ def main():
4848

4949
if __name__ == "__main__":
5050
import doctest
51+
5152
doctest.testmod()

patterns/behavioral/template.py

+1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,5 @@ def main():
6969

7070
if __name__ == "__main__":
7171
import doctest
72+
7273
doctest.testmod()

patterns/behavioral/visitor.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Visitor:
3636
def visit(self, node, *args, **kwargs):
3737
meth = None
3838
for cls in node.__class__.__mro__:
39-
meth_name = 'visit_' + cls.__name__
39+
meth_name = "visit_" + cls.__name__
4040
meth = getattr(self, meth_name, None)
4141
if meth:
4242
break
@@ -46,10 +46,10 @@ def visit(self, node, *args, **kwargs):
4646
return meth(node, *args, **kwargs)
4747

4848
def generic_visit(self, node, *args, **kwargs):
49-
print('generic_visit ' + node.__class__.__name__)
49+
print("generic_visit " + node.__class__.__name__)
5050

5151
def visit_B(self, node, *args, **kwargs):
52-
print('visit_B ' + node.__class__.__name__)
52+
print("visit_B " + node.__class__.__name__)
5353

5454

5555
def main():
@@ -70,4 +70,5 @@ def main():
7070

7171
if __name__ == "__main__":
7272
import doctest
73+
7374
doctest.testmod()

patterns/creational/abstract_factory.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def main():
101101

102102

103103
if __name__ == "__main__":
104-
random.seed(1234) # for deterministic doctest outputs
104+
random.seed(1234) # for deterministic doctest outputs
105105
import doctest
106+
106107
doctest.testmod()

patterns/creational/borg.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,18 @@ def __init__(self):
4242

4343

4444
class YourBorg(Borg):
45-
4645
def __init__(self, state=None):
4746
super().__init__()
4847
if state:
4948
self.state = state
5049
else:
5150
# initiate the first instance with default state
52-
if not hasattr(self, 'state'):
53-
self.state = 'Init'
51+
if not hasattr(self, "state"):
52+
self.state = "Init"
5453

5554
def __str__(self):
5655
return self.state
57-
56+
5857

5958
def main():
6059
"""
@@ -106,4 +105,5 @@ def main():
106105

107106
if __name__ == "__main__":
108107
import doctest
108+
109109
doctest.testmod()

0 commit comments

Comments
 (0)