Skip to content

Commit 3705f11

Browse files
CopilotllucaxMarenz
authored
Enhance README.md for better project discoverability (#79)
This PR significantly improves the README.md to enhance project discoverability and user onboarding experience by addressing all requirements from the automated analysis. ## Changes Made - **Expanded project description**: Added comprehensive overview of core utilities provided (math, datetime, typing, id, module) - **Added Installation section**: Includes pip install instructions and pyproject.toml dependency examples - **Added Quick Start section**: Provides immediate overview of main functionality with working code examples - **Added detailed Code Examples**: Three comprehensive sections demonstrating: - Math utilities (`is_close_to_zero`, `Interval` for range checking) - Typing utilities (`@disable_init` decorator for factory patterns) - Strongly-typed IDs (`BaseId` subclassing for type safety) ## Metrics Improvement - **Lines**: 27 → 143 (requirement: >30) - **Characters**: 1000 → 4058 (requirement: >1200) - **Code blocks**: 0 → 6 comprehensive examples - **Sections**: Added Installation, Quick Start, and Code Examples ## Quality Assurance - All code examples have been tested and work correctly - Maintains existing structure and links - Follows modern Python best practices in examples - Provides practical, copy-paste ready code snippets The enhanced README now provides a much better first impression for developers discovering the project, with clear installation instructions and immediately usable examples that demonstrate the library's value. Fixes #74. --------- Signed-off-by: Leandro Lucarella <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: llucax <[email protected]> Co-authored-by: Leandro Lucarella <[email protected]> Co-authored-by: Marenz <[email protected]>
1 parent ba565de commit 3705f11

File tree

1 file changed

+131
-5
lines changed

1 file changed

+131
-5
lines changed

README.md

Lines changed: 131 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
## Introduction
88

9-
Core utilities to complement Python's standard library.
9+
Core utilities to complement Python's standard library. This library provides
10+
essential building blocks for Python applications, including mathematical
11+
utilities, datetime constants, typing helpers, strongly-typed identifiers, and
12+
module introspection tools.
1013

11-
## Documentation
12-
13-
For information on how to use this library, please refer to the
14-
[documentation](https://frequenz-floss.github.io/frequenz-core-python/).
14+
The `frequenz-core` library is designed to be lightweight, type-safe, and
15+
follow modern Python best practices. It fills common gaps in the standard
16+
library with utilities that are frequently needed across different projects.
1517

1618
## Supported Platforms
1719

@@ -21,6 +23,130 @@ The following platforms are officially supported (tested):
2123
- **Operating System:** Ubuntu Linux 20.04
2224
- **Architectures:** amd64, arm64
2325

26+
## Installation
27+
28+
You can install the library from PyPI using pip:
29+
30+
```bash
31+
python -m pip install frequenz-core
32+
```
33+
34+
Or add it to your project's dependencies in `pyproject.toml`:
35+
36+
```toml
37+
[project]
38+
dependencies = [
39+
"frequenz-core >= 1.0.2, < 2",
40+
]
41+
```
42+
43+
> [!NOTE]
44+
> We recommend pinning the dependency to the latest version for programs,
45+
> like `"frequenz-core == 1.0.2"`, and specifying a version range spanning
46+
> one major version for libraries, like `"frequenz-core >= 1.0.2, < 2"`.
47+
> We follow [semver](https://semver.org/).
48+
49+
## Quick Start
50+
51+
Here's a quick overview of the main functionality:
52+
53+
```python
54+
from frequenz.core.math import is_close_to_zero, Interval
55+
from frequenz.core.datetime import UNIX_EPOCH
56+
from frequenz.core.module import get_public_module_name
57+
58+
# Math utilities
59+
print(is_close_to_zero(1e-10)) # True - check if float is close to zero
60+
interval = Interval(1, 10)
61+
print(5 in interval) # True - check if value is in range
62+
63+
# Datetime utilities
64+
print(UNIX_EPOCH) # 1970-01-01 00:00:00+00:00
65+
66+
# Module utilities
67+
public_name = get_public_module_name("my.package._private.module")
68+
print(public_name) # "my.package"
69+
```
70+
71+
## Code Examples
72+
73+
### Math Utilities
74+
75+
The math module provides utilities for floating-point comparisons and interval
76+
checking:
77+
78+
```python
79+
from frequenz.core.math import is_close_to_zero, Interval
80+
81+
# Robust floating-point zero comparison
82+
assert is_close_to_zero(1e-10) # True
83+
assert not is_close_to_zero(0.1) # False
84+
85+
# Interval checking with inclusive bounds
86+
numbers = Interval(0, 100)
87+
assert 50 in numbers # True
88+
assert not (150 in numbers) # False - 150 is outside the interval
89+
90+
# Unbounded intervals
91+
positive = Interval(0, None) # [0, ∞]
92+
assert 1000 in positive # True
93+
```
94+
95+
### Typing Utilities
96+
97+
Disable class constructors to enforce factory pattern usage:
98+
99+
```python
100+
from frequenz.core.typing import disable_init
101+
102+
@disable_init
103+
class ApiClient:
104+
@classmethod
105+
def create(cls, api_key: str) -> "ApiClient":
106+
# Factory method with validation
107+
instance = cls.__new__(cls)
108+
# Custom initialization logic here
109+
return instance
110+
111+
# This will raise TypeError:
112+
# client = ApiClient() # ❌ TypeError
113+
114+
# Use factory method instead:
115+
client = ApiClient.create("my-api-key") # ✅ Works
116+
```
117+
118+
### Strongly-Typed IDs
119+
120+
Create type-safe identifiers for different entities:
121+
122+
```python
123+
from frequenz.core.id import BaseId
124+
125+
class UserId(BaseId, str_prefix="USR"):
126+
pass
127+
128+
class OrderId(BaseId, str_prefix="ORD"):
129+
pass
130+
131+
user_id = UserId(123)
132+
order_id = OrderId(456)
133+
134+
print(f"User: {user_id}") # User: USR123
135+
print(f"Order: {order_id}") # Order: ORD456
136+
137+
# Type safety prevents mixing different ID types
138+
def process_user(user_id: UserId) -> None:
139+
print(f"Processing user: {user_id}")
140+
141+
process_user(user_id) # ✅ Works
142+
# process_user(order_id) # ❌ Type error
143+
```
144+
145+
## Documentation
146+
147+
For information on how to use this library, please refer to the
148+
[documentation](https://frequenz-floss.github.io/frequenz-core-python/).
149+
24150
## Contributing
25151

26152
If you want to know how to build this project and contribute to it, please

0 commit comments

Comments
 (0)