Skip to content

Commit

Permalink
Merge pull request #8194 from kiendang/ruff-format
Browse files Browse the repository at this point in the history
Use ruff format to replace black
  • Loading branch information
kiendang authored Oct 26, 2023
2 parents df1a184 + 1455e09 commit a7f36e2
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 44 deletions.
20 changes: 2 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,13 @@ repos:
args: [".", "--settings-path .isort.cfg"]
always_run: true

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
args: ["."]
always_run: true

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: "v0.0.283"
rev: "v0.1.2"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

# - repo: https://github.com/PyCQA/flake8
# rev: 6.0.0
# hooks:
# - id: flake8
# args: ["--config=packages/syft/setup.cfg"]
# always_run: true
# additional_dependencies:
# - flake8-bugbear
# files: "^packages/syft(?!(/tests/|.*_pb2\\.py$)).*\\.py"
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
Expand Down
12 changes: 8 additions & 4 deletions packages/hagrid/hagrid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,22 @@ def cli() -> None:
def get_compose_src_path(
node_name: str,
template_location: Optional[str] = None,
**kwargs: TypeDict[str, Any],
**kwargs: Any,
) -> str:
grid_path = GRID_SRC_PATH()
tag = kwargs["tag"]
# Use local compose files if in editable mode and
# template_location is None and (kwargs["dev"] is True or tag is local)
if EDITABLE_MODE and template_location is None and (kwargs["dev"] is True or tag == "local"): # type: ignore
if (
EDITABLE_MODE
and template_location is None
and (kwargs["dev"] is True or tag == "local")
):
path = grid_path
else:
path = deployment_dir(node_name)

if kwargs["deployment_type"] == "single_container": # type: ignore
if kwargs["deployment_type"] == "single_container":
path = path + "/worker"

