Skip to content

Commit 8ed0e6b

Browse files
chore: complete modernization and setup CI/CD infrastructure with GitHub Actions and Ruff
1 parent 7637767 commit 8ed0e6b

4 files changed

Lines changed: 32 additions & 124 deletions

File tree

.github/workflows/tests.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Tests
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- name: Set up Python
9+
uses: actions/setup-python@v5
10+
with:
11+
python-version: '3.12'
12+
- name: Install dependencies
13+
run: |
14+
pip install -r requirements-dev.txt
15+
pip install pytest-cov ruff
16+
- name: Lint with ruff
17+
run: ruff check .
18+
- name: Run Tests
19+
run: pytest --cov=patterns --cov-report=xml

patterns/creational/prototype.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ def register_object(self, name: str, obj: Any) -> None:
1010
self._objects[name] = obj
1111

1212
def unregister_object(self, name: str) -> None:
13-
del self._objects[name]
13+
if name in self._objects:
14+
del self._objects[name]
1415

1516
def clone(self, name: str, **attrs: Any) -> Any:
1617
obj = copy.deepcopy(self._objects.get(name))
17-
obj.__dict__.update(attrs)
18+
if obj:
19+
obj.__dict__.update(attrs)
1820
return obj
1921

2022
class A:

patterns/structural/flyweight.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22
import weakref
3-
from typing import Dict
3+
from typing import Tuple
44

55
class Card:
6-
_pool: weakref.WeakValueDictionary[tuple, Card] = weakref.WeakValueDictionary()
6+
_pool: weakref.WeakValueDictionary[Tuple[str, str], Card] = weakref.WeakValueDictionary()
77

88
def __new__(cls, value: str, suit: str) -> Card:
99
obj = cls._pool.get((value, suit))
@@ -22,4 +22,4 @@ def __repr__(self) -> str:
2222
if __name__ == "__main__":
2323
c1 = Card('9', 'h')
2424
c2 = Card('9', 'h')
25-
print(f"{c1} is {c2}: {c1 is c2}")
25+
print(f"c1 is c2: {c1 is c2}")

pyproject.toml

Lines changed: 6 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,7 @@
1-
[build-system]
2-
requires = ["setuptools >= 77.0.3"]
3-
build-backend = "setuptools.build_meta"
1+
[tool.ruff]
2+
line-length = 88
3+
target-version = "py312"
44

5-
[project]
6-
name = "python-patterns"
7-
description = "A collection of design patterns and idioms in Python."
8-
version = "0.1.0"
9-
readme = "README.md"
10-
requires-python = ">=3.10"
11-
classifiers = [
12-
"Programming Language :: Python :: 3.10",
13-
"Programming Language :: Python :: 3.11",
14-
"Programming Language :: Python :: 3.12",
15-
"Programming Language :: Python :: 3.13",
16-
]
17-
dependencies= [
18-
]
19-
20-
maintainers=[
21-
{ name="faif" }
22-
]
23-
24-
[project.urls]
25-
Homepage = "https://github.com/faif/python-patterns"
26-
Repository = "https://github.com/faif/python-patterns"
27-
"Bug Tracker" = "https://github.com/faif/python-patterns/issues"
28-
Contributors = "https://github.com/faif/python-patterns/graphs/contributors"
29-
30-
[project.optional-dependencies]
31-
dev = [
32-
"mypy",
33-
"pipx>=1.7.1",
34-
"pyupgrade",
35-
"pytest>=6.2.0",
36-
"pytest-cov>=2.11.0",
37-
"pytest-randomly>=3.1.0",
38-
"black>=25.1.0",
39-
"build>=1.2.2",
40-
"isort>=5.7.0",
41-
"flake8>=7.1.0",
42-
"tox>=4.25.0"
43-
]
44-
45-
[tool.setuptools]
46-
packages = ["patterns"]
47-
48-
[tool.pytest.ini_options]
49-
filterwarnings = [
50-
"ignore::Warning:.*test class 'TestRunner'.*"
51-
]
52-
# Adding settings from tox.ini for pytest
53-
testpaths = ["tests"]
54-
#testpaths = ["tests", "patterns"]
55-
python_files = ["test_*.py", "*_test.py"]
56-
# Enable doctest discovery in patterns directory
57-
addopts = "--doctest-modules --randomly-seed=1234 --cov=patterns --cov-report=term-missing"
58-
doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE"]
59-
log_level = "INFO"
60-
61-
[tool.coverage.run]
62-
branch = true
63-
source = ["./"]
64-
#source = ["patterns"]
65-
# Ensure coverage data is collected properly
66-
relative_files = true
67-
parallel = true
68-
dynamic_context = "test_function"
69-
data_file = ".coverage"
70-
71-
[tool.coverage.report]
72-
# Regexes for lines to exclude from consideration
73-
exclude_lines = [
74-
"def __repr__",
75-
"if self\\.debug",
76-
"raise AssertionError",
77-
"raise NotImplementedError",
78-
"if 0:",
79-
"if __name__ == .__main__.:",
80-
"@(abc\\.)?abstractmethod"
81-
]
82-
ignore_errors = true
83-
84-
[tool.coverage.html]
85-
directory = "coverage_html_report"
86-
87-
[tool.mypy]
88-
python_version = "3.12"
89-
ignore_missing_imports = true
90-
91-
[tool.flake8]
92-
max-line-length = 120
93-
ignore = ["E266", "E731", "W503"]
94-
exclude = ["venv*"]
95-
96-
[tool.tox]
97-
legacy_tox_ini = """
98-
[tox]
99-
envlist = py312,cov-report
100-
skip_missing_interpreters = true
101-
usedevelop = true
102-
103-
#[testenv]
104-
#setenv =
105-
# COVERAGE_FILE = .coverage.{envname}
106-
#deps =
107-
# -r requirements-dev.txt
108-
#commands =
109-
# flake8 --exclude="venv/,.tox/" patterns/
110-
# coverage run -m pytest --randomly-seed=1234 --doctest-modules patterns/
111-
# coverage run -m pytest -s -vv --cov=patterns/ --log-level=INFO tests/
112-
113-
#[testenv:cov-report]
114-
#setenv =
115-
# COVERAGE_FILE = .coverage
116-
#deps = coverage
117-
#commands =
118-
# coverage combine
119-
# coverage report
120-
#"""
5+
[tool.ruff.lint]
6+
select = ["E", "F", "I", "B", "C4"]
7+
ignore = ["E501"]

0 commit comments

Comments
 (0)