fivcglue 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.
- fivcglue-0.1.0/LICENSE +22 -0
- fivcglue-0.1.0/PKG-INFO +209 -0
- fivcglue-0.1.0/README.md +177 -0
- fivcglue-0.1.0/pyproject.toml +114 -0
- fivcglue-0.1.0/setup.cfg +4 -0
- fivcglue-0.1.0/src/fivcglue/__about__.py +1 -0
- fivcglue-0.1.0/src/fivcglue/__init__.py +13 -0
- fivcglue-0.1.0/src/fivcglue/implements/__init__.py +126 -0
- fivcglue-0.1.0/src/fivcglue/implements/caches_mem.py +146 -0
- fivcglue-0.1.0/src/fivcglue/implements/caches_redis.py +33 -0
- fivcglue-0.1.0/src/fivcglue/implements/configs_jsonfile.py +37 -0
- fivcglue-0.1.0/src/fivcglue/implements/configs_yamlfile.py +37 -0
- fivcglue-0.1.0/src/fivcglue/implements/loggers_builtin.py +53 -0
- fivcglue-0.1.0/src/fivcglue/implements/mutexes_redis.py +184 -0
- fivcglue-0.1.0/src/fivcglue/implements/utils.py +31 -0
- fivcglue-0.1.0/src/fivcglue/interfaces/__init__.py +78 -0
- fivcglue-0.1.0/src/fivcglue/interfaces/caches.py +35 -0
- fivcglue-0.1.0/src/fivcglue/interfaces/configs.py +35 -0
- fivcglue-0.1.0/src/fivcglue/interfaces/loggers.py +56 -0
- fivcglue-0.1.0/src/fivcglue/interfaces/mutexes.py +43 -0
- fivcglue-0.1.0/src/fivcglue/interfaces/utils.py +76 -0
- fivcglue-0.1.0/src/fivcglue.egg-info/PKG-INFO +209 -0
- fivcglue-0.1.0/src/fivcglue.egg-info/SOURCES.txt +30 -0
- fivcglue-0.1.0/src/fivcglue.egg-info/dependency_links.txt +1 -0
- fivcglue-0.1.0/src/fivcglue.egg-info/requires.txt +9 -0
- fivcglue-0.1.0/src/fivcglue.egg-info/top_level.txt +1 -0
- fivcglue-0.1.0/tests/test_caches.py +16 -0
- fivcglue-0.1.0/tests/test_component_site.py +213 -0
- fivcglue-0.1.0/tests/test_configs.py +31 -0
- fivcglue-0.1.0/tests/test_loggers.py +112 -0
- fivcglue-0.1.0/tests/test_mutexes.py +200 -0
- fivcglue-0.1.0/tests/test_utils.py +200 -0
fivcglue-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Charlie Zhang
|
|
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.
|
|
22
|
+
|
fivcglue-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fivcglue
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Domain-Driven Design (DDD) programming package for Python, similar to zope.interface
|
|
5
|
+
Author-email: Charlie ZHANG <sunnypig2002@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Documentation, https://github.com/5C-Plus/fivcglue#readme
|
|
8
|
+
Project-URL: Issues, https://github.com/5C-Plus/fivcglue/issues
|
|
9
|
+
Project-URL: Source, https://github.com/5C-Plus/fivcglue
|
|
10
|
+
Keywords: ddd,domain-driven-design,interface,architecture
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: Software Development :: Object Brokering
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: yaml
|
|
25
|
+
Requires-Dist: PyYAML>=6.0.1; extra == "yaml"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=8.2.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# FivcGlue
|
|
34
|
+
|
|
35
|
+
A Domain-Driven Design (DDD) programming package for Python, similar to `zope.interface`.
|
|
36
|
+
|
|
37
|
+
## 🎯 Overview
|
|
38
|
+
|
|
39
|
+
FivcGlue provides a clean and intuitive way to implement Domain-Driven Design patterns in Python applications. It offers interfaces and implementations for common DDD building blocks, helping you structure your code following DDD principles.
|
|
40
|
+
|
|
41
|
+
## 🚀 Quick Start
|
|
42
|
+
|
|
43
|
+
### Prerequisites
|
|
44
|
+
- Python 3.10 or higher
|
|
45
|
+
- UV package manager (recommended) or pip
|
|
46
|
+
|
|
47
|
+
### Installation
|
|
48
|
+
|
|
49
|
+
**With UV (recommended):**
|
|
50
|
+
```bash
|
|
51
|
+
# Install with development dependencies
|
|
52
|
+
make install
|
|
53
|
+
|
|
54
|
+
# Or minimal installation
|
|
55
|
+
make install-min
|
|
56
|
+
|
|
57
|
+
# With YAML support
|
|
58
|
+
uv sync --extra yaml
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**With pip:**
|
|
62
|
+
```bash
|
|
63
|
+
# Basic installation
|
|
64
|
+
pip install -e .
|
|
65
|
+
|
|
66
|
+
# With YAML support
|
|
67
|
+
pip install -e ".[yaml]"
|
|
68
|
+
|
|
69
|
+
# With development dependencies
|
|
70
|
+
pip install -e ".[dev,yaml]"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 📦 Features
|
|
74
|
+
|
|
75
|
+
FivcGlue provides core DDD building blocks:
|
|
76
|
+
|
|
77
|
+
- **Interfaces**: Define contracts for your domain components
|
|
78
|
+
- **Configurations**: Flexible configuration management (JSON, YAML)
|
|
79
|
+
- **Caching**: In-memory and Redis-based caching implementations
|
|
80
|
+
- **Logging**: Built-in logging utilities
|
|
81
|
+
- **Mutexes**: Distributed locking with Redis support
|
|
82
|
+
|
|
83
|
+
## 💻 Usage
|
|
84
|
+
|
|
85
|
+
### Basic Example
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from fivcglue.interfaces import IConfig
|
|
89
|
+
from fivcglue.implements import YAMLFileConfig
|
|
90
|
+
|
|
91
|
+
# Load configuration from YAML file
|
|
92
|
+
config = YAMLFileConfig("config.yml")
|
|
93
|
+
value = config.get("key", default="default_value")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Configuration Management
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from fivcglue.implements import JSONFileConfig, YAMLFileConfig
|
|
100
|
+
|
|
101
|
+
# JSON configuration
|
|
102
|
+
json_config = JSONFileConfig("settings.json")
|
|
103
|
+
|
|
104
|
+
# YAML configuration (requires PyYAML)
|
|
105
|
+
yaml_config = YAMLFileConfig("settings.yml")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Caching
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from fivcglue.implements import MemoryCache, RedisCache
|
|
112
|
+
|
|
113
|
+
# In-memory cache
|
|
114
|
+
cache = MemoryCache()
|
|
115
|
+
cache.set("key", "value", ttl=3600)
|
|
116
|
+
value = cache.get("key")
|
|
117
|
+
|
|
118
|
+
# Redis cache
|
|
119
|
+
redis_cache = RedisCache(host="localhost", port=6379)
|
|
120
|
+
redis_cache.set("key", "value", ttl=3600)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 📁 Project Structure
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
src/fivcglue/
|
|
127
|
+
├── interfaces/ # Interface definitions
|
|
128
|
+
│ ├── configs.py # Configuration interfaces
|
|
129
|
+
│ ├── caches.py # Cache interfaces
|
|
130
|
+
│ ├── loggers.py # Logger interfaces
|
|
131
|
+
│ └── mutexes.py # Mutex interfaces
|
|
132
|
+
├── implements/ # Concrete implementations
|
|
133
|
+
│ ├── configs_jsonfile.py
|
|
134
|
+
│ ├── configs_yamlfile.py
|
|
135
|
+
│ ├── caches_mem.py
|
|
136
|
+
│ ├── caches_redis.py
|
|
137
|
+
│ ├── loggers_builtin.py
|
|
138
|
+
│ └── mutexes_redis.py
|
|
139
|
+
└── fixtures/ # Test fixtures
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## 🛠️ Development
|
|
143
|
+
|
|
144
|
+
### Available Make Commands
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
make help # Show all available commands
|
|
148
|
+
make install # Install with dev dependencies
|
|
149
|
+
make install-min # Install minimal dependencies
|
|
150
|
+
make dev # Install development dependencies
|
|
151
|
+
make lint # Run code linting
|
|
152
|
+
make format # Format code
|
|
153
|
+
make test # Run tests
|
|
154
|
+
make test-cov # Run tests with coverage
|
|
155
|
+
make clean # Clean temporary files
|
|
156
|
+
make build # Build distribution packages
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Running Tests
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Run all tests
|
|
163
|
+
make test
|
|
164
|
+
|
|
165
|
+
# Run with coverage
|
|
166
|
+
make test-cov
|
|
167
|
+
|
|
168
|
+
# Run specific test file
|
|
169
|
+
uv run pytest tests/test_configs.py -v
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Code Quality
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Lint code
|
|
176
|
+
make lint
|
|
177
|
+
|
|
178
|
+
# Format code
|
|
179
|
+
make format
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## 📚 Documentation
|
|
183
|
+
|
|
184
|
+
For more detailed documentation, see the [docs/](docs/) directory:
|
|
185
|
+
|
|
186
|
+
- [Architecture](docs/ARCHITECTURE.md) - System architecture and design
|
|
187
|
+
- [Dependencies](docs/DEPENDENCIES.md) - Dependency management guide
|
|
188
|
+
|
|
189
|
+
## 🤝 Contributing
|
|
190
|
+
|
|
191
|
+
Contributions are welcome! Please feel free to submit issues and pull requests.
|
|
192
|
+
|
|
193
|
+
### Development Setup
|
|
194
|
+
|
|
195
|
+
1. Clone the repository
|
|
196
|
+
2. Install dependencies: `make install`
|
|
197
|
+
3. Run tests: `make test`
|
|
198
|
+
4. Format code: `make format`
|
|
199
|
+
5. Run linting: `make lint`
|
|
200
|
+
|
|
201
|
+
## 📄 License
|
|
202
|
+
|
|
203
|
+
MIT License - see LICENSE file for details
|
|
204
|
+
|
|
205
|
+
## 🔗 Links
|
|
206
|
+
|
|
207
|
+
- **Documentation**: [GitHub README](https://github.com/5C-Plus/fivcglue#readme)
|
|
208
|
+
- **Issues**: [GitHub Issues](https://github.com/5C-Plus/fivcglue/issues)
|
|
209
|
+
- **Source**: [GitHub Repository](https://github.com/5C-Plus/fivcglue)
|
fivcglue-0.1.0/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# FivcGlue
|
|
2
|
+
|
|
3
|
+
A Domain-Driven Design (DDD) programming package for Python, similar to `zope.interface`.
|
|
4
|
+
|
|
5
|
+
## 🎯 Overview
|
|
6
|
+
|
|
7
|
+
FivcGlue provides a clean and intuitive way to implement Domain-Driven Design patterns in Python applications. It offers interfaces and implementations for common DDD building blocks, helping you structure your code following DDD principles.
|
|
8
|
+
|
|
9
|
+
## 🚀 Quick Start
|
|
10
|
+
|
|
11
|
+
### Prerequisites
|
|
12
|
+
- Python 3.10 or higher
|
|
13
|
+
- UV package manager (recommended) or pip
|
|
14
|
+
|
|
15
|
+
### Installation
|
|
16
|
+
|
|
17
|
+
**With UV (recommended):**
|
|
18
|
+
```bash
|
|
19
|
+
# Install with development dependencies
|
|
20
|
+
make install
|
|
21
|
+
|
|
22
|
+
# Or minimal installation
|
|
23
|
+
make install-min
|
|
24
|
+
|
|
25
|
+
# With YAML support
|
|
26
|
+
uv sync --extra yaml
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**With pip:**
|
|
30
|
+
```bash
|
|
31
|
+
# Basic installation
|
|
32
|
+
pip install -e .
|
|
33
|
+
|
|
34
|
+
# With YAML support
|
|
35
|
+
pip install -e ".[yaml]"
|
|
36
|
+
|
|
37
|
+
# With development dependencies
|
|
38
|
+
pip install -e ".[dev,yaml]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 📦 Features
|
|
42
|
+
|
|
43
|
+
FivcGlue provides core DDD building blocks:
|
|
44
|
+
|
|
45
|
+
- **Interfaces**: Define contracts for your domain components
|
|
46
|
+
- **Configurations**: Flexible configuration management (JSON, YAML)
|
|
47
|
+
- **Caching**: In-memory and Redis-based caching implementations
|
|
48
|
+
- **Logging**: Built-in logging utilities
|
|
49
|
+
- **Mutexes**: Distributed locking with Redis support
|
|
50
|
+
|
|
51
|
+
## 💻 Usage
|
|
52
|
+
|
|
53
|
+
### Basic Example
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from fivcglue.interfaces import IConfig
|
|
57
|
+
from fivcglue.implements import YAMLFileConfig
|
|
58
|
+
|
|
59
|
+
# Load configuration from YAML file
|
|
60
|
+
config = YAMLFileConfig("config.yml")
|
|
61
|
+
value = config.get("key", default="default_value")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Configuration Management
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from fivcglue.implements import JSONFileConfig, YAMLFileConfig
|
|
68
|
+
|
|
69
|
+
# JSON configuration
|
|
70
|
+
json_config = JSONFileConfig("settings.json")
|
|
71
|
+
|
|
72
|
+
# YAML configuration (requires PyYAML)
|
|
73
|
+
yaml_config = YAMLFileConfig("settings.yml")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Caching
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from fivcglue.implements import MemoryCache, RedisCache
|
|
80
|
+
|
|
81
|
+
# In-memory cache
|
|
82
|
+
cache = MemoryCache()
|
|
83
|
+
cache.set("key", "value", ttl=3600)
|
|
84
|
+
value = cache.get("key")
|
|
85
|
+
|
|
86
|
+
# Redis cache
|
|
87
|
+
redis_cache = RedisCache(host="localhost", port=6379)
|
|
88
|
+
redis_cache.set("key", "value", ttl=3600)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 📁 Project Structure
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
src/fivcglue/
|
|
95
|
+
├── interfaces/ # Interface definitions
|
|
96
|
+
│ ├── configs.py # Configuration interfaces
|
|
97
|
+
│ ├── caches.py # Cache interfaces
|
|
98
|
+
│ ├── loggers.py # Logger interfaces
|
|
99
|
+
│ └── mutexes.py # Mutex interfaces
|
|
100
|
+
├── implements/ # Concrete implementations
|
|
101
|
+
│ ├── configs_jsonfile.py
|
|
102
|
+
│ ├── configs_yamlfile.py
|
|
103
|
+
│ ├── caches_mem.py
|
|
104
|
+
│ ├── caches_redis.py
|
|
105
|
+
│ ├── loggers_builtin.py
|
|
106
|
+
│ └── mutexes_redis.py
|
|
107
|
+
└── fixtures/ # Test fixtures
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 🛠️ Development
|
|
111
|
+
|
|
112
|
+
### Available Make Commands
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
make help # Show all available commands
|
|
116
|
+
make install # Install with dev dependencies
|
|
117
|
+
make install-min # Install minimal dependencies
|
|
118
|
+
make dev # Install development dependencies
|
|
119
|
+
make lint # Run code linting
|
|
120
|
+
make format # Format code
|
|
121
|
+
make test # Run tests
|
|
122
|
+
make test-cov # Run tests with coverage
|
|
123
|
+
make clean # Clean temporary files
|
|
124
|
+
make build # Build distribution packages
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Running Tests
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Run all tests
|
|
131
|
+
make test
|
|
132
|
+
|
|
133
|
+
# Run with coverage
|
|
134
|
+
make test-cov
|
|
135
|
+
|
|
136
|
+
# Run specific test file
|
|
137
|
+
uv run pytest tests/test_configs.py -v
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Code Quality
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Lint code
|
|
144
|
+
make lint
|
|
145
|
+
|
|
146
|
+
# Format code
|
|
147
|
+
make format
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## 📚 Documentation
|
|
151
|
+
|
|
152
|
+
For more detailed documentation, see the [docs/](docs/) directory:
|
|
153
|
+
|
|
154
|
+
- [Architecture](docs/ARCHITECTURE.md) - System architecture and design
|
|
155
|
+
- [Dependencies](docs/DEPENDENCIES.md) - Dependency management guide
|
|
156
|
+
|
|
157
|
+
## 🤝 Contributing
|
|
158
|
+
|
|
159
|
+
Contributions are welcome! Please feel free to submit issues and pull requests.
|
|
160
|
+
|
|
161
|
+
### Development Setup
|
|
162
|
+
|
|
163
|
+
1. Clone the repository
|
|
164
|
+
2. Install dependencies: `make install`
|
|
165
|
+
3. Run tests: `make test`
|
|
166
|
+
4. Format code: `make format`
|
|
167
|
+
5. Run linting: `make lint`
|
|
168
|
+
|
|
169
|
+
## 📄 License
|
|
170
|
+
|
|
171
|
+
MIT License - see LICENSE file for details
|
|
172
|
+
|
|
173
|
+
## 🔗 Links
|
|
174
|
+
|
|
175
|
+
- **Documentation**: [GitHub README](https://github.com/5C-Plus/fivcglue#readme)
|
|
176
|
+
- **Issues**: [GitHub Issues](https://github.com/5C-Plus/fivcglue/issues)
|
|
177
|
+
- **Source**: [GitHub Repository](https://github.com/5C-Plus/fivcglue)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fivcglue"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A Domain-Driven Design (DDD) programming package for Python, similar to zope.interface"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = ["ddd", "domain-driven-design", "interface", "architecture"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Charlie ZHANG", email = "sunnypig2002@gmail.com" },
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Programming Language :: Python",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Topic :: Software Development :: Object Brokering",
|
|
27
|
+
]
|
|
28
|
+
dependencies = []
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
yaml = ["PyYAML>=6.0.1"]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=8.2.0",
|
|
34
|
+
"pytest-asyncio>=0.21.0",
|
|
35
|
+
"pytest-cov>=4.1.0",
|
|
36
|
+
"ruff>=0.4.0",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Documentation = "https://github.com/5C-Plus/fivcglue#readme"
|
|
41
|
+
Issues = "https://github.com/5C-Plus/fivcglue/issues"
|
|
42
|
+
Source = "https://github.com/5C-Plus/fivcglue"
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
where = ["src"]
|
|
46
|
+
|
|
47
|
+
[tool.coverage.run]
|
|
48
|
+
source_pkgs = ["fivcglue", "tests"]
|
|
49
|
+
branch = true
|
|
50
|
+
parallel = true
|
|
51
|
+
omit = [
|
|
52
|
+
"src/fivcglue/__about__.py",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.coverage.paths]
|
|
56
|
+
fivcglue = ["src/fivcglue", "*/fivcglue/src/fivcglue"]
|
|
57
|
+
tests = ["tests", "*/fivcglue/tests"]
|
|
58
|
+
|
|
59
|
+
[tool.coverage.report]
|
|
60
|
+
exclude_lines = [
|
|
61
|
+
"no cov",
|
|
62
|
+
"if __name__ == .__main__.:",
|
|
63
|
+
"if TYPE_CHECKING:",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[tool.pytest.ini_options]
|
|
67
|
+
# Test discovery settings
|
|
68
|
+
testpaths = ["tests"]
|
|
69
|
+
python_files = ["test_*.py", "*_test.py"]
|
|
70
|
+
python_classes = ["Test*"]
|
|
71
|
+
python_functions = ["test_*"]
|
|
72
|
+
|
|
73
|
+
# Additional pytest options
|
|
74
|
+
addopts = [
|
|
75
|
+
"--strict-markers",
|
|
76
|
+
"--strict-config",
|
|
77
|
+
"--verbose",
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
# Markers for test categorization
|
|
81
|
+
markers = [
|
|
82
|
+
"asyncio: marks tests as async (deselect with '-m \"not asyncio\"')",
|
|
83
|
+
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
# Suppress warnings for cleaner output
|
|
87
|
+
filterwarnings = [
|
|
88
|
+
"ignore::DeprecationWarning",
|
|
89
|
+
"ignore::PendingDeprecationWarning",
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
[tool.ruff]
|
|
93
|
+
line-length = 100
|
|
94
|
+
target-version = "py310"
|
|
95
|
+
|
|
96
|
+
[tool.ruff.lint]
|
|
97
|
+
select = [
|
|
98
|
+
"E", # pycodestyle errors
|
|
99
|
+
"W", # pycodestyle warnings
|
|
100
|
+
"F", # pyflakes
|
|
101
|
+
"I", # isort
|
|
102
|
+
"B", # flake8-bugbear
|
|
103
|
+
"C4", # flake8-comprehensions
|
|
104
|
+
"UP", # pyupgrade
|
|
105
|
+
]
|
|
106
|
+
ignore = [
|
|
107
|
+
"E501", # line too long (handled by formatter)
|
|
108
|
+
"B008", # do not perform function calls in argument defaults
|
|
109
|
+
"C901", # too complex
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
[tool.ruff.format]
|
|
113
|
+
quote-style = "double"
|
|
114
|
+
indent-style = "space"
|
fivcglue-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TextIO
|
|
4
|
+
|
|
5
|
+
from fivcglue import (
|
|
6
|
+
IComponent,
|
|
7
|
+
IComponentSite,
|
|
8
|
+
IComponentSiteBuilder,
|
|
9
|
+
)
|
|
10
|
+
from fivcglue import (
|
|
11
|
+
utils as i_utils,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ComponentSite(IComponentSite):
|
|
16
|
+
"""
|
|
17
|
+
default implementation of IComponentSite
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self):
|
|
21
|
+
self.service_mapping: dict[type, dict[str, IComponent]] = {}
|
|
22
|
+
|
|
23
|
+
def get_component(
|
|
24
|
+
self,
|
|
25
|
+
interface: type,
|
|
26
|
+
name: str = "",
|
|
27
|
+
) -> IComponent:
|
|
28
|
+
component = self.query_component(interface, name=name)
|
|
29
|
+
if not component:
|
|
30
|
+
err_msg = "component not found"
|
|
31
|
+
raise LookupError(err_msg)
|
|
32
|
+
return component
|
|
33
|
+
|
|
34
|
+
def query_component(
|
|
35
|
+
self,
|
|
36
|
+
interface: type,
|
|
37
|
+
name: str = "",
|
|
38
|
+
) -> IComponent | None:
|
|
39
|
+
component = self.service_mapping.get(interface)
|
|
40
|
+
return component and component.get(name)
|
|
41
|
+
|
|
42
|
+
def register_component(
|
|
43
|
+
self,
|
|
44
|
+
interface: type,
|
|
45
|
+
implement: IComponent,
|
|
46
|
+
name: str = "",
|
|
47
|
+
) -> IComponent:
|
|
48
|
+
if not issubclass(implement.__class__, interface):
|
|
49
|
+
err_msg = "incorrect implementation for component interface"
|
|
50
|
+
raise TypeError(err_msg)
|
|
51
|
+
|
|
52
|
+
mapping = self.service_mapping.setdefault(interface, {})
|
|
53
|
+
mapping.update({name: implement})
|
|
54
|
+
return implement
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ComponentSiteBuilder(IComponentSiteBuilder):
|
|
58
|
+
"""
|
|
59
|
+
default implementation of ServiceBuilder
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def _loads(component_site: IComponentSite, configs: tuple | list):
|
|
64
|
+
if not isinstance(configs, (tuple, list)):
|
|
65
|
+
err_msg = "invalid component configuration file"
|
|
66
|
+
raise TypeError(err_msg)
|
|
67
|
+
|
|
68
|
+
for config_item in configs:
|
|
69
|
+
service_class_name = config_item.pop("class", "")
|
|
70
|
+
service_entries_name = config_item.pop("entries", [])
|
|
71
|
+
if not isinstance(service_entries_name, (tuple, list)):
|
|
72
|
+
err_msg = "invalid component entries in configuration file"
|
|
73
|
+
raise TypeError(err_msg)
|
|
74
|
+
try:
|
|
75
|
+
service_class = i_utils.import_string(service_class_name)
|
|
76
|
+
except ImportError as e:
|
|
77
|
+
err_msg = f"invalid component class {service_class_name}"
|
|
78
|
+
raise LookupError(err_msg) from e
|
|
79
|
+
|
|
80
|
+
service_instance = service_class(component_site, **config_item)
|
|
81
|
+
for e in service_entries_name:
|
|
82
|
+
if not isinstance(e, dict):
|
|
83
|
+
err_msg = "invalid component entry in configuration file"
|
|
84
|
+
raise TypeError(err_msg)
|
|
85
|
+
|
|
86
|
+
service_name = e.get("name", "")
|
|
87
|
+
service_interface_name = e.get("interface", "")
|
|
88
|
+
try:
|
|
89
|
+
service_interface = i_utils.import_string(service_interface_name)
|
|
90
|
+
except ImportError as e:
|
|
91
|
+
err_msg = f"invalid component interface {service_interface_name}"
|
|
92
|
+
raise LookupError(err_msg) from e
|
|
93
|
+
|
|
94
|
+
component_site.register_component(
|
|
95
|
+
service_interface, service_instance, name=service_name
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def _parse(self, configs: TextIO, fmt: str = "json"):
|
|
99
|
+
if fmt == "json":
|
|
100
|
+
import json
|
|
101
|
+
|
|
102
|
+
return json.loads(configs.read())
|
|
103
|
+
|
|
104
|
+
if fmt in ["yaml", "yml"]:
|
|
105
|
+
import yaml
|
|
106
|
+
|
|
107
|
+
return yaml.safe_load(configs.read())
|
|
108
|
+
|
|
109
|
+
err_msg = f"Unknown file format {fmt}"
|
|
110
|
+
raise NotImplementedError(err_msg)
|
|
111
|
+
|
|
112
|
+
def loads(
|
|
113
|
+
self,
|
|
114
|
+
component_site: IComponentSite,
|
|
115
|
+
configs: TextIO,
|
|
116
|
+
fmt: str = "json",
|
|
117
|
+
):
|
|
118
|
+
self._loads(component_site, self._parse(configs, fmt))
|
|
119
|
+
|
|
120
|
+
def dumps(
|
|
121
|
+
self,
|
|
122
|
+
component_site: IComponentSite,
|
|
123
|
+
configs: TextIO,
|
|
124
|
+
fmt: str = "json",
|
|
125
|
+
):
|
|
126
|
+
raise NotImplementedError
|