diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7de2532f6d..47380e103d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,8 +27,20 @@ repos: files: "gym-unity/.*" args: [--ignore-missing-imports, --disallow-incomplete-defs] +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.1 + hooks: + - id: flake8 + exclude: > + (?x)^( + .*_pb2.py| + .*_pb2_grpc.py + )$ + # flake8-tidy-imports is used for banned-modules, not actually tidying + additional_dependencies: [flake8-comprehensions==3.2.2, flake8-tidy-imports==4.1.0, flake8-bugbear==20.1.4] + - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 + rev: v2.5.0 hooks: - id: mixed-line-ending exclude: > @@ -38,14 +50,7 @@ repos: .*.meta )$ args: [--fix=lf] - - id: flake8 - exclude: > - (?x)^( - .*_pb2.py| - .*_pb2_grpc.py - )$ - # flake8-tidy-imports is used for banned-modules, not actually tidying - additional_dependencies: [flake8-comprehensions==3.1.4, flake8-tidy-imports==4.0.0, flake8-bugbear==20.1.2] + - id: trailing-whitespace name: trailing-whitespace-markdown types: [markdown] diff --git a/ml-agents/mlagents/trainers/ppo/trainer.py b/ml-agents/mlagents/trainers/ppo/trainer.py index 6b2f81b9f8..6cbc47a297 100644 --- a/ml-agents/mlagents/trainers/ppo/trainer.py +++ b/ml-agents/mlagents/trainers/ppo/trainer.py @@ -203,9 +203,9 @@ def _update_policy(self): self.update_buffer.shuffle(sequence_length=self.policy.sequence_length) buffer = self.update_buffer max_num_batch = buffer_length // batch_size - for l in range(0, max_num_batch * batch_size, batch_size): + for i in range(0, max_num_batch * batch_size, batch_size): update_stats = self.optimizer.update( - buffer.make_mini_batch(l, l + batch_size), n_sequences + buffer.make_mini_batch(i, i + batch_size), n_sequences ) for stat_name, value in update_stats.items(): batch_update_stats[stat_name].append(value) diff --git a/ml-agents/mlagents/trainers/subprocess_env_manager.py b/ml-agents/mlagents/trainers/subprocess_env_manager.py index badff20104..0687cbdf14 100644 --- a/ml-agents/mlagents/trainers/subprocess_env_manager.py +++ b/ml-agents/mlagents/trainers/subprocess_env_manager.py @@ -301,7 +301,7 @@ def external_brains(self) -> Dict[BehaviorName, BrainParameters]: return self.env_workers[0].recv().payload def close(self) -> None: - logger.debug(f"SubprocessEnvManager closing.") + logger.debug("SubprocessEnvManager closing.") self.step_queue.close() self.step_queue.join_thread() for env_worker in self.env_workers: diff --git a/ml-agents/tests/yamato/check_coverage_percent.py b/ml-agents/tests/yamato/check_coverage_percent.py index a4b10105e7..e3f2f11f76 100644 --- a/ml-agents/tests/yamato/check_coverage_percent.py +++ b/ml-agents/tests/yamato/check_coverage_percent.py @@ -25,9 +25,9 @@ def check_coverage(root_dir, min_percentage): # Rather than try to parse the XML, just look for a line of the form # 73.9 lines = f.readlines() - for l in lines: - if "Linecoverage" in l: - pct = l.replace("", "").replace("", "") + for line in lines: + if "Linecoverage" in line: + pct = line.replace("", "").replace("", "") pct = float(pct) if pct < min_percentage: print( diff --git a/ml-agents/tests/yamato/yamato_utils.py b/ml-agents/tests/yamato/yamato_utils.py index 7939836ff1..399ede176d 100644 --- a/ml-agents/tests/yamato/yamato_utils.py +++ b/ml-agents/tests/yamato/yamato_utils.py @@ -149,7 +149,7 @@ def undo_git_checkout(): subprocess.check_call("git reset HEAD .", shell=True) subprocess.check_call("git checkout -- .", shell=True) # Ensure the cache isn't polluted with old compiled assemblies. - subprocess.check_call(f"rm -rf Project/Library", shell=True) + subprocess.check_call("rm -rf Project/Library", shell=True) def override_config_file(src_path, dest_path, **kwargs): diff --git a/utils/validate_versions.py b/utils/validate_versions.py index 4833387402..6d41ea33fa 100755 --- a/utils/validate_versions.py +++ b/utils/validate_versions.py @@ -39,9 +39,9 @@ def _escape_non_none(s: Optional[str]) -> str: def extract_version_string(filename): with open(filename) as f: - for l in f.readlines(): - if l.startswith(VERSION_LINE_START): - return l.replace(VERSION_LINE_START, "").strip() + for line in f.readlines(): + if line.startswith(VERSION_LINE_START): + return line.replace(VERSION_LINE_START, "").strip() return None