Skip to content

Commit

Permalink
Switch from pylint to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Moguri committed Apr 20, 2024
1 parent 8cd5962 commit ad32868
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 101 deletions.
39 changes: 23 additions & 16 deletions pman/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
#pylint: skip-file
# ruff: noqa: I001, PLC0414

# Utilities
from ._utils import (
config_exists,
get_abs_path,
get_config,
get_config_plugins,
get_python_program,
get_rel_path,
run_script,
is_frozen,
config_exists as config_exists,
get_abs_path as get_abs_path,
get_config as get_config,
get_config_plugins as get_config_plugins,
get_python_program as get_python_program,
get_rel_path as get_rel_path,
is_frozen as is_frozen,
run_script as run_script,
)

# Core functions
from ._build import build as build
from ._core import (
create_project,
run,
dist,
clean,
clean as clean,
create_project as create_project,
dist as dist,
run as run,
)
from ._build import build

# Exceptions
from .exceptions import *
from .exceptions import (
BuildError as BuildError,
ConfigError as ConfigError,
FrozenEnvironmentError as FrozenEnvironmentError,
NoConfigError as NoConfigError,
PManError as PManError,
)

# Version
from .version import __version__
from .version import __version__ as __version__
25 changes: 11 additions & 14 deletions pman/_build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
import concurrent.futures
import contextlib
import dataclasses
import fnmatch
import itertools
Expand All @@ -10,27 +11,25 @@
import sys
import time

# pylint: disable=redefined-builtin
from rich import (
live,
print,
progress,
table,
)


from . import plugins
from .plugins.common import ConverterResult
from ._utils import (
disallow_frozen,
ensure_config,
get_abs_path,
get_rel_path,
run_hooks,
)
from .plugins.common import ConverterResult


def gather_files(srcdir, include_patterns, exclude_patterns, verbose=False):
def gather_files(srcdir, include_patterns, exclude_patterns, *, verbose=False):
found_assets = []
for root, _dirs, files in os.walk(srcdir):
for asset in files:
Expand Down Expand Up @@ -152,7 +151,7 @@ def generate_explicit_streams(config, converters):
verbose=verbose
)
plugin_name = stream_configs['plugin']
converter = converter_map.get(plugin_name, None)
converter = converter_map.get(plugin_name)
if not converter:
print(
f'Failed to find plugin ({plugin_name}) for stream\n'
Expand Down Expand Up @@ -236,7 +235,7 @@ def skip_build(converter, asset):
]
skip = (
os.path.exists(dst)
and all((os.stat(i).st_mtime <= os.stat(dst).st_mtime for i in deps))
and all(os.stat(i).st_mtime <= os.stat(dst).st_mtime for i in deps)
)
if skip:
if verbose:
Expand All @@ -249,10 +248,10 @@ def skip_build(converter, asset):
max_workers = None
pool = concurrent.futures.ProcessPoolExecutor(max_workers=max_workers)
jobs = []
for converter, assets, converter_config in streams:
for converter, stream_assets, converter_config in streams:
assets = [
asset
for asset in assets
for asset in stream_assets
if not skip_build(converter, asset)
]

Expand Down Expand Up @@ -317,19 +316,17 @@ def update_progress():
for _, fut in jobs:
for result in fut.result():
builddb[result.output_file] = result
except KeyboardInterrupt as exc:
for pid in pool._processes: # pylint: disable=protected-access
try:
except KeyboardInterrupt:
for pid in pool._processes: # noqa
with contextlib.suppress(ProcessLookupError):
os.kill(pid, signal.SIGKILL)
except ProcessLookupError:
pass
shutdown_args = {
'wait': False
}
if sys.version_info >= (3, 9):
shutdown_args['cancel_futures'] = True
pool.shutdown(**shutdown_args)
raise exc
raise

with open(builddb_path, 'w', encoding='utf8') as builddb_file:
json.dump([dataclasses.asdict(i) for i in builddb.values()], builddb_file)
Expand Down
22 changes: 9 additions & 13 deletions pman/_core.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import contextlib
import os
import shlex
import shutil
import tomli as toml

import tomli as toml

from . import creationutils
from ._build import build
from ._utils import (
disallow_frozen,
ensure_config,
get_abs_path,
get_config,
get_config_plugins,
ensure_config,
disallow_frozen,
run_hooks,
run_script,
)
Expand Down Expand Up @@ -41,7 +42,7 @@ def create_project(projectdir='.', extra_plugins=None):
config = get_config(projectdir)

for plugin in get_config_plugins(config, 'pre_create'):
getattr(plugin, 'pre_create')(config)
plugin.pre_create(config)

creationutils.create_dirs(projectdir, (
config['build']['asset_dir'],
Expand All @@ -56,11 +57,8 @@ def create_project(projectdir='.', extra_plugins=None):
('test_imports.py', 'tests/test_imports.py'),
))

for plugin in get_config_plugins(config, 'pre_post'):
getattr(plugin, 'pre_post')(config)



for plugin in get_config_plugins(config, 'post_create'):
plugin.post_create(config)


@ensure_config
Expand All @@ -69,7 +67,7 @@ def create_project(projectdir='.', extra_plugins=None):
def run(config=None):
mainfile = get_abs_path(config, config['run']['main_file'])
print(f'Running main file: {mainfile}')
args = [mainfile] + shlex.split(config['run']['extra_args'])
args = [mainfile, *shlex.split(config['run']['extra_args'])]
run_script(config, args, cwd=config['internal']['projectdir'])


Expand Down Expand Up @@ -153,7 +151,5 @@ def clean(config=None):
shutil.rmtree(get_abs_path(config, export_dir), ignore_errors=True)
shutil.rmtree(get_abs_path(config, 'build'), ignore_errors=True)
shutil.rmtree(get_abs_path(config, 'dist'), ignore_errors=True)
try:
with contextlib.suppress(FileNotFoundError):
os.unlink(get_abs_path(config, '.pman_builddb'))
except FileNotFoundError:
pass
6 changes: 3 additions & 3 deletions pman/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import subprocess
import sys

from .import plugins
from . import plugins
from .config import Config
from .exceptions import (
ConfigError,
Expand Down Expand Up @@ -63,7 +63,7 @@ def run_program(_config, args, cwd=None):

def run_script(config, args, cwd=None):
pyprog = get_python_program(config)
run_program(config, [pyprog] + args, cwd=cwd)
run_program(config, [pyprog, *args], cwd=cwd)


def get_config_plugins(config, has_attr=None):
Expand Down Expand Up @@ -128,7 +128,7 @@ def disallow_frozen(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if is_frozen():
raise FrozenEnvironmentError()
raise FrozenEnvironmentError
return func(*args, **kwargs)
return wrapper

Expand Down
7 changes: 0 additions & 7 deletions pman/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import subprocess
import sys


import pman


Expand Down Expand Up @@ -36,12 +35,6 @@ def test(_, config):
def dist(args, config):
pman.get_python_program(config)

try:
import direct.dist.commands #pylint:disable=unused-import,unused-variable
except ImportError:
print('Setuptools-based distribution is not supported by this version of Panda3D')
return

build_installers = None
if args.skip_installers:
build_installers = False
Expand Down
9 changes: 5 additions & 4 deletions pman/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import functools
import os
from dataclasses import (
dataclass,
field,
fields,
is_dataclass,
)
import functools
import os
from typing import (
Any,
ClassVar,
)

import tomli as toml
Expand Down Expand Up @@ -54,7 +55,7 @@ def __contains__(self, key):

@dataclass
class GeneralConfig(ConfigBase):
DEFAULT_PLUGINS = [
DEFAULT_PLUGINS: ClassVar[list[str]] = [
'native2bam',
'blend2bam',
]
Expand Down Expand Up @@ -110,7 +111,7 @@ class InternalConfig(ConfigBase):

@dataclass
class Config(ConfigBase):
PROJECT_CONFIG_NAMES = [
PROJECT_CONFIG_NAMES: ClassVar[list[str]] = [
'pyproject.toml',
'.pman',
'.pman.user',
Expand Down
12 changes: 6 additions & 6 deletions pman/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
class PManException(Exception):
class PManError(Exception):
pass


class NoConfigError(PManException):
class NoConfigError(PManError):
pass


class ConfigError(PManException):
class ConfigError(PManError):
pass


class CouldNotFindPythonError(PManException):
class CouldNotFindPythonError(PManError):
pass


class BuildError(PManException):
class BuildError(PManError):
pass


class FrozenEnvironmentError(PManException):
class FrozenEnvironmentError(PManError):
def __init__(self):
super().__init__("Operation not supported in frozen applications")
5 changes: 2 additions & 3 deletions pman/native2bam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import panda3d.core as p3d


CONFIG_DATA = """
assimp-gen-normals true
bam-texture-mode unchanged
Expand All @@ -23,8 +22,8 @@ def make_texpath_relative(node, srcdir, converted_textures):
continue
texture.filename = os.path.relpath(texture.filename, srcdir)
converted_textures.add(texture)
renderstate = renderstate.set_attrib(texattrib)
geomnode.set_geom_state(idx, renderstate)
newrenderstate = renderstate.set_attrib(texattrib)
geomnode.set_geom_state(idx, newrenderstate)



Expand Down
2 changes: 1 addition & 1 deletion pman/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def load_plugin(entrypoint):
return plugin_class()

eps = entry_points()
if isinstance(eps, dict): # Python 3.8 and 3.9
if isinstance(eps, dict): # Python 3.8 and 3.9 # noqa: SIM108
plugins = eps.get('pman.plugins')
else:
plugins = eps.select(group='pman.plugins')
Expand Down
14 changes: 8 additions & 6 deletions pman/plugins/blend2bam.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import subprocess
import sys
from dataclasses import (
dataclass,
field,
)
import os
import subprocess
import sys
from typing import (
Any,
ClassVar,
Literal,
)

Expand All @@ -15,8 +16,9 @@
ConverterResult,
)


class Blend2BamPlugin:
converters = [
converters: ClassVar[list[ConverterInfo]] = [
ConverterInfo(
name='blend2bam',
supported_extensions=['.blend'],
Expand Down Expand Up @@ -93,5 +95,5 @@ def convert(self, config, converter_config, srcdir, dstdir, assets):
]
))

proc.check_returncode()
return results
proc.check_returncode()
return results
2 changes: 1 addition & 1 deletion pman/plugins/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing

from dataclasses import dataclass, field


@dataclass(frozen=True)
class ConverterInfo:
name: str
Expand Down
Loading

0 comments on commit ad32868

Please sign in to comment.