Skip to content

Commit 640993f

Browse files
committed
docs(contrib): add contributing guidelines and update documentation
- Add CONTRIBUTING.md file with guidelines for bug reporting, enhancements, and code contributions - Create CONTRIBUTING.rst for Sphinx documentation - Update index.rst to include CONTRIBUTING in the contents - Make minor code improvements in utils.py and _catches.py
1 parent 094d7ab commit 640993f

File tree

5 files changed

+200
-7
lines changed

5 files changed

+200
-7
lines changed

CONTRIBUTING.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Contributing
2+
3+
Thank you for your interest in contributing to redis_func_cache! This document provides guidelines and information to help you contribute effectively to the project.
4+
5+
## Code of Conduct
6+
7+
By participating in this project, you are expected to uphold our Code of Conduct, which promotes a welcoming and inclusive environment for all contributors.
8+
9+
## How to Contribute
10+
11+
### Reporting Bugs
12+
13+
Before reporting a bug, please check the existing issues to see if it has been reported. If not, create a new issue with:
14+
15+
- A clear and descriptive title
16+
- A detailed description of the problem
17+
- Steps to reproduce the issue
18+
- Expected vs. actual behavior
19+
- Your environment information (Python version, Redis version, OS, etc.)
20+
21+
### Suggesting Enhancements
22+
23+
We welcome feature requests and suggestions. To propose an enhancement:
24+
25+
1. Check existing issues to avoid duplicates
26+
2. Create a new issue with a clear title and detailed description
27+
3. Explain why this enhancement would be useful
28+
4. If possible, provide examples of how the feature would be used
29+
30+
### Code Contributions
31+
32+
#### Development Setup
33+
34+
1. Fork the repository
35+
2. Clone your fork:
36+
```bash
37+
git clone https://github.com/your-username/redis_func_cache.git
38+
cd redis_func_cache
39+
```
40+
3. Install [uv](https://docs.astral.sh/uv/) if you haven't already:
41+
```bash
42+
# On macOS and Linux
43+
curl -LsSf https://astral.sh/uv/install.sh | sh
44+
45+
# On Windows
46+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
47+
48+
# Or using pip
49+
pip install uv
50+
```
51+
4. Create a virtual environment and install dependencies:
52+
```bash
53+
uv venv
54+
uv sync --all-extras --dev
55+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
56+
```
57+
58+
#### Running Tests
59+
60+
Before submitting changes, ensure all tests pass:
61+
62+
```bash
63+
# Run all tests
64+
uv run pytest
65+
66+
# Run tests with coverage
67+
uv run pytest --cov=src
68+
69+
# Run specific test categories
70+
uv run pytest tests/test_basic.py
71+
```
72+
73+
#### Code Style
74+
75+
We use several tools to maintain code quality:
76+
77+
- **Ruff**: For linting and formatting. Check <https://docs.astral.sh/ruff/> for more details.
78+
- **MyPy**: For static type checking. Check <https://mypy.readthedocs.io/en/stable/> for more details.
79+
- **Pre-commit hooks**: To automatically check code before committing. Check <https://pre-commit.com/> for more details.
80+
81+
You should install them before making changes.
82+
83+
To run checks manually:
84+
85+
```bash
86+
# Run all pre-commit checks
87+
uv run pre-commit run --all-files
88+
89+
# Run specific checks
90+
uv run ruff check .
91+
uv run ruff format .
92+
uv run mypy src
93+
```
94+
95+
#### Making Changes
96+
97+
1. Create a new branch for your feature or bugfix:
98+
```bash
99+
git checkout -b feature/your-feature-name
100+
```
101+
2. Make your changes, following the code style guidelines
102+
103+
3. Add tests for new functionality
104+
105+
4. Ensure all tests pass (you shall run redis server on localhost:6379 before running tests):
106+
107+
```bash
108+
uv run pytest
109+
```
110+
111+
If the changes are concerned with Redis cluster, it is recommended to run the tests against a Redis cluster by docker compose:
112+
113+
```bash
114+
cd docker
115+
docker compose up
116+
```
117+
118+
If you have standalone Redis server(s) running, you can run the tests against it/them by setting the environment variables
119+
120+
- `REDIS_URL`: url for the single Redis server
121+
- `REDIS_CLUSTER_NODES`: `":"` split list of Redis cluster nodes
122+
123+
A `.env` file can be used to set the environment variables.
124+
125+
5. Commit your changes with a clear, descriptive commit message
126+
127+
6. Push to your fork and submit a pull request
128+
129+
### Pull Request Guidelines
130+
131+
When submitting a pull request:
132+
133+
1. Provide a clear title and description
134+
2. Reference any related issues
135+
3. Ensure your code follows the project's style guidelines
136+
4. Include tests for new functionality
137+
5. Update documentation as needed
138+
6. Keep pull requests focused on a single feature or bugfix
139+
140+
### Documentation
141+
142+
Improvements to documentation are always welcome. This includes:
143+
144+
- Updates to README.md
145+
- Docstring improvements
146+
- Examples and tutorials
147+
- Comments in code
148+
149+
## Development Practices
150+
151+
### Lua Scripts
152+
153+
This project uses Redis Lua scripts for atomic operations. When modifying Lua scripts:
154+
155+
1. Ensure scripts remain atomic and efficient
156+
2. Test with various Redis versions
157+
3. Keep scripts readable and well-commented
158+
4. Follow existing patterns in the codebase
159+
160+
### Testing
161+
162+
We maintain high test coverage and follow these practices:
163+
164+
1. Write unit tests for new functionality
165+
2. Test both synchronous and asynchronous code paths
166+
3. Include edge cases and error conditions
167+
4. Test with different cache policies
168+
5. Use appropriate mocking when needed
169+
170+
### Versioning
171+
172+
We follow [Semantic Versioning](https://semver.org/). Changes are categorized as:
173+
174+
- **Major**: Breaking changes
175+
- **Minor**: New features (backward compatible)
176+
- **Patch**: Bug fixes (backward compatible)
177+
178+
## Getting Help
179+
180+
If you need help with your contribution:
181+
182+
1. Check the documentation and existing issues
183+
2. Join our community discussions
184+
3. Contact the maintainers directly
185+
186+
## License
187+
188+
By contributing to redis_func_cache, you agree that your contributions will be licensed under the BSD 3-Clause License.

docs/CONTRIBUTING.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONTRIBUTING
2+
############
3+
4+
.. include:: ../CONTRIBUTING.md
5+
:parser: myst_parser.sphinx_

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Contents
4040

4141
README
4242
CHANGELOG
43+
CONTRIBUTING
4344
AUTHORS
4445
LICENSE
4546

src/redis_func_cache/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def clean_lua_script(source: str) -> str:
111111
code = "".join(tok_str for _, tok_str in lexer.get_tokens(source))
112112
# remote empty lines
113113
return "\n".join(s for line in code.splitlines() if (s := line.strip()))
114-
115114
else: # pragma: no cover
116115
return source
117116

tests/_catches.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ async def close_async_redis_client():
6060
global async_redis_client
6161
if async_redis_client is not None:
6262
# 使用 aclose() 而不是 close() 以避免弃用警告
63-
if hasattr(async_redis_client, "aclose"):
64-
await async_redis_client.aclose()
63+
if aclose := getattr(async_redis_client, "aclose", None):
64+
await aclose()
6565
else:
6666
await async_redis_client.close()
6767
async_redis_client = None
@@ -153,8 +153,8 @@ async def close_all_async_resources():
153153
tasks = []
154154
for cache in ASYNC_CACHES.values():
155155
try:
156-
if hasattr(cache.client, "aclose"):
157-
tasks.append(cache.client.aclose())
156+
if aclose := getattr(cache.client, "aclose", None):
157+
tasks.append(aclose())
158158
elif hasattr(cache.client, "close"):
159159
tasks.append(cache.client.close())
160160
except Exception:
@@ -163,8 +163,8 @@ async def close_all_async_resources():
163163

164164
for cache in ASYNC_MULTI_CACHES.values():
165165
try:
166-
if hasattr(cache.client, "aclose"):
167-
tasks.append(cache.client.aclose())
166+
if aclose := getattr(cache.client, "aclose", None):
167+
tasks.append(aclose())
168168
elif hasattr(cache.client, "close"):
169169
tasks.append(cache.client.close())
170170
except Exception:

0 commit comments

Comments
 (0)