|
| 1 | +# You Can You Up (UCUU) 🚀 |
| 2 | +-------- |
| 3 | +[](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 | + |
0 commit comments