浏览代码

remove pylint (#4836)

* remove pylint

* remove other pylint disables
/MLA-1734-demo-provider
GitHub 4 年前
当前提交
7387a77f
共有 16 个文件被更改,包括 14 次插入99 次删除
  1. 12
      .pre-commit-config.yaml
  2. 2
      ml-agents-envs/mlagents_envs/environment.py
  3. 2
      ml-agents-envs/mlagents_envs/registry/binary_utils.py
  4. 15
      ml-agents-envs/mlagents_envs/rpc_utils.py
  5. 2
      ml-agents/mlagents/torch_utils/torch.py
  6. 7
      ml-agents/mlagents/trainers/agent_processor.py
  7. 1
      ml-agents/mlagents/trainers/barracuda.py
  8. 1
      ml-agents/mlagents/trainers/learn.py
  9. 2
      ml-agents/mlagents/trainers/optimizer/torch_optimizer.py
  10. 4
      ml-agents/mlagents/trainers/policy/torch_policy.py
  11. 4
      ml-agents/mlagents/trainers/sac/optimizer_torch.py
  12. 2
      ml-agents/mlagents/trainers/stats.py
  13. 2
      ml-agents/mlagents/trainers/tests/torch/test_ppo.py
  14. 2
      ml-agents/mlagents/trainers/tests/torch/test_sac.py
  15. 2
      ml-agents/mlagents/trainers/trainer/rl_trainer.py
  16. 53
      .pylintrc

12
.pre-commit-config.yaml


hooks:
- id: python-check-mock-methods
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v2.4.4
hooks:
- id: pylint
exclude: >
(?x)^(
.*_pb2.py|
.*_pb2_grpc.py|
.*/tests/.*
)$
args: [--score=n]
- repo: https://github.com/mattlqx/pre-commit-search-and-replace
rev: v1.0.3
hooks:

2
ml-agents-envs/mlagents_envs/environment.py


"""
try:
# A negative value -N indicates that the child was terminated by signal N (POSIX only).
s = signal.Signals(-returncode) # pylint: disable=no-member
s = signal.Signals(-returncode)
return s.name
except Exception:
# Should generally be a ValueError, but catch everything just in case.

2
ml-agents-envs/mlagents_envs/registry/binary_utils.py


break
try:
download_and_extract_zip(url, name)
except Exception: # pylint: disable=W0702
except Exception:
if attempt + 1 < NUMBER_ATTEMPTS:
logger.warning(
f"Attempt {attempt + 1} / {NUMBER_ATTEMPTS}"

15
ml-agents-envs/mlagents_envs/rpc_utils.py


def _process_visual_observation(
obs_index: int,
shape: Tuple[int, int, int],
agent_info_list: Collection[
AgentInfoProto
], # pylint: disable=unsubscriptable-object
agent_info_list: Collection[AgentInfoProto],
) -> np.ndarray:
if len(agent_info_list) == 0:
return np.zeros((0, shape[0], shape[1], shape[2]), dtype=np.float32)

@timed
def _process_vector_observation(
obs_index: int,
shape: Tuple[int, ...],
agent_info_list: Collection[
AgentInfoProto
], # pylint: disable=unsubscriptable-object
obs_index: int, shape: Tuple[int, ...], agent_info_list: Collection[AgentInfoProto]
) -> np.ndarray:
if len(agent_info_list) == 0:
return np.zeros((0,) + shape, dtype=np.float32)

@timed
def steps_from_proto(
agent_info_list: Collection[
AgentInfoProto
], # pylint: disable=unsubscriptable-object
behavior_spec: BehaviorSpec,
agent_info_list: Collection[AgentInfoProto], behavior_spec: BehaviorSpec
) -> Tuple[DecisionSteps, TerminalSteps]:
decision_agent_info_list = [
agent_info for agent_info in agent_info_list if not agent_info.done

2
ml-agents/mlagents/torch_utils/torch.py


torch.set_num_threads(cpu_utils.get_num_threads_to_use())
os.environ["KMP_BLOCKTIME"] = "0"
# Known PyLint compatibility with PyTorch https://github.com/pytorch/pytorch/issues/701
# pylint: disable=E1101
if torch.cuda.is_available():
torch.set_default_tensor_type(torch.cuda.FloatTensor)
device = torch.device("cuda")

7
ml-agents/mlagents/trainers/agent_processor.py


)
def _process_step(
self,
step: Union[
TerminalStep, DecisionStep
], # pylint: disable=unsubscriptable-object
global_id: str,
index: int,
self, step: Union[TerminalStep, DecisionStep], global_id: str, index: int
) -> None:
terminated = isinstance(step, TerminalStep)
stored_decision_step, idx = self.last_step_result.get(global_id, (None, None))

1
ml-agents/mlagents/trainers/barracuda.py


# pylint: skip-file
# flake8: noqa
from __future__ import print_function
from collections import defaultdict

1
ml-agents/mlagents/trainers/learn.py


def get_version_string() -> str:
# pylint: disable=no-member
return f""" Version information:
ml-agents: {mlagents.trainers.__version__},
ml-agents-envs: {mlagents_envs.__version__},

2
ml-agents/mlagents/trainers/optimizer/torch_optimizer.py


from mlagents.trainers.torch.utils import ModelUtils
class TorchOptimizer(Optimizer): # pylint: disable=W0223
class TorchOptimizer(Optimizer):
def __init__(self, policy: TorchPolicy, trainer_settings: TrainerSettings):
super().__init__()
self.policy = policy

4
ml-agents/mlagents/trainers/policy/torch_policy.py


for agent_id in decision_requests.agent_id
] # For 1-D array, the iterator order is correct.
run_out = self.evaluate(
decision_requests, global_agent_ids
) # pylint: disable=assignment-from-no-return
run_out = self.evaluate(decision_requests, global_agent_ids)
self.save_memories(global_agent_ids, run_out.get("memory_out"))
self.check_nan_action(run_out.get("action"))
return ActionInfo(

4
ml-agents/mlagents/trainers/sac/optimizer_torch.py


# ExitStack allows us to enter the torch.no_grad() context conditionally
with ExitStack() as stack:
if not q1_grad:
stack.enter_context(torch.no_grad()) # pylint: disable=E1101
stack.enter_context(torch.no_grad())
q1_out, _ = self.q1_network(
inputs,
actions=actions,

with ExitStack() as stack:
if not q2_grad:
stack.enter_context(torch.no_grad()) # pylint: disable=E1101
stack.enter_context(torch.no_grad())
q2_out, _ = self.q2_network(
inputs,
actions=actions,

2
ml-agents/mlagents/trainers/stats.py


)
class StatsSummary(NamedTuple): # pylint: disable=inherit-non-class
class StatsSummary(NamedTuple):
mean: float
std: float
num: int

2
ml-agents/mlagents/trainers/tests/torch/test_ppo.py


from mlagents.trainers.tests import mock_brain as mb
from mlagents.trainers.tests.test_trajectory import make_fake_trajectory
from mlagents.trainers.settings import NetworkSettings
from mlagents.trainers.tests.dummy_config import ( # noqa: F401; pylint: disable=unused-variable
from mlagents.trainers.tests.dummy_config import ( # noqa: F401
ppo_dummy_config,
curiosity_dummy_config,
gail_dummy_config,

2
ml-agents/mlagents/trainers/tests/torch/test_sac.py


from mlagents.trainers.policy.torch_policy import TorchPolicy
from mlagents.trainers.tests import mock_brain as mb
from mlagents.trainers.settings import NetworkSettings
from mlagents.trainers.tests.dummy_config import ( # noqa: F401; pylint: disable=unused-variable
from mlagents.trainers.tests.dummy_config import ( # noqa: F401
sac_dummy_config,
curiosity_dummy_config,
)

2
ml-agents/mlagents/trainers/trainer/rl_trainer.py


logger = get_logger(__name__)
class RLTrainer(Trainer): # pylint: disable=abstract-method
class RLTrainer(Trainer):
"""
This class is the base class for trainers that use Reward Signals.
"""

53
.pylintrc


[MASTER]
# Add files or directories to the ignore list. They should be base names, not
# paths.
ignore=CVS
generated-members=torch.*
[MESSAGES CONTROL]
#enable=
disable =
# C0301: Line too long
# C0330: Wrong hanging indentation before block
# disabled because black handles this
C0301,C0330,
# C0114: Missing module docstring
# C0115: Missing class docstring
# C0116: Missing function or method docstring
C0114,C0115,C0116,
# All convention and refactor for now
C,R,
# W1201: Specify string format arguments as logging function parameters
# W1202: Use % formatting in logging functions and pass the % parameters as arguments
W1201,W1202,
# W0612: Unused variable
# W0613: Unused argument
W0612, W0613,
# W0107: Unnecessary pass statement
W0107,
# W0511 "TODO"
W0511,
# W0703: Catching too general exception Exception
W0703,
# E0401: Unable to import... - triggers for external dependencies like numpy
E0401,
# This was causing false positives
# Appears to be https://github.com/PyCQA/pylint/issues/2981
W0201,
# Using the global statement
W0603,
# "Access to a protected member _foo of a client class (protected-access)"
W0212
正在加载...
取消
保存