pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/faif/python-patterns/commit/51e83c508ac3bcf21d04d8dc823160e5085b2d6d

origen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-9c8f61f9f58ad7b2.css" /> Added dependency free makefile for mformatting · faif/python-patterns@51e83c5 · GitHub
Skip to content

Commit 51e83c5

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

49 files changed

Lines changed: 403 additions & 229 deletions

Some content is hidden

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

makefile

Lines changed: 88 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 5 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy