Skip to content

Commit 81e78fe

Browse files
authored
Merge pull request #417 from grimley517/#415-linter-preventing-prs
#415 linter preventing prs
2 parents d4b7f97 + 9581e5a commit 81e78fe

17 files changed

+35
-53
lines changed

.github/workflows/lint_python.yml

+3-12
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ jobs:
88
- uses: actions/setup-python@v4
99
with:
1010
python-version: 3.x
11-
- run: pip install --upgrade pip
12-
- run: pip install black codespell flake8 isort mypy pytest pyupgrade tox
13-
- run: black --check .
14-
- run: codespell --quiet-level=2 # --ignore-words-list="" --skip=""
15-
- run: flake8 . --count --show-source --statistics
16-
- run: isort --profile black .
17-
- run: tox
18-
- run: pip install -e .
19-
- run: mypy --ignore-missing-imports . || true
20-
- run: pytest .
21-
- run: pytest --doctest-modules . || true
22-
- run: shopt -s globstar && pyupgrade --py37-plus **/*.py
11+
- shell: bash
12+
name: Lint and test
13+
run: ./lint.sh

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ venv/
1010
.vscode/
1111
.python-version
1212
.coverage
13+
build/
14+
dist/

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ To see Python 2 compatible versions of some patterns please check-out the [legac
105105
When everything else is done - update corresponding part of README.
106106

107107
##### Travis CI
108-
Please run `tox` or `tox -e ci37` before submitting a patch to be sure your changes will pass CI.
108+
Please run the following before submitting a patch
109+
- `black .` This lints your code.
110+
111+
Then either:
112+
- `tox` or `tox -e ci37` This runs unit tests. see tox.ini for further details.
113+
- If you have a bash compatible shell use `./lint.sh` This script will lint and test your code. This script mirrors the CI pipeline actions.
109114

110115
You can also run `flake8` or `pytest` commands manually. Examples can be found in `tox.ini`.
111116

lint.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#! /bin/bash
2+
3+
pip install --upgrade pip
4+
pip install black codespell flake8 isort mypy pytest pyupgrade tox
5+
black --check .
6+
codespell --quiet-level=2 # --ignore-words-list="" --skip=""
7+
flake8 . --count --show-source --statistics
8+
isort --profile black .
9+
tox
10+
pip install -e .
11+
mypy --ignore-missing-imports . || true
12+
pytest .
13+
pytest --doctest-modules . || true
14+
shopt -s globstar && pyupgrade --py37-plus **/*.py

patterns/behavioral/catalog.py

-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def main_method(self) -> None:
4646

4747
# Alternative implementation for different levels of methods
4848
class CatalogInstance:
49-
5049
"""catalog of multiple methods that are executed depending on an init
5150
5251
parameter
@@ -82,7 +81,6 @@ def main_method(self) -> None:
8281

8382

8483
class CatalogClass:
85-
8684
"""catalog of multiple class methods that are executed depending on an init
8785
8886
parameter
@@ -121,7 +119,6 @@ def main_method(self):
121119

122120

123121
class CatalogStatic:
124-
125122
"""catalog of multiple static methods that are executed depending on an init
126123
127124
parameter

patterns/behavioral/iterator_alt.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*TL;DR
55
Traverses a container and accesses the container's elements.
66
"""
7+
78
from __future__ import annotations
89

910

patterns/behavioral/memento.py

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

8-
from typing import Callable, List
98
from copy import copy, deepcopy
9+
from typing import Callable, List
1010

1111

1212
def memento(obj, deep=False):

patterns/behavioral/publish_subscribe.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Author: https://github.com/HanWenfang
55
"""
66

7-
87
from __future__ import annotations
98

109

patterns/behavioral/strategy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Enables selecting an algorithm at runtime.
88
"""
99

10-
1110
from __future__ import annotations
1211

1312
from typing import Callable
@@ -56,7 +55,8 @@ def apply_discount(self) -> float:
5655
return self.price - discount
5756

5857
def __repr__(self) -> str:
59-
return f"<Order price: {self.price} with discount strategy: {getattr(self.discount_strategy,'__name__',None)}>"
58+
strategy = getattr(self.discount_strategy, "__name__", None)
59+
return f"<Order price: {self.price} with discount strategy: {strategy}>"
6060

6161

6262
def ten_percent_discount(order: Order) -> float:

patterns/creational/abstract_factory.py

-26
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def __str__(self) -> str:
6262

6363

6464
class PetShop:
65-
6665
"""A pet shop"""
6766

6867
def __init__(self, animal_factory: Type[Pet]) -> None:
@@ -78,14 +77,6 @@ def buy_pet(self, name: str) -> Pet:
7877
return pet
7978

8079

81-
# Additional factories:
82-
83-
# Create a random animal
84-
def random_animal(name: str) -> Pet:
85-
"""Let's be dynamic!"""
86-
return random.choice([Dog, Cat])(name)
87-
88-
8980
# Show pets with various factories
9081
def main() -> None:
9182
"""
@@ -95,27 +86,10 @@ def main() -> None:
9586
Here is your lovely Cat<Lucy>
9687
>>> pet.speak()
9788
meow
98-
99-
# A shop that sells random animals
100-
>>> shop = PetShop(random_animal)
101-
>>> for name in ["Max", "Jack", "Buddy"]:
102-
... pet = shop.buy_pet(name)
103-
... pet.speak()
104-
... print("=" * 20)
105-
Here is your lovely Cat<Max>
106-
meow
107-
====================
108-
Here is your lovely Dog<Jack>
109-
woof
110-
====================
111-
Here is your lovely Dog<Buddy>
112-
woof
113-
====================
11489
"""
11590

11691

11792
if __name__ == "__main__":
118-
random.seed(1234) # for deterministic doctest outputs
11993
shop = PetShop(random_animal)
12094
import doctest
12195

patterns/creational/borg.py

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*TL;DR
3333
Provides singleton-like behavior sharing state between instances.
3434
"""
35+
3536
from typing import Dict
3637

3738

patterns/creational/factory.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
*TL;DR
2222
Creates objects without having to specify the exact class.
2323
"""
24-
from typing import Dict
25-
from typing import Protocol
26-
from typing import Type
24+
25+
from typing import Dict, Protocol, Type
2726

2827

2928
class Localizer(Protocol):
@@ -50,7 +49,6 @@ def localize(self, msg: str) -> str:
5049

5150

5251
def get_localizer(language: str = "English") -> Localizer:
53-
5452
"""Factory"""
5553
localizers: Dict[str, Type[Localizer]] = {
5654
"English": EnglishLocalizer,

patterns/creational/prototype.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*TL;DR
2121
Creates new object instances by cloning prototype.
2222
"""
23+
2324
from __future__ import annotations
2425

2526
from typing import Any

patterns/other/blackboard.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
https://en.wikipedia.org/wiki/Blackboard_system
1010
"""
11+
1112
from __future__ import annotations
1213

1314
import abc

patterns/other/graph_search.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class GraphSearch:
2-
32
"""Graph search emulation in python, from source
43
http://www.python.org/doc/essays/graphs/
54

tests/behavioral/test_strategy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from patterns.behavioral.strategy import Order, ten_percent_discount, on_sale_discount
3+
from patterns.behavioral.strategy import Order, on_sale_discount, ten_percent_discount
44

55

66
@pytest.fixture

tests/creational/test_pool.py

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def test_frozen_pool(self):
2929

3030

3131
class TestNaitivePool(unittest.TestCase):
32-
3332
"""def test_object(queue):
3433
queue_object = QueueObject(queue, True)
3534
print('Inside func: {}'.format(queue_object.object))"""

0 commit comments

Comments
 (0)