From af8645a42d0233d6d62f7f78f72ea7316483098d Mon Sep 17 00:00:00 2001 From: Paul Abumov Date: Thu, 12 Oct 2023 14:09:21 -0400 Subject: [PATCH] Linting fixes --- .../parlai_test_script.py | 1 - .../webapp/src/static/index.html | 7 -- .../webapp/src/static/index.html | 7 -- .../webapp/src/static/index.html | 7 -- .../architects/ec2/ec2_helpers.py | 3 +- .../architects/router/flask/static/index.html | 7 -- mephisto/abstractions/blueprint.py | 1 + .../static_task/static_agent_state.py | 1 - .../parlai_chat/webapp/src/static/index.html | 7 -- .../databases/local_singleton_database.py | 1 + .../providers/prolific/api/client.py | 1 - mephisto/data_model/exceptions.py | 1 + mephisto/tools/examine_utils.py | 1 - scripts/update_copyright_headers.py | 81 ++++++++----------- .../architects/test_heroku_architect.py | 1 + 15 files changed, 38 insertions(+), 89 deletions(-) diff --git a/examples/parlai_chat_task_demo/parlai_test_script.py b/examples/parlai_chat_task_demo/parlai_test_script.py index 99cf39539..f05518d0b 100644 --- a/examples/parlai_chat_task_demo/parlai_test_script.py +++ b/examples/parlai_chat_task_demo/parlai_test_script.py @@ -34,7 +34,6 @@ class ParlAITaskConfig(build_default_task_config("example")): # type: ignore @task_script(config=ParlAITaskConfig) def main(operator: "Operator", cfg: DictConfig) -> None: - world_opt = {"num_turns": cfg.num_turns, "turn_timeout": cfg.turn_timeout} custom_bundle_path = cfg.mephisto.blueprint.get("custom_source_bundle", None) diff --git a/examples/parlai_chat_task_demo/webapp/src/static/index.html b/examples/parlai_chat_task_demo/webapp/src/static/index.html index a206e8701..5b82997b3 100644 --- a/examples/parlai_chat_task_demo/webapp/src/static/index.html +++ b/examples/parlai_chat_task_demo/webapp/src/static/index.html @@ -1,16 +1,9 @@ - -This source code is licensed under the license found in the -LICENSE file in the root directory of this source tree. - ---> - diff --git a/examples/static_react_task/webapp/src/static/index.html b/examples/static_react_task/webapp/src/static/index.html index 0ad3a5f43..b8e126f27 100644 --- a/examples/static_react_task/webapp/src/static/index.html +++ b/examples/static_react_task/webapp/src/static/index.html @@ -1,16 +1,9 @@ - -This source code is licensed under the license found in the -LICENSE file in the root directory of this source tree. - ---> - diff --git a/examples/static_react_task_with_tips/webapp/src/static/index.html b/examples/static_react_task_with_tips/webapp/src/static/index.html index 855763f9d..28c7e2370 100644 --- a/examples/static_react_task_with_tips/webapp/src/static/index.html +++ b/examples/static_react_task_with_tips/webapp/src/static/index.html @@ -1,16 +1,9 @@ - -This source code is licensed under the license found in the -LICENSE file in the root directory of this source tree. - ---> - diff --git a/mephisto/abstractions/architects/ec2/ec2_helpers.py b/mephisto/abstractions/architects/ec2/ec2_helpers.py index b6f230b5d..ad29a028b 100644 --- a/mephisto/abstractions/architects/ec2/ec2_helpers.py +++ b/mephisto/abstractions/architects/ec2/ec2_helpers.py @@ -132,7 +132,6 @@ def create_hosted_zone(session: boto3.Session, domain_name: str) -> str: zone_id = find_hosted_zone(session, domain_name) if zone_id is None: - res = client.create_hosted_zone( Name=domain_name, CallerReference=str(time.time()), @@ -228,7 +227,7 @@ def register_zone_records( """ # Get details about the load balancer ec2_client = session.client("elbv2") - balancer = ec2_client.describe_load_balancers(LoadBalancerArns=[load_balancer_arn],)[ + balancer = ec2_client.describe_load_balancers(LoadBalancerArns=[load_balancer_arn])[ "LoadBalancers" ][0] load_balancer_dns = balancer["DNSName"] diff --git a/mephisto/abstractions/architects/router/flask/static/index.html b/mephisto/abstractions/architects/router/flask/static/index.html index fcffe0b75..fdadf17a5 100644 --- a/mephisto/abstractions/architects/router/flask/static/index.html +++ b/mephisto/abstractions/architects/router/flask/static/index.html @@ -1,16 +1,9 @@ - -This source code is licensed under the license found in the -LICENSE file in the root directory of this source tree. - ---> - diff --git a/mephisto/abstractions/blueprint.py b/mephisto/abstractions/blueprint.py index e4ccb699d..b9f746048 100644 --- a/mephisto/abstractions/blueprint.py +++ b/mephisto/abstractions/blueprint.py @@ -187,6 +187,7 @@ def mixin_args_and_state(mixin_cls: Type["BlueprintMixin"], target_cls: Type["Bl class MyBlueprint(ABlueprintMixin, Blueprint): pass """ + # Ignore typing on most of this, as mypy is not able to parse what's happening @dataclass class MixedInArgsClass(mixin_cls.ArgsMixin, target_cls.ArgsClass): # type: ignore diff --git a/mephisto/abstractions/blueprints/abstract/static_task/static_agent_state.py b/mephisto/abstractions/blueprints/abstract/static_task/static_agent_state.py index 032437bc2..138cb67c0 100644 --- a/mephisto/abstractions/blueprints/abstract/static_task/static_agent_state.py +++ b/mephisto/abstractions/blueprints/abstract/static_task/static_agent_state.py @@ -36,7 +36,6 @@ def _set_init_state(self, data: Any): self.state["inputs"] = data def get_init_state(self) -> Optional[Dict[str, Any]]: - """ Return the initial state for this agent, None if no such state exists diff --git a/mephisto/abstractions/blueprints/parlai_chat/webapp/src/static/index.html b/mephisto/abstractions/blueprints/parlai_chat/webapp/src/static/index.html index a206e8701..5b82997b3 100644 --- a/mephisto/abstractions/blueprints/parlai_chat/webapp/src/static/index.html +++ b/mephisto/abstractions/blueprints/parlai_chat/webapp/src/static/index.html @@ -1,16 +1,9 @@ - -This source code is licensed under the license found in the -LICENSE file in the root directory of this source tree. - ---> - diff --git a/mephisto/abstractions/databases/local_singleton_database.py b/mephisto/abstractions/databases/local_singleton_database.py index 27728cacf..0e61b3915 100644 --- a/mephisto/abstractions/databases/local_singleton_database.py +++ b/mephisto/abstractions/databases/local_singleton_database.py @@ -37,6 +37,7 @@ logger = get_logger(name=__name__) + # Note: This class could be a generic factory around any MephistoDB, converting # the system to a singleton implementation. It requires all of the data being # updated locally though, so binding to LocalMephistoDB makes sense for now. diff --git a/mephisto/abstractions/providers/prolific/api/client.py b/mephisto/abstractions/providers/prolific/api/client.py index 3e1c1fe94..f1298bb11 100644 --- a/mephisto/abstractions/providers/prolific/api/client.py +++ b/mephisto/abstractions/providers/prolific/api/client.py @@ -45,7 +45,6 @@ def _base_request(cls, *args, **kwargs): class ProlificClient: - Bonuses: Type[_Bonuses] EligibilityRequirements: Type[_EligibilityRequirements] Invitations: Type[_Invitations] diff --git a/mephisto/data_model/exceptions.py b/mephisto/data_model/exceptions.py index 3aa2c9759..bc291c992 100644 --- a/mephisto/data_model/exceptions.py +++ b/mephisto/data_model/exceptions.py @@ -4,6 +4,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. + # types of exceptions thrown when an agent exits the chat. These are thrown # on a failed act call call. If one of these is thrown and not handled, # the world should die and enter cleanup. diff --git a/mephisto/tools/examine_utils.py b/mephisto/tools/examine_utils.py index ca40d6d71..e7ce6eb0a 100644 --- a/mephisto/tools/examine_utils.py +++ b/mephisto/tools/examine_utils.py @@ -223,7 +223,6 @@ def run_examine_by_worker( apply_all_decision = None reason = None for idx, unit in enumerate(w_units): - print( f"Reviewing for worker {worker_name}, ({idx+1}/{len(w_units)}), " f"Previous {format_worker_stats(w_id, previous_work_by_worker)} " diff --git a/scripts/update_copyright_headers.py b/scripts/update_copyright_headers.py index 75eeadd95..1a085111e 100644 --- a/scripts/update_copyright_headers.py +++ b/scripts/update_copyright_headers.py @@ -39,10 +39,7 @@ class UnsupportedFile(Exception): pass -def _add_prefix_suffix( - prefix: str, lines: List[str], suffix: Optional[str] = None -) -> List[str]: - +def _add_prefix_suffix(prefix: str, lines: List[str], suffix: Optional[str] = None) -> List[str]: lines = lines[:] for i, line in enumerate(lines): lines[i] = (prefix or "") + line + (suffix or "") @@ -50,24 +47,18 @@ def _add_prefix_suffix( def _make_copyright_lines(ext: str) -> List[str]: - """ Insert copyright as comment lines specific to file extension """ + """ + Insert copyright as comment lines specific to file extension + """ lines = [] ext = ext.lstrip(".") if ext in ["py", "sh", "yml", "yaml"]: lines = _add_prefix_suffix("# ", COPYRIGHT_LINES) elif ext in ["js", "jsx", "ts", "tsx", "css", "scss"]: - lines = ( - ["/*"] + - _add_prefix_suffix(" * ", COPYRIGHT_LINES) + - [" */"] - ) + lines = ["/*"] + _add_prefix_suffix(" * ", COPYRIGHT_LINES) + [" */"] elif ext in ["md", "html"]: - lines = ( - [""] - ) + lines = [""] else: raise UnsupportedFile(f"Unsupported file extension `{ext}`") @@ -75,7 +66,9 @@ def _make_copyright_lines(ext: str) -> List[str]: def _update_copyright_header(file_path: str, replace_existing: bool = False): - """ Add or replace copyright notice at the top of a file """ + """ + Add or replace copyright notice at the top of a file + """ ext = os.path.splitext(file_path)[1].lower() EXAMINED_LINES = 10 @@ -108,40 +101,38 @@ def _update_copyright_header(file_path: str, replace_existing: bool = False): insert_at_line_number = 0 new_lines = ( - lines[:insert_at_line_number] + - (["\n"] if insert_at_line_number > 0 else [])+ - _make_copyright_lines(ext) + - ["\n"] + - lines[insert_at_line_number:] + lines[:insert_at_line_number] + + (["\n"] if insert_at_line_number > 0 else []) + + _make_copyright_lines(ext) + + ["\n"] + + lines[insert_at_line_number:] ) elif replace_existing: - # Replace old copyright notice + # Replace existing copyright notice print("Updating existing notice") - get_empty_line_numbers = lambda _lines: [i for i, l in enumerate(_lines) if l == "\n"] - empty_line_numbers_before = get_empty_line_numbers(lines[:anchor_line_number]) - if empty_line_numbers_before: - first_line_number = max(empty_line_numbers_before) + 1 - else: - first_line_number = 0 - lines_before_copyright = lines[:first_line_number] - - empty_line_numbers_after = get_empty_line_numbers(lines[anchor_line_number:EXAMINED_LINES]) - if empty_line_numbers_after: - last_line_number = anchor_line_number + min(empty_line_numbers_after) - 1 - else: + first_line_number = 0 + last_line_number = None + for i, line in enumerate(lines[:EXAMINED_LINES]): + if line == "\n": + # Empty line + if i < anchor_line_number: + first_line_number = i + 1 + else: + last_line_number = i - 1 + + if last_line_number is None: raise ProcessingError( - 'Could not find the end of existing copyright notice ' - '(empty line missing right after?)' + "Could not find the end of existing copyright notice " + "(empty line missing right after?)" ) + # Note that we're also replacing an empty line after copyright notice - lines_after_copyright = lines[last_line_number + 2:] + lines_before_copyright = lines[:first_line_number] + lines_after_copyright = lines[last_line_number + 2 :] new_lines = ( - lines_before_copyright + - _make_copyright_lines(ext) + - ["\n"] + - lines_after_copyright + lines_before_copyright + _make_copyright_lines(ext) + ["\n"] + lines_after_copyright ) if new_lines: @@ -169,13 +160,7 @@ def run( valid_file_paths = [ path for path in all_paths - if ( - os.path.isfile(path) and - all( - f"/{ex_dir}/" not in path - for ex_dir in EXCLUDE_DIR_NAMES - ) - ) + if os.path.isfile(path) and all(f"/{ex_dir}/" not in path for ex_dir in EXCLUDE_DIR_NAMES) ] print(f"Processing {len(valid_file_paths)} files") diff --git a/test/abstractions/architects/test_heroku_architect.py b/test/abstractions/architects/test_heroku_architect.py index 97a2d111e..d46018dea 100644 --- a/test/abstractions/architects/test_heroku_architect.py +++ b/test/abstractions/architects/test_heroku_architect.py @@ -23,6 +23,7 @@ from mephisto.operations.hydra_config import MephistoConfig from mephisto.abstractions.blueprints.mock.mock_blueprint import MockSharedState + # TODO(#104) these tests should be marked as nightly's rather than on every run? # Maybe with some kind of LONG TEST flag? Investigate class HerokuArchitectTests(ArchitectTests):