Skip to content

Commit

Permalink
Merge branch 'dev' into dataset-actionobj-delete-apis
Browse files Browse the repository at this point in the history
  • Loading branch information
khoaguin committed Jul 5, 2024
2 parents 41ad01a + 4c97cb4 commit 351ffc4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/syft/src/syft/node/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ def attach_debugger() -> None:
print(
"\nStarting the server with the Python Debugger enabled (`debug=True`).\n"
'To attach the debugger, open the command palette in VSCode and select "Debug: Start Debugging (F5)".\n'
f"Then, enter `{debug_port}` in the port field and press Enter.\n"
f"Then, enter `{debug_port}` in the port field and press Enter.\n",
flush=True,
)
print(f"Waiting for debugger to attach on port `{debug_port}`...")
print(f"Waiting for debugger to attach on port `{debug_port}`...", flush=True)
debugpy.wait_for_client() # blocks execution until a remote debugger is attached
print("Debugger attached")
print("Debugger attached", flush=True)


def run_uvicorn(
Expand Down
7 changes: 7 additions & 0 deletions packages/syft/src/syft/protocol/protocol_version.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@
"hash": "e124f56ddf4565df2be056553eecd15de7c80bd5f5fd0d06e8ff7815bb05563a",
"action": "add"
}
},
"EmptyInputPolicy": {
"2": {
"version": 2,
"hash": "3117e16cbe4dbc344ab90fbbd36ba90dfb518e66f0fb07644bbe7864dcdeb309",
"action": "add"
}
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions packages/syft/src/syft/service/code/user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from typing import final

# third party
from IPython.display import HTML
from IPython.display import Markdown
from IPython.display import display
from pydantic import ValidationError
from pydantic import field_validator
Expand Down Expand Up @@ -71,6 +73,7 @@
from ...util.decorators import deprecated
from ...util.markdown import CodeMarkdown
from ...util.markdown import as_markdown_code
from ...util.notebook_ui.styles import FONT_CSS
from ...util.util import prompt_warning_message
from ..action.action_endpoint import CustomEndpointActionObject
from ..action.action_object import Action
Expand Down Expand Up @@ -917,6 +920,62 @@ def _inner_repr(self, level: int = 0) -> str:
def _repr_markdown_(self, wrap_as_python: bool = True, indent: int = 0) -> str:
return as_markdown_code(self._inner_repr())

def _ipython_display_(self, level: int = 0) -> None:
tabs = " " * level
shared_with_line = ""
if len(self.output_readers) > 0 and self.output_reader_names is not None:
owners_string = " and ".join([f"*{x}*" for x in self.output_reader_names])
shared_with_line += (
f"<p>{tabs}Custom Policy: "
f"outputs are *shared* with the owners of {owners_string} once computed</p>"
)
constants_str = ""
args = [
x
for _dict in self.input_policy_init_kwargs.values() # type: ignore
for x in _dict.values()
]
constants = [x for x in args if isinstance(x, Constant)]
constants_str = "\n&emsp;".join([f"{x.kw}: {x.val}" for x in constants])
# indent all lines except the first one
asset_str = "<br>".join(
[f"&emsp;&emsp;{line}" for line in self._asset_json.split("\n")]
).lstrip()

repr_str = f"""
<style>
{FONT_CSS}
.syft-code {{color: {SURFACE[options.color_theme]};}}
.syft-code h3,
.syft-code p {{font-family: 'Open Sans'}}
</style>
<div class="syft-code">
<h3>{tabs}UserCode</h3>
<p>{tabs}<strong>id:</strong> UID = {self.id}</p>
<p>{tabs}<strong>service_func_name:</strong> str = {self.service_func_name}</p>
<p>{tabs}<strong>shareholders:</strong> list = {self.input_owners}</p>
<p>{tabs}<strong>status:</strong> list = {self.code_status}</p>
{tabs}{constants_str}
{tabs}{shared_with_line}
<p>{tabs}<strong>assets:</strong> dict = {asset_str}</p>
<p>{tabs}<strong>code:</strong></p>
</div>
"""
md = "\n".join(
[f"{' '*level}{substring}" for substring in self.raw_code.split("\n")[:-1]]
)
display(HTML(repr_str), Markdown(as_markdown_code(md)))
if self.nested_codes is not None and self.nested_codes != {}:
nested_line_html = f"""
<div class="syft-code">
<p>{tabs}<strong>Nested Requests:</p>
</div>
"""
display(HTML(nested_line_html))
for obj, _ in self.nested_codes.values():
code = obj.resolve
code._ipython_display_(level=level + 1)

@property
def show_code(self) -> CodeMarkdown:
return CodeMarkdown(self.raw_code)
Expand Down
1 change: 1 addition & 0 deletions packages/syft/src/syft/service/policy/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ class UserInputPolicy(InputPolicy):
pass


@serializable()
class EmpyInputPolicy(InputPolicy):
__canonical_name__ = "EmptyInputPolicy"
pass
Expand Down

0 comments on commit 351ffc4

Please sign in to comment.