Skip to content

Commit

Permalink
style: fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: loonghao <[email protected]>
  • Loading branch information
loonghao committed May 11, 2024
1 parent 3fe0629 commit 13c1810
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 26 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ and it is recommended to use Python 3.8 or higher versions.

通过虚拟环境去设置开发环境, 推荐python-3.8以上的版本

通过pip安装相关开发依赖

```shell
pip install -r requirements-dev.txt
```
Expand Down Expand Up @@ -103,13 +105,15 @@ nox -s lint

进行代码整理
```shell
nox -s lint-fx
nox -s lint-fix
```

# 生成安装包

执行下面的命令可以在<repo>/.zip下面创建zip,参数 `--version` 当前工具的版本号
**注意:`make-zip``--version`之间有 俩个`-`**

**注意:`make-zip``--version`之间有 俩个`-`**

```shell
nox -s make-zip -- --version 0.5.0
```
Expand Down Expand Up @@ -188,13 +192,16 @@ print(api.scan_files_from_pattern("your/path/*.m[ab]"))
```

# 案例
如果你想要快速通过maya standalone去批量清理maya文件,可以`下载`或者`git clone`当前`main`分支的工程,
根据上面指引设置好开发环境
通过`nox`命令去启动maya `standalone`环境,maya版本根据你当前本地安装的maya为准,比如你本地安装了`2018`,
如果你想要快速通过maya standalone去批量清理maya文件,
可以`下载`或者`git clone`当前`main`分支的工程,
根据上面指引设置好开发环境,
通过`nox`命令去启动maya `standalone`环境,maya版本根据你当前本地安装的maya为准,
比如你本地安装了`2018`,
那么就是 `nox -s maya -- 2018 --standalone`
下面的语法是启动一个maya-2020的环境去动态从`c:/test`文件夹下去查杀病毒

```shell
nox -s maya-2020-s -- c:/test/*.m[ab]
nox -s maya -- 2018 --standalone --pattern c:/test/*.m[ab]
```

## Contributors ✨
Expand Down
1 change: 1 addition & 0 deletions maya_umbrella/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from maya_umbrella.defender import get_defender_instance
from maya_umbrella.scanner import MayaVirusScanner


# All public APIs.
__all__ = [
"MayaVirusDefender",
Expand Down
6 changes: 5 additions & 1 deletion maya_umbrella/defender.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ def context_defender():


def get_defender_instance():
"""Get the MayaVirusDefender instance."""
"""Get the MayaVirusDefender instance.
Returns:
MayaVirusDefender: The MayaVirusDefender instance.
"""
global MAYA_UMBRELLA_DEFENDER
if MAYA_UMBRELLA_DEFENDER is None:
MAYA_UMBRELLA_DEFENDER = MayaVirusDefender()
Expand Down
32 changes: 19 additions & 13 deletions maya_umbrella/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import glob
import importlib
import json
import logging
import os
import random
import re
Expand Down Expand Up @@ -43,10 +44,20 @@ def safe_rmtree(path):


def _codes_open(path, encoding="utf-8"):
# Import built-in modules
with codecs.open(path, "r", encoding) as file_:
return file_.read()
"""Open and read the content of a file using the specified encoding.
Args:
path (str): Path to the file.
encoding (str, optional): The encoding to use when reading the file. Defaults to "utf-8".
Returns:
str: The content of the file, or an empty string if the file could not be read.
"""
try:
with codecs.open(path, "r", encoding) as file_:
return file_.read()
except (OSError, IOError): # noqa: UP024
return ""

def read_file(path):
"""Read the content of the file at the given path."""
Expand Down Expand Up @@ -78,12 +89,6 @@ def write_file(path, content):
file_.write(content)


def _codes_write(path, content, encoding="utf-8"):
# Import built-in modules
with codecs.open(path, "w", encoding) as file_:
file_.write(content)


@contextmanager
def atomic_writes(src, mode, **options):
"""Context manager for atomic writes to a file.
Expand All @@ -102,7 +107,7 @@ def atomic_writes(src, mode, **options):
AttributeError: If the os module does not have the 'replace' function (Python 2 compatibility).
"""
temp_path = os.path.join(os.path.dirname(src), "._{}".format(id_generator()))
open_func = open if PY3 else _codes_open
open_func = open if PY3 else codecs.open
with open_func(temp_path, mode, **options) as f:
yield f
try:
Expand Down Expand Up @@ -295,6 +300,7 @@ def get_backup_path(path, root_path=None):

def get_maya_install_root(maya_version):
"""Get the Maya install root path."""
logger = logging.getLogger(__name__)
maya_location = os.getenv("MAYA_LOCATION")
try:
# Import built-in modules
Expand All @@ -308,14 +314,14 @@ def get_maya_install_root(maya_version):
)
root, _ = winreg.QueryValueEx(key, "MAYA_INSTALL_LOCATION")
if not os.path.isdir(root):
print("Failed to locate the appropriate Maya path in the registration list.")
logger.info("Failed to locate the appropriate Maya path in the registration list.")
except OSError:
return maya_location
maya_location = maya_location or root
if not maya_location:
print("maya not found.")
logger.info("maya not found.")
return
maya_exe = os.path.join(maya_location, "bin", "maya.exe")
if not os.path.exists(maya_exe):
print("maya.exe not found in {maya_location}.".format(maya_location=maya_location))
logger.info("maya.exe not found in {maya_location}.".format(maya_location=maya_location))
return maya_location
8 changes: 8 additions & 0 deletions maya_umbrella/vaccines/vaccine3.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class Vaccine(AbstractVaccine):

@staticmethod
def is_infected(script_node):
"""Check if a script node is infected with a virus.
Args:
script_node (str): The name of the script node to check.
Returns:
bool: True if the script node is infected, False otherwise.
"""
if "_gene" in script_node:
return True
if "uifiguration" in script_node:
Expand Down
16 changes: 10 additions & 6 deletions nox_actions/run_maya.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ def run_maya(session: nox.Session):
r = requests.get(get_pip_url) # create HTTP response object
with open(get_pip_py, "wb") as f:
f.write(r.content)

# Use mayapy to install pip.
session.run_install(mayapy, get_pip_py)

session.run_install(
mayapy,
"-m",
"pip",
"install",
"--ignore-installed",
"pytest",
"pytest-cov",
"pytest-mock",
"-r",
os.path.join(THIS_ROOT, "requirements-dev.txt"),
"--target",
temp_dir,
)
Expand All @@ -67,7 +69,8 @@ def run_maya(session: nox.Session):
test_runner,
f"--cov={PACKAGE_NAME}",
f"--rootdir={test_root}",
env={"PYTHONPATH": f"{THIS_ROOT};{temp_dir}"},
external=True,
env={"PYTHONPATH": _assemble_env_paths(THIS_ROOT, temp_dir)},
)

elif args.standalone:
Expand All @@ -80,12 +83,13 @@ def run_maya(session: nox.Session):
)
else:
# Launch maya
print(_assemble_env_paths(THIS_ROOT, os.path.join(THIS_ROOT, "maya")))
paths = _assemble_env_paths(THIS_ROOT, os.path.join(THIS_ROOT, "maya"))
print(f"PYTHONPATH: {paths}")
session.run(
maya_exe_root,
external=True,
env={
"PYTHONPATH": _assemble_env_paths(THIS_ROOT, os.path.join(THIS_ROOT, "maya")),
"PYTHONPATH": paths,
"MAYA_UMBRELLA_LOG_LEVEL": "DEBUG",
},
)
8 changes: 8 additions & 0 deletions nox_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@


def _assemble_env_paths(*paths):
"""Assemble environment paths separated by a semicolon.
Args:
*paths: Paths to be assembled.
Returns:
str: Assembled paths separated by a semicolon.
"""
return ";".join(paths)
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
poetry
nox
requests
pytest
pytest-cov
pytest-mock

0 comments on commit 13c1810

Please sign in to comment.