diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 58d9b674fa8..35c749afd5c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/packages/hagrid/hagrid/cli.py b/packages/hagrid/hagrid/cli.py index 35852e6521f..62817c43612 100644 --- a/packages/hagrid/hagrid/cli.py +++ b/packages/hagrid/hagrid/cli.py @@ -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) @@ -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") diff --git a/packages/hagrid/hagrid/deps.py b/packages/hagrid/hagrid/deps.py index f0062e65545..8b82ade0430 100644 --- a/packages/hagrid/hagrid/deps.py +++ b/packages/hagrid/hagrid/deps.py @@ -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 diff --git a/packages/hagrid/hagrid/quickstart_ui.py b/packages/hagrid/hagrid/quickstart_ui.py index 49c84ce5e9e..0492a94aa99 100644 --- a/packages/hagrid/hagrid/quickstart_ui.py +++ b/packages/hagrid/hagrid/quickstart_ui.py @@ -269,9 +269,7 @@ def download( jupyter_path = first.replace(os.path.abspath(directory) + "/", "") html += f'
{tutorial_name} downloaded.' - html += ( - f'
📖 Click to Open Tutorial
' - ) + html += f'
📖 Click to Open Tutorial' return NBOutput(html) def _repr_html_(self) -> str: diff --git a/packages/syft/src/syft/client/registry.py b/packages/syft/src/syft/client/registry.py index b5008344a3d..f25e24ab2bf 100644 --- a/packages/syft/src/syft/client/registry.py +++ b/packages/syft/src/syft/client/registry.py @@ -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: @@ -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: diff --git a/packages/syft/src/syft/node/node.py b/packages/syft/src/syft/node/node.py index f0b26cdec1f..ca7c4ee444e 100644 --- a/packages/syft/src/syft/node/node.py +++ b/packages/syft/src/syft/node/node.py @@ -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) diff --git a/packages/syft/src/syft/service/action/action_object.py b/packages/syft/src/syft/service/action/action_object.py index f713bb69c9a..b833fcbf09b 100644 --- a/packages/syft/src/syft/service/action/action_object.py +++ b/packages/syft/src/syft/service/action/action_object.py @@ -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( diff --git a/packages/syft/src/syft/service/project/project.py b/packages/syft/src/syft/service/project/project.py index b343f170f20..9fbf7218974 100644 --- a/packages/syft/src/syft/service/project/project.py +++ b/packages/syft/src/syft/service/project/project.py @@ -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 diff --git a/packages/syft/src/syft/store/sqlite_document_store.py b/packages/syft/src/syft/store/sqlite_document_store.py index 856f604da09..0cb1cd11b4e 100644 --- a/packages/syft/src/syft/store/sqlite_document_store.py +++ b/packages/syft/src/syft/store/sqlite_document_store.py @@ -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(): diff --git a/packages/syft/src/syft/types/syft_object.py b/packages/syft/src/syft/types/syft_object.py index 49f89f4f99d..b3226adeaf0 100644 --- a/packages/syft/src/syft/types/syft_object.py +++ b/packages/syft/src/syft/types/syft_object.py @@ -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] diff --git a/packages/syft/src/syft/util/env.py b/packages/syft/src/syft/util/env.py index 7d7ab43f19f..af3024af67f 100644 --- a/packages/syft/src/syft/util/env.py +++ b/packages/syft/src/syft/util/env.py @@ -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() diff --git a/packages/syft/tests/syft/eager_test.py b/packages/syft/tests/syft/eager_test.py index 6870e444811..63a907ff6c3 100644 --- a/packages/syft/tests/syft/eager_test.py +++ b/packages/syft/tests/syft/eager_test.py @@ -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) diff --git a/ruff.toml b/ruff.toml index f392c081370..507b2c0697c 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,4 +1,4 @@ -line-length = 120 +line-length = 88 # Enable flake8-bugbear (`B`) rules. # https://beta.ruff.rs/docs/configuration/#using-rufftoml @@ -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