os.makedirs(path, exist_ok=True)
Expand Down Expand Up @@ -3420,7 +3424,7 @@ def land(args: TypeTuple[str], **kwargs: Any) -> None:
help="Show HAGrid debug information", context_settings={"show_default": True}
)
@click.argument("args", type=str, nargs=-1)
def debug(args: TypeTuple[str], **kwargs: TypeDict[str, Any]) -> None:
def debug(args: TypeTuple[str], **kwargs: Any) -> None:
debug_info = gather_debug()
print("\n\nWhen reporting bugs, please copy everything between the lines.")
print("==================================================================\n")
Expand Down
7 changes: 4 additions & 3 deletions packages/hagrid/hagrid/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,10 @@ def docker_running(timeout: Optional[float] = None) -> Tuple[bool, str]:
2 - {WHITE}Ubuntu: {GREEN}sudo service docker start {NO_COLOR}
-------------------------------------------------------------------------------------------------------\n
"""
error_msg += f"""{YELLOW}{BOLD}Std Output Logs{NO_COLOR}
=================\n\n""" + "\n".join(
msg
error_msg += (
f"""{YELLOW}{BOLD}Std Output Logs{NO_COLOR}
=================\n\n"""
+ "\n".join(msg)
)

except Exception as e: # nosec
Expand Down
4 changes: 1 addition & 3 deletions packages/hagrid/hagrid/quickstart_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ def download(
jupyter_path = first.replace(os.path.abspath(directory) + "/", "")

html += f'<div class="alert alert-success">{tutorial_name} downloaded.'
html += (
f'<br />📖 <a href="{jupyter_path}">Click to Open Tutorial</a></div>'
)
html += f'<br />📖 <a href="{jupyter_path}">Click to Open Tutorial</a></div>'
return NBOutput(html)

def _repr_html_(self) -> str:
Expand Down
8 changes: 2 additions & 6 deletions packages/syft/src/syft/client/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def check_network(network: Dict) -> Optional[Dict[Any, Any]]:
# If not defined, try to ask in /syft/version endpoint (supported by 0.7.0)
try:
version_url = url + "api/v2/metadata"
res = requests.get(
version_url, timeout=DEFAULT_TIMEOUT
) # nosec
res = requests.get(version_url, timeout=DEFAULT_TIMEOUT) # nosec
if res.status_code == 200:
network["version"] = res.json()["syft_version"]
else:
Expand Down Expand Up @@ -326,9 +324,7 @@ def check_enclave(enclave: Dict) -> Optional[Dict[Any, Any]]:
# If not defined, try to ask in /syft/version endpoint (supported by 0.7.0)
try:
version_url = url + "api/v2/metadata"
res = requests.get(
version_url, timeout=DEFAULT_TIMEOUT
) # nosec
res = requests.get(version_url, timeout=DEFAULT_TIMEOUT) # nosec
if res.status_code == 200:
enclave["version"] = res.json()["syft_version"]
else:
Expand Down
4 changes: 3 additions & 1 deletion packages/syft/src/syft/node/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ def handle_api_call_with_unsigned_result(
f"you have has no access to: {api_call.path}"
) # type: ignore
else:
return SyftError(message=f"API call not in registered services: {api_call.path}") # type: ignore
return SyftError(
message=f"API call not in registered services: {api_call.path}"
) # type: ignore

_private_api_path = user_config_registry.private_path_for(api_call.path)
method = self.get_service_method(_private_api_path)
Expand Down
3 changes: 2 additions & 1 deletion packages/syft/src/syft/service/action/action_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ def syft_make_action_with_self(
def syft_get_path(self) -> str:
"""Get the type path of the underlying object"""
if isinstance(self, AnyActionObject) and self.syft_internal_type:
return f"{self.syft_action_data_type.__name__}" # avoids AnyActionObject errors
# avoids AnyActionObject errors
return f"{self.syft_action_data_type.__name__}"
return f"{type(self).__name__}"

def syft_remote_method(
Expand Down
4 changes: 3 additions & 1 deletion packages/syft/src/syft/service/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ def poll_answer_wizard(poll: ProjectMultipleChoicePoll) -> int:

print("\t" + "=" * 69)
print()
print(w.fill("All done! You have successfully completed the Poll Answer Wizard! 🎩"))
print(
w.fill("All done! You have successfully completed the Poll Answer Wizard! 🎩")
)
print()

return choice
Expand Down
8 changes: 6 additions & 2 deletions packages/syft/src/syft/store/sqlite_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,18 @@ def _set(self, key: UID, value: Any) -> None:
if self._exists(key):
self._update(key, value)
else:
insert_sql = f"insert into {self.table_name} (uid, repr, value) VALUES (?, ?, ?)" # nosec
insert_sql = (
f"insert into {self.table_name} (uid, repr, value) VALUES (?, ?, ?)" # nosec
)
data = _serialize(value, to_bytes=True)
res = self._execute(insert_sql, [str(key), _repr_debug_(value), data])
if res.is_err():
raise ValueError(res.err())

def _update(self, key: UID, value: Any) -> None:
insert_sql = f"update {self.table_name} set uid = ?, repr = ?, value = ? where uid = ?" # nosec
insert_sql = (
f"update {self.table_name} set uid = ?, repr = ?, value = ? where uid = ?" # nosec
)
data = _serialize(value, to_bytes=True)
res = self._execute(insert_sql, [str(key), _repr_debug_(value), data, str(key)])
if res.is_err():
Expand Down
3 changes: 2 additions & 1 deletion packages/syft/src/syft/types/syft_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class SyftBaseObject(pydantic.BaseModel, SyftHashableObject):
class Config:
arbitrary_types_allowed = True

__canonical_name__: str # the name which doesn't change even when there are multiple classes
# the name which doesn't change even when there are multiple classes
__canonical_name__: str
__version__: int # data is always versioned

syft_node_location: Optional[UID]
Expand Down
2 changes: 1 addition & 1 deletion packages/syft/src/syft/util/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Env(SyftObject):

@property
def packages(self) -> list[tuple[str, str]]:
return [(k, v) for k, v in self.packages_dict.items()]
return list(self.packages_dict.items())

def create_local_env(self) -> None:
venv.EnvBuilder()
5 changes: 3 additions & 2 deletions packages/syft/tests/syft/eager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ def my_plan(x=np.array([1, 2, 3, 4, 5, 6])): # noqa: B008
def test_setattribute(worker, guest_client):
root_domain_client = worker.root_client

private_data, mock_data = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]), np.array(
[[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]
private_data, mock_data = (
np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]),
np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]),
)

obj = TwinObject(private_obj=private_data, mock_obj=mock_data)
Expand Down
5 changes: 4 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
line-length = 120
line-length = 88

# Enable flake8-bugbear (`B`) rules.
# https://beta.ruff.rs/docs/configuration/#using-rufftoml
Expand All @@ -17,6 +17,9 @@ ignore = [

target-version = "py38"

[pycodestyle]
max-line-length = 120

[pyupgrade]
# this keeps annotation syntaxes like Union[X, Y] instead of X | Y
# https://beta.ruff.rs/docs/settings/#pyupgrade-keep-runtime-typing
Expand Down

0 comments on commit a7f36e2

Please sign in to comment.