Skip to content

Commit

Permalink
style: Fix lints
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 7a073c2 commit 8df1f8f
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 287 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install -U pip poetry nox
python -m pip -r requirements-dev.txt
poetry --version
- name: Run tests and collect coverage
run: |
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/mr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install -U pip poetry nox
python -m pip -r requirements-dev.txt
poetry --version
- name: lint
run: |
nox -s ruff_check
- name: isort
run: |
nox -s isort_check
nox -s lint
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install -U pip poetry nox
python -m pip -r requirements-dev.txt
poetry --version
poetry build
# Note that we don't need credentials.
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ manual_test_in_maya.start()
我们可以利用封装好的`nox`命令去执行进行代码检查

```shell
nox -s ruff_check
nox -s lint
```

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

# 生成安装包
Expand Down
8 changes: 7 additions & 1 deletion manual_test_in_maya.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import os
# Import built-in modules
import glob
import os

# Import third-party modules
import maya.cmds as cmds

# Import local modules
from maya_umbrella.maya_funs import open_maya_file


ROOT = os.path.dirname(os.path.abspath(__file__))


Expand Down
4 changes: 3 additions & 1 deletion maya/userSetup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Import local modules
# Import third-party modules
import maya.cmds as cmds

# Import local modules
from maya_umbrella import MayaVirusDefender


Expand Down
24 changes: 12 additions & 12 deletions maya_umbrella/hooks/delete_unknown_plugin_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ def hook(virus_cleaner):
unknown_node = cmds.ls(type="unknown")
unknown_plugin = cmds.unknownPlugin(query=True, l=True)
if unknown_node:
for nodeObj in unknown_node:
if cmds.objExists(nodeObj):
if cmds.referenceQuery(nodeObj, isNodeReferenced=True):
virus_cleaner.logger.warning("Node from reference, skip. {}".format(nodeObj))
for node_obj in unknown_node:
if cmds.objExists(node_obj):
if cmds.referenceQuery(node_obj, isNodeReferenced=True):
virus_cleaner.logger.warning("Node from reference, skip. {}".format(node_obj))
continue
if cmds.lockNode(nodeObj, query=True)[0]:
if cmds.lockNode(node_obj, query=True)[0]:
try:
cmds.lockNode(nodeObj, lock=False)
cmds.lockNode(node_obj, lock=False)
except Exception:
virus_cleaner.logger.warning(
"The node is locked and cannot be unlocked. skip {}".format(nodeObj)
"The node is locked and cannot be unlocked. skip {}".format(node_obj)
)
continue
try:
cmds.delete(nodeObj)
virus_cleaner.logger.warning("Delete node: {}".format(nodeObj))
cmds.delete(node_obj)
virus_cleaner.logger.warning("Delete node: {}".format(node_obj))
except Exception:
pass

if unknown_plugin:
for plugObj in unknown_plugin:
cmds.unknownPlugin(plugObj, remove=True)
virus_cleaner.logger.warning("Delete plug-in: {}".format(plugObj))
for plug_obj in unknown_plugin:
cmds.unknownPlugin(plug_obj, remove=True)
virus_cleaner.logger.warning("Delete plug-in: {}".format(plug_obj))
4 changes: 2 additions & 2 deletions maya_umbrella/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Translator(object):
data (dict): Dictionary containing translation data for different locales.
locale (str): The current locale.
"""

def __init__(self, file_format="json", default_locale=None):
"""Initialize the Translator.
Expand All @@ -24,8 +25,7 @@ def __init__(self, file_format="json", default_locale=None):
default_locale (str, optional): Default locale to use for translations. Defaults to None,
which uses the MAYA_UMBRELLA_LANG environment variable or the Maya UI language.
"""
_default_locale = os.getenv("MAYA_UMBRELLA_LANG", maya_ui_language())
default_locale = default_locale or _default_locale
default_locale = default_locale or os.getenv("MAYA_UMBRELLA_LANG", maya_ui_language())
self.data = {}
self.locale = default_locale
translations_folder = os.path.join(this_root(), "locales")
Expand Down
10 changes: 6 additions & 4 deletions maya_umbrella/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Import built-in modules
import logging.handlers
from logging import Formatter
from logging import getLogger
from logging import handlers
import os

# Import local modules
Expand All @@ -20,18 +22,18 @@ def setup_logger(logger=None, logfile=None, log_level=None):
Returns:
logging.Logger: The set up logger.
"""
logger = logger or logging.getLogger(PACKAGE_NAME)
logger = logger or getLogger(PACKAGE_NAME)
log_level = log_level or os.getenv("MAYA_UMBRELLA_LOG_LEVEL", "INFO")
logger.setLevel(log_level)
logfile = logfile or get_log_file()
if not len(logger.handlers):
filehandler = logging.handlers.RotatingFileHandler(
filehandler = handlers.RotatingFileHandler(
logfile,
mode="a",
backupCount=7,
delay=True,
maxBytes=LOG_MAX_BYTES,
)
filehandler.setFormatter(logging.Formatter(LOG_FORMAT))
filehandler.setFormatter(Formatter(LOG_FORMAT))
logger.addHandler(filehandler)
return logger
2 changes: 1 addition & 1 deletion maya_umbrella/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, output_path=None, env=None):
Args:
output_path (str, optional): Path to save the fixed files. Defaults to None, which overwrites the original
files.
files.
env (dict, optional): Custom environment variables. Defaults to None,
which sets the 'MAYA_COLOR_MANAGEMENT_SYNCOLOR' variable to '1'.
"""
Expand Down
13 changes: 7 additions & 6 deletions maya_umbrella/vaccines/vaccine3.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ def collect_infected_mel_files(self):
# check usersetup.mel
# C:/Users/hallong/Documents/maya/scripts/usersetup.mel
# C:/Users/hallong/Documents/maya/xxxx/scripts/usersetup.mel
for usersetup_mel in [
usersetup_mel_paths = [
os.path.join(self.api.local_script_path, "usersetup.mel"),
os.path.join(self.api.user_script_path, "usersetup.mel"),
]:
if os.path.exists(usersetup_mel):
if check_virus_file_by_signature(usersetup_mel):
self.report_issue(usersetup_mel)
self.api.add_infected_file(usersetup_mel)
]

for usersetup_mel in usersetup_mel_paths:
if os.path.exists(usersetup_mel) and check_virus_file_by_signature(usersetup_mel):
self.report_issue(usersetup_mel)
self.api.add_infected_file(usersetup_mel)

def collect_script_jobs(self):
"""Collect all script jobs related to the virus."""
Expand Down
3 changes: 2 additions & 1 deletion nox_actions/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def lint(session: nox.Session) -> None:


def lint_fix(session: nox.Session) -> None:
session.install("isort", "ruff", "pre-commit")
session.install("isort", "ruff", "pre-commit", "autoflake")
session.run("ruff", "check", "--fix")
session.run("isort", ".")
session.run("pre-commit", "run", "--all-files")
session.run("autoflake", "--in-place", "--remove-all-unused-imports", "--remove-unused-variables")
3 changes: 2 additions & 1 deletion nox_actions/run_maya.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

# Ensure maya_umbrella is importable.
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Import local modules
from maya_umbrella.filesystem import get_maya_install_root
from maya_umbrella.filesystem import get_maya_install_root # noqa: E402


def run_maya(session: nox.Session):
Expand Down
Loading

0 comments on commit 8df1f8f

Please sign in to comment.