Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
meta-paul committed Oct 12, 2023
1 parent 5ab87f1 commit af8645a
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 89 deletions.
1 change: 0 additions & 1 deletion examples/parlai_chat_task_demo/parlai_test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions examples/parlai_chat_task_demo/webapp/src/static/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<!--
<!---
Copyright (c) Meta Platforms and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->

This source code is licensed under the license found in the
LICENSE file in the root directory of this source tree.

-->

<!DOCTYPE html>
<html>
<head>
Expand Down
7 changes: 0 additions & 7 deletions examples/static_react_task/webapp/src/static/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<!--
<!---
Copyright (c) Meta Platforms and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->

This source code is licensed under the license found in the
LICENSE file in the root directory of this source tree.

-->

<!DOCTYPE html>
<html>
<head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<!--
<!---
Copyright (c) Meta Platforms and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->

This source code is licensed under the license found in the
LICENSE file in the root directory of this source tree.

-->

<!DOCTYPE html>
<html>
<head>
Expand Down
3 changes: 1 addition & 2 deletions mephisto/abstractions/architects/ec2/ec2_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<!--
<!---
Copyright (c) Meta Platforms and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->

This source code is licensed under the license found in the
LICENSE file in the root directory of this source tree.

-->

<!DOCTYPE html>
<html>
<head>
Expand Down
1 change: 1 addition & 0 deletions mephisto/abstractions/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<!--
<!---
Copyright (c) Meta Platforms and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->

This source code is licensed under the license found in the
LICENSE file in the root directory of this source tree.

-->

<!DOCTYPE html>
<html>
<head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion mephisto/abstractions/providers/prolific/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def _base_request(cls, *args, **kwargs):


class ProlificClient:

Bonuses: Type[_Bonuses]
EligibilityRequirements: Type[_EligibilityRequirements]
Invitations: Type[_Invitations]
Expand Down
1 change: 1 addition & 0 deletions mephisto/data_model/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion mephisto/tools/examine_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)} "
Expand Down
81 changes: 33 additions & 48 deletions scripts/update_copyright_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,36 @@ 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 "")
return lines


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 = (
["<!---"] +
_add_prefix_suffix(" ", COPYRIGHT_LINES) +
["-->"]
)
lines = ["<!---"] + _add_prefix_suffix(" ", COPYRIGHT_LINES) + ["-->"]
else:
raise UnsupportedFile(f"Unsupported file extension `{ext}`")

return _add_prefix_suffix(None, lines, "\n")


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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions test/abstractions/architects/test_heroku_architect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit af8645a

Please sign in to comment.