clock-pattern 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ # linting files
2
+ .coverage
3
+
4
+ # cache files/folders
5
+ **cache**
6
+
7
+ # build and distribution files/folders
8
+ **dist**
9
+ **build**
10
+
11
+ # environment folders
12
+ **.venv**
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) (2025) adriamontoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: clock-pattern
3
+ Version: 0.1.0
4
+ Summary: The Clock Pattern is a Python package that turns time into an injectable dependency.
5
+ Project-URL: Homepage, https://github.com/adriamontoto/clock-pattern
6
+ Project-URL: Repository, https://github.com/adriamontoto/clock-pattern
7
+ Project-URL: Issues, https://github.com/adriamontoto/clock-pattern/issues
8
+ Author: Adria Montoto
9
+ License-Expression: MIT
10
+ License-File: LICENSE.md
11
+ Keywords: clock,dependency-injection,development,domain-driven-design,pattern,python,utilities
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: value-object-pattern>=0.5.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ <a name="readme-top"></a>
26
+
27
+ # ๐Ÿ•ฐ๏ธ Clock Pattern
28
+
29
+ <p align="center">
30
+ <a href="https://github.com/adriamontoto/clock-pattern/actions/workflows/ci.yaml?event=push&branch=master" target="_blank">
31
+ <img src="https://github.com/adriamontoto/clock-pattern/actions/workflows/ci.yaml/badge.svg?event=push&branch=master" alt="CI Pipeline">
32
+ </a>
33
+ <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/adriamontoto/clock-pattern" target="_blank">
34
+ <img src="https://coverage-badge.samuelcolvin.workers.dev/adriamontoto/clock-pattern.svg" alt="Coverage Pipeline">
35
+ </a>
36
+ <a href="https://pypi.org/project/clock-pattern" target="_blank">
37
+ <img src="https://img.shields.io/pypi/v/clock-pattern?color=%2334D058&label=pypi%20package" alt="Package Version">
38
+ </a>
39
+ <a href="https://pypi.org/project/clock-pattern/" target="_blank">
40
+ <img src="https://img.shields.io/pypi/pyversions/clock-pattern.svg?color=%2334D058" alt="Supported Python Versions">
41
+ </a>
42
+ </p>
43
+
44
+ The **Clock Pattern** is a Python ๐Ÿ package that turns time into an injectable dependency ๐Ÿงฉ. By replacing ad-hoc datetime.now() calls with a swappable Clock interface ๐Ÿ•ฐ๏ธ you unlock deterministic tests ๐Ÿงช, decouple business logic from the OS clock, and gain the freedom to swap in high-precision or logical clocks without touching domain code.
45
+ <br><br>
46
+
47
+ ## Table of Contents
48
+
49
+ - [๐Ÿ“ฅ Installation](#installation)
50
+ - [๐Ÿค Contributing](#contributing)
51
+ - [๐Ÿ”‘ License](#license)
52
+
53
+ <p align="right">
54
+ <a href="#readme-top">๐Ÿ”ผ Back to top</a>
55
+ </p><br><br>
56
+
57
+ <a name="installation"></a>
58
+
59
+ ## ๐Ÿ“ฅ Installation
60
+
61
+ You can install **Clock Pattern** using `pip`:
62
+
63
+ ```bash
64
+ pip install clock-pattern
65
+ ```
66
+
67
+ <p align="right">
68
+ <a href="#readme-top">๐Ÿ”ผ Back to top</a>
69
+ </p><br><br>
70
+
71
+ <a name="contributing"></a>
72
+
73
+ ## ๐Ÿค Contributing
74
+
75
+ We love community help! Before you open an issue or pull request, please read:
76
+
77
+ - [`๐Ÿค How to Contribute`](https://github.com/adriamontoto/clock-pattern/blob/master/.github/CONTRIBUTING.md)
78
+ - [`๐Ÿงญ Code of Conduct`](https://github.com/adriamontoto/clock-pattern/blob/master/.github/CODE_OF_CONDUCT.md)
79
+ - [`๐Ÿ” Security Policy`](https://github.com/adriamontoto/clock-pattern/blob/master/.github/SECURITY.md)
80
+
81
+ _Thank you for helping make **๐Ÿ•ฐ๏ธ Clock Pattern** package awesome! ๐ŸŒŸ_
82
+
83
+ <p align="right">
84
+ <a href="#readme-top">๐Ÿ”ผ Back to top</a>
85
+ </p><br><br>
86
+
87
+ <a name="license"></a>
88
+
89
+ ## ๐Ÿ”‘ License
90
+
91
+ This project is licensed under the terms of the [`MIT license`](https://github.com/adriamontoto/clock-pattern/blob/master/LICENSE.md).
92
+
93
+ <p align="right">
94
+ <a href="#readme-top">๐Ÿ”ผ Back to top</a>
95
+ </p>
@@ -0,0 +1,71 @@
1
+ <a name="readme-top"></a>
2
+
3
+ # ๐Ÿ•ฐ๏ธ Clock Pattern
4
+
5
+ <p align="center">
6
+ <a href="https://github.com/adriamontoto/clock-pattern/actions/workflows/ci.yaml?event=push&branch=master" target="_blank">
7
+ <img src="https://github.com/adriamontoto/clock-pattern/actions/workflows/ci.yaml/badge.svg?event=push&branch=master" alt="CI Pipeline">
8
+ </a>
9
+ <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/adriamontoto/clock-pattern" target="_blank">
10
+ <img src="https://coverage-badge.samuelcolvin.workers.dev/adriamontoto/clock-pattern.svg" alt="Coverage Pipeline">
11
+ </a>
12
+ <a href="https://pypi.org/project/clock-pattern" target="_blank">
13
+ <img src="https://img.shields.io/pypi/v/clock-pattern?color=%2334D058&label=pypi%20package" alt="Package Version">
14
+ </a>
15
+ <a href="https://pypi.org/project/clock-pattern/" target="_blank">
16
+ <img src="https://img.shields.io/pypi/pyversions/clock-pattern.svg?color=%2334D058" alt="Supported Python Versions">
17
+ </a>
18
+ </p>
19
+
20
+ The **Clock Pattern** is a Python ๐Ÿ package that turns time into an injectable dependency ๐Ÿงฉ. By replacing ad-hoc datetime.now() calls with a swappable Clock interface ๐Ÿ•ฐ๏ธ you unlock deterministic tests ๐Ÿงช, decouple business logic from the OS clock, and gain the freedom to swap in high-precision or logical clocks without touching domain code.
21
+ <br><br>
22
+
23
+ ## Table of Contents
24
+
25
+ - [๐Ÿ“ฅ Installation](#installation)
26
+ - [๐Ÿค Contributing](#contributing)
27
+ - [๐Ÿ”‘ License](#license)
28
+
29
+ <p align="right">
30
+ <a href="#readme-top">๐Ÿ”ผ Back to top</a>
31
+ </p><br><br>
32
+
33
+ <a name="installation"></a>
34
+
35
+ ## ๐Ÿ“ฅ Installation
36
+
37
+ You can install **Clock Pattern** using `pip`:
38
+
39
+ ```bash
40
+ pip install clock-pattern
41
+ ```
42
+
43
+ <p align="right">
44
+ <a href="#readme-top">๐Ÿ”ผ Back to top</a>
45
+ </p><br><br>
46
+
47
+ <a name="contributing"></a>
48
+
49
+ ## ๐Ÿค Contributing
50
+
51
+ We love community help! Before you open an issue or pull request, please read:
52
+
53
+ - [`๐Ÿค How to Contribute`](https://github.com/adriamontoto/clock-pattern/blob/master/.github/CONTRIBUTING.md)
54
+ - [`๐Ÿงญ Code of Conduct`](https://github.com/adriamontoto/clock-pattern/blob/master/.github/CODE_OF_CONDUCT.md)
55
+ - [`๐Ÿ” Security Policy`](https://github.com/adriamontoto/clock-pattern/blob/master/.github/SECURITY.md)
56
+
57
+ _Thank you for helping make **๐Ÿ•ฐ๏ธ Clock Pattern** package awesome! ๐ŸŒŸ_
58
+
59
+ <p align="right">
60
+ <a href="#readme-top">๐Ÿ”ผ Back to top</a>
61
+ </p><br><br>
62
+
63
+ <a name="license"></a>
64
+
65
+ ## ๐Ÿ”‘ License
66
+
67
+ This project is licensed under the terms of the [`MIT license`](https://github.com/adriamontoto/clock-pattern/blob/master/LICENSE.md).
68
+
69
+ <p align="right">
70
+ <a href="#readme-top">๐Ÿ”ผ Back to top</a>
71
+ </p>
@@ -0,0 +1 @@
1
+ __version__ = '0.1.0'
@@ -0,0 +1,3 @@
1
+ from .system_clock import SystemClock
2
+
3
+ __all__ = ('SystemClock',)
@@ -0,0 +1,120 @@
1
+ """
2
+ SystemClock module.
3
+ """
4
+
5
+ from sys import version_info
6
+
7
+ if version_info >= (3, 12):
8
+ from typing import override # pragma: no cover
9
+ else:
10
+ from typing_extensions import override # pragma: no cover
11
+
12
+ from datetime import UTC, date, datetime, tzinfo
13
+ from zoneinfo import ZoneInfo
14
+
15
+ from value_object_pattern.usables.dates import StringTimezoneValueObject, TimezoneValueObject
16
+
17
+ from clock_pattern.models.clock import Clock
18
+
19
+
20
+ class SystemClock(Clock):
21
+ """
22
+ SystemClock class is responsible of retrieving the current date/datetime with the provided timezone.
23
+
24
+ Example:
25
+ ```python
26
+ from clock_pattern.clocks import SystemClock
27
+
28
+ clock = SystemClock()
29
+ print(clock.now())
30
+ # >>> 2025-06-16 13:57:26.210964+00:00
31
+ ```
32
+ """
33
+
34
+ _timezone: tzinfo
35
+
36
+ def __init__(self, *, timezone: str | tzinfo = UTC) -> None:
37
+ """
38
+ SystemClock constructor is responsible to store which `timezone` the user wants to use when retrieving the
39
+ current date/datetime.
40
+
41
+ Args:
42
+ timezone: (str | tzinfo, optional): Timezone of the date/datetime to retrieve. Default to UTC.
43
+
44
+ Raises:
45
+ TypeError: If `timezone` is not of type tzinfo.
46
+ TypeError: If `timezone` is not of type string.
47
+ ValueError: If `timezone` is not a valid timezone.
48
+
49
+ Example:
50
+ ```python
51
+ from clock_pattern.clocks import SystemClock
52
+
53
+ clock = SystemClock()
54
+ print(clock.now())
55
+ # >>> 2025-06-16 13:57:26.210964+00:00
56
+ ```
57
+ """
58
+ if isinstance(timezone, tzinfo):
59
+ timezone = str(TimezoneValueObject(value=timezone, title='SystemClock', parameter='timezone'))
60
+
61
+ StringTimezoneValueObject(value=timezone, title='SystemClock', parameter='timezone')
62
+
63
+ self._timezone = ZoneInfo(timezone)
64
+
65
+ @override
66
+ def now(self) -> datetime:
67
+ """
68
+ Retrieve the current datetime (now).
69
+
70
+ Returns:
71
+ datetime: The current datetime.
72
+
73
+ Example:
74
+ ```python
75
+ from clock_pattern.clocks import SystemClock
76
+
77
+ clock = SystemClock()
78
+ print(clock.now())
79
+ # >>> 2025-06-16 13:57:26.210964+00:00
80
+ ```
81
+ """
82
+ return datetime.now(tz=self._timezone)
83
+
84
+ @override
85
+ def today(self) -> date:
86
+ """
87
+ Retrieve the current date (today).
88
+
89
+ Returns:
90
+ date: The current date.
91
+
92
+ Example:
93
+ ```python
94
+ from clock_pattern.clocks import SystemClock
95
+
96
+ clock = SystemClock()
97
+ print(clock.now())
98
+ # >>> 2025-06-16
99
+ ```
100
+ """
101
+ return datetime.now(tz=self._timezone).date()
102
+
103
+ @property
104
+ def timezone(self) -> tzinfo:
105
+ """
106
+ Retrieve the timezone of the clock.
107
+
108
+ Returns:
109
+ tzinfo: The timezone of the clock.
110
+
111
+ Example:
112
+ ```python
113
+ from clock_pattern.clocks import SystemClock
114
+
115
+ clock = SystemClock()
116
+ print(clock.timezone)
117
+ # >>> UTC
118
+ ```
119
+ """
120
+ return self._timezone
@@ -0,0 +1,3 @@
1
+ from .clock import Clock
2
+
3
+ __all__ = ('Clock',)
@@ -0,0 +1,59 @@
1
+ """
2
+ Clock module.
3
+ """
4
+
5
+ from abc import ABC, abstractmethod
6
+ from datetime import date, datetime
7
+
8
+
9
+ class Clock(ABC):
10
+ """
11
+ Clock class.
12
+
13
+ ***This class is abstract and should not be instantiated directly***.
14
+
15
+ Example:
16
+ ```python
17
+ from clock_pattern.clocks import SystemClock
18
+
19
+ clock = SystemClock()
20
+ print(clock.now())
21
+ # >>> 2025-06-16 13:57:26.210964+00:00
22
+ ```
23
+ """
24
+
25
+ @abstractmethod
26
+ def now(self) -> datetime:
27
+ """
28
+ Retrieve the current datetime (now).
29
+
30
+ Returns:
31
+ datetime: The current datetime.
32
+
33
+ Example:
34
+ ```python
35
+ from clock_pattern.clocks import SystemClock
36
+
37
+ clock = SystemClock()
38
+ print(clock.now())
39
+ # >>> 2025-06-16 13:57:26.210964+00:00
40
+ ```
41
+ """
42
+
43
+ @abstractmethod
44
+ def today(self) -> date:
45
+ """
46
+ Retrieve the current date (today).
47
+
48
+ Returns:
49
+ date: The current date.
50
+
51
+ Example:
52
+ ```python
53
+ from clock_pattern.clocks import SystemClock
54
+
55
+ clock = SystemClock()
56
+ print(clock.today())
57
+ # >>> 2025-06-16
58
+ ```
59
+ """
File without changes
@@ -0,0 +1,208 @@
1
+ [build-system]
2
+ requires = ['hatchling']
3
+ build-backend = 'hatchling.build'
4
+
5
+
6
+ [tool.hatch.version]
7
+ path = 'clock_pattern/__init__.py'
8
+
9
+ [tool.hatch.build.targets.sdist]
10
+ include = ['clock_pattern/']
11
+
12
+
13
+ [project]
14
+ name = 'clock-pattern'
15
+ description = 'The Clock Pattern is a Python package that turns time into an injectable dependency.'
16
+ readme = './README.md'
17
+ authors = [{ name = 'Adria Montoto' }]
18
+ license = 'MIT'
19
+ classifiers = [
20
+ 'License :: OSI Approved :: MIT License',
21
+ 'Intended Audience :: Developers',
22
+ 'Operating System :: OS Independent',
23
+ 'Typing :: Typed',
24
+ 'Programming Language :: Python',
25
+ 'Programming Language :: Python :: 3',
26
+ 'Programming Language :: Python :: 3.11',
27
+ 'Programming Language :: Python :: 3.12',
28
+ 'Programming Language :: Python :: 3.13',
29
+ ]
30
+ keywords = [
31
+ 'python',
32
+ 'development',
33
+ 'utilities',
34
+ 'clock',
35
+ 'pattern',
36
+ 'dependency-injection',
37
+ 'domain-driven-design',
38
+ ]
39
+ requires-python = '>=3.11'
40
+ dependencies = ['value-object-pattern>=0.5.0']
41
+ dynamic = ['version']
42
+
43
+ [project.urls]
44
+ Homepage = 'https://github.com/adriamontoto/clock-pattern'
45
+ Repository = 'https://github.com/adriamontoto/clock-pattern'
46
+ Issues = 'https://github.com/adriamontoto/clock-pattern/issues'
47
+
48
+
49
+ [dependency-groups]
50
+ audit = ['pip-audit>=2.9.0']
51
+ coverage = ['coverage[toml]>=7.0.0', 'smokeshow>=0.5.0']
52
+ develop = ['pre-commit>=3.0.0']
53
+ format = ['ruff>=0.11.10']
54
+ lint = ['ruff>=0.11.10', 'mypy[reports]>=1.0.0', { include-group = 'test' }]
55
+ release = ['build>=1.2.2', 'python-semantic-release>=10.0.2']
56
+ test = [
57
+ 'pytest>=8.0.0',
58
+ 'pytest-randomly>=3.0.0',
59
+ 'object-mother-pattern>=2.1.0',
60
+ { include-group = 'coverage' },
61
+ ]
62
+ all = [
63
+ { include-group = 'audit' },
64
+ { include-group = 'coverage' },
65
+ { include-group = 'develop' },
66
+ { include-group = 'format' },
67
+ { include-group = 'lint' },
68
+ { include-group = 'release' },
69
+ { include-group = 'test' },
70
+ ]
71
+
72
+
73
+ [tool.pytest.ini_options]
74
+ pythonpath = '.'
75
+ addopts = [
76
+ '--strict-config', # fail if an unregistered option is used
77
+ '--strict-markers', # fail if an unregistered marker is used
78
+ '--color=yes', # color the output
79
+ ]
80
+ markers = ['unit_testing: Check a unique functionality']
81
+ xfail_strict = true
82
+
83
+
84
+ [tool.coverage.run]
85
+ source = ['clock_pattern']
86
+ parallel = true
87
+ branch = true
88
+ relative_files = true
89
+
90
+ [tool.coverage.report]
91
+ show_missing = true
92
+ skip_covered = true
93
+ precision = 2
94
+ exclude_lines = [
95
+ 'pragma: no cover',
96
+ 'raise NotImplementedError',
97
+ 'if TYPE_CHECKING:',
98
+ 'if typing.TYPE_CHECKING:',
99
+ '@overload',
100
+ '@typing.overload',
101
+ 'typing.assert_never',
102
+ 'assert_never',
103
+ ]
104
+
105
+ [tool.coverage.paths]
106
+ source = ['clock_pattern']
107
+
108
+
109
+ [tool.ruff]
110
+ indent-width = 4
111
+ line-length = 120
112
+ target-version = 'py313'
113
+ output-format = 'grouped'
114
+
115
+ [tool.ruff.format]
116
+ docstring-code-format = true
117
+ docstring-code-line-length = 120
118
+ indent-style = 'space'
119
+ quote-style = 'single'
120
+ skip-magic-trailing-comma = false
121
+
122
+ [tool.ruff.lint]
123
+ select = [
124
+ 'F', # pyflakes
125
+ 'S', # flake8-bandit
126
+ 'B', # flake8-bugbear
127
+ 'DTZ', # flake8-datetimez
128
+ 'C4', # flake8-comprehensions
129
+ 'SIM', # flake8-simplify
130
+ 'I', # isort
131
+ 'C90', # mccabe
132
+ 'N', # pep8-naming
133
+ 'PERF', # perflint
134
+ 'E', # pycodestyle
135
+ 'W', # pycodestyle
136
+ 'D', # pydocstyle
137
+ 'UP', # pyupgrade
138
+ 'RUF', # ruff
139
+ ]
140
+ ignore = [
141
+ 'UP035', # Checks for uses of deprecated imports based on the minimum supported Python version.
142
+ 'UP036', # Checks for conditional blocks gated on sys.version_info comparisons that are outdated for the minimum supported Python version.
143
+ 'E111', # Checks for indentation with a non-multiple of 4 spaces.
144
+ 'E114', # Checks for indentation of comments with a non-multiple of 4 spaces.
145
+ 'E117', # Checks for over-indented code.
146
+ 'W191', # Checks for indentation that uses tabs.
147
+ 'D200', # Checks for single-line docstrings that are broken across multiple lines.
148
+ 'D205', # 1 blank line required between summary line and description.
149
+ 'D206', # Checks for docstrings that are indented with tabs.
150
+ 'D212', # Checks for docstring summary lines that are not positioned on the first physical line of the docstring.
151
+ 'D401', # First line of docstring should be in imperative mood.
152
+ 'D300', # Checks for docstrings that use '''triple single quotes''' instead of 'triple double quotes'.
153
+ 'RUF100', # Checks for unused noqa directives.
154
+ ]
155
+
156
+ [tool.ruff.lint.per-file-ignores]
157
+ '__init__.py' = [
158
+ 'F401', # Checks for unused imports.
159
+ 'D104', # Checks for undocumented public package definitions.
160
+ ]
161
+ '**test**.py' = [
162
+ 'S101', # Use of `assert` detected.
163
+ ]
164
+
165
+ [tool.ruff.lint.mccabe]
166
+ max-complexity = 10
167
+
168
+ [tool.ruff.lint.pydocstyle]
169
+ convention = 'pep257'
170
+
171
+ [tool.ruff.lint.isort]
172
+ case-sensitive = true
173
+ known-first-party = ['clock_pattern']
174
+ combine-as-imports = true
175
+
176
+
177
+ [tool.mypy]
178
+ strict = true
179
+ warn_unreachable = true
180
+ enable_error_code = [
181
+ 'redundant-expr',
182
+ 'possibly-undefined',
183
+ 'truthy-bool',
184
+ 'explicit-override',
185
+ ]
186
+
187
+
188
+ [tool.semantic_release]
189
+ allow_zero_version = true
190
+ commit_message = 'bump: new version {version} released'
191
+ commit_parser = 'conventional'
192
+ major_on_zero = true
193
+ no_git_verify = false
194
+ tag_format = 'v{version}'
195
+ version_variables = ['clock_pattern/__init__.py:__version__']
196
+
197
+ [tool.semantic_release.commit_parser_options]
198
+ minor_tags = ['feat']
199
+ patch_tags = ['fix', 'perf', 'build']
200
+ allowed_tags = ['feat', 'fix', 'perf', 'build']
201
+ default_bump_level = 0
202
+ parse_squash_commits = false
203
+ ignore_merge_commits = true
204
+
205
+ [tool.semantic_release.changelog]
206
+ template_dir = 'docs/changelog_template'
207
+ mode = 'update'
208
+ exclude_commit_patterns = ['''Merged? .*''']