Skip to content

Commit 2fca72c

Browse files
committed
[feat] ucuu demo v0.1.0
0 parents  commit 2fca72c

20 files changed

+750
-0
lines changed

.github/workflows/gh-pages.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Deploy Pages
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
7+
jobs:
8+
deploy:
9+
permissions:
10+
pages: write
11+
id-token: write
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Pages
17+
uses: actions/configure-pages@v4
18+
19+
- name: Build with Jekyll
20+
uses: actions/jekyll-build-pages@v1
21+
with:
22+
source: ./
23+
destination: ./_site
24+
25+
- name: Upload artifact
26+
uses: actions/upload-pages-artifact@v3
27+
with:
28+
path: ./_site
29+
30+
- name: Deploy to GitHub Pages
31+
uses: actions/deploy-pages@v4
32+
env:
33+
GH_TOKEN: ${{ secrets.GH_TOKEN }}

.github/workflows/publish.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
build-and-publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Install requirements
15+
run: |
16+
if [ -f requirements.txt ]; then
17+
python -m pip install --upgrade -r requirements.txt
18+
fi
19+
python -m pip install --upgrade toml
20+
21+
- name: Check version matches tag
22+
id: check_version
23+
run: |
24+
TAG_VERSION="${GITHUB_REF##*/}"
25+
FILE_VERSION=$(python3 -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
26+
if [ "$TAG_VERSION" != "v$FILE_VERSION" ]; then
27+
echo "Tag version ($TAG_VERSION) does not match pyproject.toml version ($FILE_VERSION)."
28+
echo "should_publish=false" >> $GITHUB_OUTPUT
29+
else
30+
echo "should_publish=true" >> $GITHUB_OUTPUT
31+
fi
32+
33+
- name: Set up Python
34+
if: steps.check_version.outputs.should_publish == 'true'
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: '3.8'
38+
39+
- name: Install build dependencies
40+
if: steps.check_version.outputs.should_publish == 'true'
41+
run: python -m pip install --upgrade build
42+
43+
- name: Build package
44+
if: steps.check_version.outputs.should_publish == 'true'
45+
run: python -m build
46+
47+
- name: Publish to PyPI
48+
if: steps.check_version.outputs.should_publish == 'true'
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
with:
51+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/python-app.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Tests
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python 3.10
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.10"
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install flake8 pytest
30+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31+
- name: Lint with flake8
32+
run: |
33+
# stop the build if there are Python syntax errors or undefined names
34+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
35+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
36+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37+
- name: Test with pytest
38+
run: |
39+
pytest

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.venv/
2+
.pytets*
3+
*.egg-info
4+
.python-version/
5+
.vscode/

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 24.4.2
4+
hooks:
5+
- id: black
6+
language_version: python3.8

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# You Can You Up (UCUU) 🚀
2+
--------
3+
[![Deploy GitHub Pages](https://github.com/wZuck/ucuu/actions/workflows/gh-pages.yml/badge.svg?branch=master)](https://github.com/wZuck/ucuu/actions/workflows/gh-pages.yml)
4+
5+
6+
> **⚠️ Important:**
7+
> The majority of the code in this repository is generated using AI coding tools such as GitHub Copilot (GPT-4o) and TRAE (Doubao 1.5 Pro).
8+
9+
## 1. Brief Introduction
10+
11+
**UCUU** is a Python utility library for function wrapping and proxying. It supports adding proxy logic to functions via decorators or patching, making it easy to extend, debug, and test.
12+
13+
---
14+
15+
## 2. Install and Usage ⚙️
16+
17+
### 2.1 Installation
18+
19+
You can install UCUU from PyPI:
20+
21+
```bash
22+
pip install ucuu
23+
```
24+
25+
Or, clone this repository and install locally:
26+
27+
```bash
28+
git clone https://github.com/wZuck/ucuu.git
29+
cd ucuu
30+
pip install .
31+
```
32+
33+
### 2.2 Usage
34+
35+
#### 2.2.1 Decorator mode (wrap for functions)
36+
37+
> Example: Use a decorator to add a proxy function.
38+
> **Effect:** When `my_func` is called, it prints "My function logic" and then the proxy prints "Hello, hello ucuu".
39+
40+
```python
41+
from ucuu.decorator import ucuu
42+
43+
@ucuu("package_utils.print_ucuu_hello", ending_words="hello ucuu")
44+
def my_func():
45+
print("My function logic")
46+
```
47+
48+
#### 2.2.2 Patch mode (wrap for external functions)
49+
50+
> Example: Patch an existing function with a proxy.
51+
> **Effect:** When `some_func` is called, it prints "Original logic" and then the proxy prints "Hello, patch mode".
52+
53+
```python
54+
from ucuu.decorator import ucuu
55+
56+
def some_func():
57+
print("Original logic")
58+
59+
some_func = ucuu("package_utils.print_ucuu_hello", ending_words="patch mode")(some_func)
60+
```
61+
62+
#### 2.2.3 Register proxy functions
63+
64+
> Example: Implement a proxy function to be called by the decorator or patch.
65+
> **Effect:** Prints different messages depending on the `ending_words` argument.
66+
67+
```python
68+
# tests/package_utils/test_print.py
69+
def print_ucuu_hello(ending_words=None, *args, **kwargs):
70+
if ending_words is None:
71+
print("No Ending Words.")
72+
elif ending_words == "please raise errors":
73+
raise NotImplementedError('Raise Error due to requests')
74+
else:
75+
print(f"Hello, {ending_words}")
76+
```
77+
78+
---
79+
80+
## 3. Demos in Testcases 🧪
81+
82+
- See the `tests/` directory for test cases covering decorator usage, patching, exception handling, argument binding, and more.
83+
84+
85+
---
86+
87+
## 4. License 📄
88+
89+
[MIT License](./LICENSE)
90+
91+
---
92+
93+
## 5. Contribute 🤝
94+
95+
Contributions via PR or issues are welcome!
96+
For suggestions or questions, please leave a message at [GitHub Issues](https://github.com/wZuck/ucuu/issues).
97+
98+
---
99+

pyproject.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[project]
2+
name = "ucuu"
3+
version = "0.1.0"
4+
description = "A lightweight and extensible Python utility toolkit for productivity and automation."
5+
readme = "README.md"
6+
license = { file = "LICENSE" }
7+
requires-python = ">=3.8"
8+
dependencies = [
9+
"rich>=14.0.0",
10+
"black>=24.0.0",
11+
]
12+
classifiers = [
13+
"Programming Language :: Python :: 3",
14+
"Programming Language :: Python :: 3.8",
15+
"License :: OSI Approved :: MIT License",
16+
"Operating System :: OS Independent",
17+
"Intended Audience :: Developers",
18+
"Topic :: Software Development :: Libraries :: Python Modules"
19+
]
20+
authors = [
21+
{ name = "wZuck", email = "wzuck.wang@gmail.com" }
22+
]
23+
[project.urls]
24+
homepage = "https://wzuck.github.io/ucuu/"
25+
repository = "https://github.com/wZuck/ucuu"
26+
documentation = "https://github.com/wZuck/ucuu"
27+
pypi = "https://pypi.org/project/ucuu/"
28+
29+
[tool.black]
30+
line-length = 88
31+
target-version = ['py38']
32+
33+
[tool.pre-commit]
34+
35+
[project.optional-dependencies]
36+
docs = [
37+
"ghp-import>=2.1.0"
38+
]
39+
publish = [
40+
"build>=1.0.0",
41+
"twine>=4.0.0"
42+
]

requirements.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile pyproject.toml --output-file requirements.txt
3+
black==24.8.0
4+
# via ucuu (pyproject.toml)
5+
click==8.1.8
6+
# via black
7+
markdown-it-py==3.0.0
8+
# via rich
9+
mdurl==0.1.2
10+
# via markdown-it-py
11+
mypy-extensions==1.1.0
12+
# via black
13+
packaging==25.0
14+
# via black
15+
pathspec==0.12.1
16+
# via black
17+
platformdirs==4.3.6
18+
# via black
19+
pygments==2.19.1
20+
# via rich
21+
rich==14.0.0
22+
# via ucuu (pyproject.toml)
23+
tomli==2.2.1
24+
# via black
25+
typing-extensions==4.13.2
26+
# via
27+
# black
28+
# rich

0 commit comments

Comments
 (0)