Skip to content

Commit

Permalink
Always default to latest maya config.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxWiklund committed Jun 1, 2023
1 parent cd968fd commit bbdd3bc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
17 changes: 6 additions & 11 deletions mayaff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

import argparse
import multiprocessing
import pkg_resources
import re
import sys
import os
from concurrent import futures
from typing import List, Tuple

from mayaff import file_resources, mayaff_api, output
from mayaff.config import MayaArgsConfig, MayaFileArgsConfig
from mayaff.config import MayaArgsConfig, MayaFileArgsConfig, CONFIG_OPTIONS, LATEST_CONFIG

__version__ = "1.0.0"
__version__ = "1.1.0"
_DESCRIPTION = "Command line tool to find and replace short maya flags."


Expand All @@ -36,10 +35,6 @@ def config_exists(parser: argparse.ArgumentParser, file_path: str) -> None:

def set_up_argparser() -> argparse.Namespace:
"""Configure argparser."""
config_options = [
f.replace(".json", "") for f in pkg_resources.resource_listdir("mayaff", "maya_configs") if f.endswith(".json")
]

parser = argparse.ArgumentParser(description=_DESCRIPTION)
parser.add_argument("-v", "--version", action="version", version="%(prog)s {}".format(__version__))
parser.add_argument("source", nargs="+", help="Directory or files you want to format.")
Expand All @@ -49,8 +44,8 @@ def set_up_argparser() -> argparse.Namespace:
config_group.add_argument(
"-t",
"--target-version",
default=max(config_options),
choices=sorted(config_options),
default=LATEST_CONFIG,
choices=CONFIG_OPTIONS,
help="Target Maya version to use when formatting flags.",
)

Expand Down Expand Up @@ -97,11 +92,11 @@ def _main() -> int:

_config = MayaFileArgsConfig(args.config, modules) if args.config else MayaArgsConfig(args.target_version, modules)
try:
exclued_re = re.compile(args.exclude)
exclude_re = re.compile(args.exclude)
except re.error:
raise UserWarning("Invalid exclude regular expression.")

files = file_resources.find_python_files(args.source, args.exclude_files, exclude_pattern=exclued_re)
files = file_resources.find_python_files(args.source, args.exclude_files, exclude_pattern=exclude_re)
if not files:
raise UserWarning("No input files found.")

Expand Down
11 changes: 9 additions & 2 deletions mayaff/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, Tuple
import json
import os
import pkg_resources
import pkgutil
from typing import List, Tuple

CONFIG_OPTIONS = [
f.replace(".json", "") for f in pkg_resources.resource_listdir("mayaff", "maya_configs") if f.endswith(".json")
]
CONFIG_OPTIONS.sort()
LATEST_CONFIG = max(CONFIG_OPTIONS, key=int)


class BaseMayaConfig(object):
Expand Down Expand Up @@ -51,7 +58,7 @@ def get_flags(self, command_name: str) -> dict:
class MayaArgsConfig(BaseMayaConfig):
"""Class to manage maya flags configuration."""

def __init__(self, config_version: str = "2022", modules: List[Tuple[str, str]] = (("maya", "cmds"),)):
def __init__(self, config_version: str = LATEST_CONFIG, modules: List[Tuple[str, str]] = (("maya", "cmds"),)):
"""Construct class and load config.
Args:
Expand Down
4 changes: 2 additions & 2 deletions mayaff/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import difflib


def print_failed(msg):
def print_failed(msg: str) -> None:
print(f"\033[31m{msg}\033[0m")


def diff(source_a: str, source_b: str, file_name: str):
def diff(source_a: str, source_b: str, file_name: str) -> str:
"""Generate diff of source with color.
Args:
Expand Down
2 changes: 1 addition & 1 deletion mayaff/pyparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _parse_command_flags(self, command_name: str) -> flags.FlagKwargs:
continue

if scope > 1:
# A open parenthesis we don't want to account for has been open.
# An open parenthesis we don't want to account for has been open.
# Continue until the scope hase been closed.
continue

Expand Down

0 comments on commit bbdd3bc

Please sign in to comment.