Skip to content

Commit 2c92106

Browse files
committed
feat: add GitHub release downloads badge and hooks disable env vars
- Add GitHub Release downloads badge to README.md and README_zh.md - Add MAYA_UMBRELLA_DISABLE_ALL_HOOKS env var to disable all hooks - Add MAYA_UMBRELLA_DISABLE_HOOKS env var to disable specific hooks by name - Update documentation with new environment variables
1 parent acdf7ff commit 2c92106

File tree

4 files changed

+191
-1
lines changed

4 files changed

+191
-1
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![Downloads](https://static.pepy.tech/badge/maya-umbrella)](https://pepy.tech/project/maya-umbrella)
99
[![Downloads](https://static.pepy.tech/badge/maya-umbrella/month)](https://pepy.tech/project/maya-umbrella)
1010
[![Downloads](https://static.pepy.tech/badge/maya-umbrella/week)](https://pepy.tech/project/maya-umbrella)
11+
[![GitHub Release](https://img.shields.io/github/downloads/loonghao/maya_umbrella/total?label=GitHub%20Downloads)](https://github.com/loonghao/maya_umbrella/releases)
1112
[![License](https://img.shields.io/pypi/l/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
1213
[![PyPI Format](https://img.shields.io/pypi/format/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
1314
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/loonghao/maya-umbrella/graphs/commit-activity)
@@ -177,6 +178,34 @@ nox -s maya -- 2018 --install-root /your/local/maya/root
177178

178179
```
179180

181+
## Hooks Control
182+
183+
Disable all hooks. When set to `true`, no hooks will be executed.
184+
```shell
185+
MAYA_UMBRELLA_DISABLE_ALL_HOOKS
186+
```
187+
If you want to disable all hooks:
188+
```shell
189+
SET MAYA_UMBRELLA_DISABLE_ALL_HOOKS=true
190+
```
191+
192+
Disable specific hooks by name. Use a comma-separated list of hook names (without `.py` extension).
193+
194+
Available hooks:
195+
- `delete_turtle` - Remove Turtle plugin and related nodes
196+
- `delete_unknown_plugin_node` - Remove unknown plugin nodes
197+
- `fix_model_panel` - Fix model panel issues
198+
- `fix_no_scene_name` - Fix scenes without names
199+
- `fix_on_model_change_3dc` - Fix 3D Coat model change callback
200+
201+
```shell
202+
MAYA_UMBRELLA_DISABLE_HOOKS
203+
```
204+
For example, to disable the `delete_turtle` and `delete_unknown_plugin_node` hooks:
205+
```shell
206+
SET MAYA_UMBRELLA_DISABLE_HOOKS=delete_turtle,delete_unknown_plugin_node
207+
```
208+
180209
# API
181210

182211
Get virus files that have not been repaired in the current scenario.

README_zh.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![Downloads](https://static.pepy.tech/badge/maya-umbrella)](https://pepy.tech/project/maya-umbrella)
99
[![Downloads](https://static.pepy.tech/badge/maya-umbrella/month)](https://pepy.tech/project/maya-umbrella)
1010
[![Downloads](https://static.pepy.tech/badge/maya-umbrella/week)](https://pepy.tech/project/maya-umbrella)
11+
[![GitHub Release](https://img.shields.io/github/downloads/loonghao/maya_umbrella/total?label=GitHub%20Downloads)](https://github.com/loonghao/maya_umbrella/releases)
1112
[![License](https://img.shields.io/pypi/l/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
1213
[![PyPI Format](https://img.shields.io/pypi/format/maya-umbrella)](https://pypi.org/project/maya-umbrella/)
1314
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/loonghao/maya-umbrella/graphs/commit-activity)
@@ -165,6 +166,34 @@ nox -s maya -- 2018 --install-root /your/local/maya/root
165166

166167
```
167168

169+
## Hooks 控制
170+
171+
禁用所有 hooks。设置为 `true` 时,不会执行任何 hooks。
172+
```shell
173+
MAYA_UMBRELLA_DISABLE_ALL_HOOKS
174+
```
175+
如果你想禁用所有 hooks:
176+
```shell
177+
SET MAYA_UMBRELLA_DISABLE_ALL_HOOKS=true
178+
```
179+
180+
按名称禁用特定的 hooks。使用逗号分隔的 hook 名称列表(不需要 `.py` 扩展名)。
181+
182+
可用的 hooks:
183+
- `delete_turtle` - 删除 Turtle 插件及相关节点
184+
- `delete_unknown_plugin_node` - 删除未知插件节点
185+
- `fix_model_panel` - 修复模型面板问题
186+
- `fix_no_scene_name` - 修复没有名称的场景
187+
- `fix_on_model_change_3dc` - 修复 3D Coat 模型变更回调
188+
189+
```shell
190+
MAYA_UMBRELLA_DISABLE_HOOKS
191+
```
192+
例如,禁用 `delete_turtle``delete_unknown_plugin_node` hooks:
193+
```shell
194+
SET MAYA_UMBRELLA_DISABLE_HOOKS=delete_turtle,delete_unknown_plugin_node
195+
```
196+
168197
# API
169198

170199
获取当前场景没有被修复的病毒文件

maya_umbrella/filesystem.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,58 @@ def load_hook(hook_file):
123123
return module
124124

125125

126+
def is_hooks_disabled():
127+
"""Check if all hooks are disabled via environment variable.
128+
129+
Returns:
130+
bool: True if hooks are disabled, False otherwise.
131+
"""
132+
return os.getenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "false").lower() == "true"
133+
134+
135+
def get_disabled_hooks():
136+
"""Get the list of disabled hook names from environment variable.
137+
138+
The environment variable MAYA_UMBRELLA_DISABLE_HOOKS should be a comma-separated
139+
list of hook names (without .py extension).
140+
141+
Example:
142+
SET MAYA_UMBRELLA_DISABLE_HOOKS=delete_turtle,delete_unknown_plugin_node
143+
144+
Returns:
145+
list: A list of disabled hook names.
146+
"""
147+
disabled = os.getenv("MAYA_UMBRELLA_DISABLE_HOOKS", "")
148+
if not disabled:
149+
return []
150+
return [name.strip() for name in disabled.split(",") if name.strip()]
151+
152+
126153
def get_hooks():
127154
"""Return a list of paths to all hook files in the 'hooks' directory.
128155
156+
This function respects the following environment variables:
157+
- MAYA_UMBRELLA_DISABLE_ALL_HOOKS: Set to "true" to disable all hooks.
158+
- MAYA_UMBRELLA_DISABLE_HOOKS: Comma-separated list of hook names to disable.
159+
129160
Returns:
130161
list: A list of paths to all hook files in the 'hooks' directory.
131162
"""
163+
if is_hooks_disabled():
164+
return []
165+
132166
pattern = os.path.join(this_root(), "hooks", "*.py")
133-
return [hook for hook in glob.glob(pattern) if "__init__" not in hook]
167+
disabled_hooks = get_disabled_hooks()
168+
169+
hooks = []
170+
for hook in glob.glob(pattern):
171+
if "__init__" in hook:
172+
continue
173+
hook_name = os.path.basename(hook).replace(".py", "")
174+
if hook_name in disabled_hooks:
175+
continue
176+
hooks.append(hook)
177+
return hooks
134178

135179

136180
def get_vaccines():

tests/test_filesystem.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
# Import local modules
55
from maya_umbrella.filesystem import check_virus_file_by_signature
66
from maya_umbrella.filesystem import get_backup_path
7+
from maya_umbrella.filesystem import get_disabled_hooks
8+
from maya_umbrella.filesystem import get_hooks
79
from maya_umbrella.filesystem import get_maya_install_root
10+
from maya_umbrella.filesystem import is_hooks_disabled
811
from maya_umbrella.filesystem import remove_virus_file_by_signature
912
from maya_umbrella.signatures import FILE_VIRUS_SIGNATURES
1013

@@ -70,3 +73,88 @@ def test_get_maya_install_root(monkeypatch, mocker):
7073
monkeypatch.setenv("MAYA_LOCATION", "your/maya/install/root")
7174
mocker.patch("os.path.exists", returnn_value=True)
7275
assert get_maya_install_root("1234") == "your/maya/install/root"
76+
77+
78+
def test_is_hooks_disabled_default():
79+
"""Test is_hooks_disabled returns False by default."""
80+
assert is_hooks_disabled() is False
81+
82+
83+
def test_is_hooks_disabled_true(monkeypatch):
84+
"""Test is_hooks_disabled returns True when env var is set."""
85+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "true")
86+
assert is_hooks_disabled() is True
87+
88+
89+
def test_is_hooks_disabled_case_insensitive(monkeypatch):
90+
"""Test is_hooks_disabled is case insensitive."""
91+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "TRUE")
92+
assert is_hooks_disabled() is True
93+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "True")
94+
assert is_hooks_disabled() is True
95+
96+
97+
def test_is_hooks_disabled_false(monkeypatch):
98+
"""Test is_hooks_disabled returns False when env var is 'false'."""
99+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "false")
100+
assert is_hooks_disabled() is False
101+
102+
103+
def test_get_disabled_hooks_default():
104+
"""Test get_disabled_hooks returns empty list by default."""
105+
assert get_disabled_hooks() == []
106+
107+
108+
def test_get_disabled_hooks_single(monkeypatch):
109+
"""Test get_disabled_hooks with single hook."""
110+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle")
111+
assert get_disabled_hooks() == ["delete_turtle"]
112+
113+
114+
def test_get_disabled_hooks_multiple(monkeypatch):
115+
"""Test get_disabled_hooks with multiple hooks."""
116+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle,delete_unknown_plugin_node")
117+
assert get_disabled_hooks() == ["delete_turtle", "delete_unknown_plugin_node"]
118+
119+
120+
def test_get_disabled_hooks_with_spaces(monkeypatch):
121+
"""Test get_disabled_hooks handles spaces correctly."""
122+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle , delete_unknown_plugin_node")
123+
assert get_disabled_hooks() == ["delete_turtle", "delete_unknown_plugin_node"]
124+
125+
126+
def test_get_disabled_hooks_empty_values(monkeypatch):
127+
"""Test get_disabled_hooks ignores empty values."""
128+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle,,delete_unknown_plugin_node,")
129+
assert get_disabled_hooks() == ["delete_turtle", "delete_unknown_plugin_node"]
130+
131+
132+
def test_get_hooks_returns_list():
133+
"""Test get_hooks returns a list of hook files."""
134+
hooks = get_hooks()
135+
assert isinstance(hooks, list)
136+
assert len(hooks) > 0
137+
138+
139+
def test_get_hooks_disabled_all(monkeypatch):
140+
"""Test get_hooks returns empty list when all hooks disabled."""
141+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_ALL_HOOKS", "true")
142+
assert get_hooks() == []
143+
144+
145+
def test_get_hooks_disabled_specific(monkeypatch):
146+
"""Test get_hooks excludes specific disabled hooks."""
147+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle")
148+
hooks = get_hooks()
149+
hook_names = [hook.split("\\")[-1].split("/")[-1].replace(".py", "") for hook in hooks]
150+
assert "delete_turtle" not in hook_names
151+
assert len(hooks) > 0
152+
153+
154+
def test_get_hooks_disabled_multiple(monkeypatch):
155+
"""Test get_hooks excludes multiple disabled hooks."""
156+
monkeypatch.setenv("MAYA_UMBRELLA_DISABLE_HOOKS", "delete_turtle,delete_unknown_plugin_node")
157+
hooks = get_hooks()
158+
hook_names = [hook.split("\\")[-1].split("/")[-1].replace(".py", "") for hook in hooks]
159+
assert "delete_turtle" not in hook_names
160+
assert "delete_unknown_plugin_node" not in hook_names

0 commit comments

Comments
 (0)