diff --git a/.gitignore b/.gitignore index 72d8b65e3ce..de762cac9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -84,4 +84,7 @@ out.* packages/grid/helm/examples/dev/migration.yaml # dynaconf settings file -**/settings.yaml \ No newline at end of file +**/settings.yaml + + +notebooks/scenarios/bigquery/*.json diff --git a/notebooks/api/0.8/05-custom-policy.ipynb b/notebooks/api/0.8/05-custom-policy.ipynb index 3d8777af877..7b383ad0d73 100644 --- a/notebooks/api/0.8/05-custom-policy.ipynb +++ b/notebooks/api/0.8/05-custom-policy.ipynb @@ -135,7 +135,7 @@ " return None\n", " return output_dict\n", "\n", - " def _is_valid(self, context):\n", + " def is_valid(self, context):\n", " return self.state[\"counts\"] < self.n_calls" ] }, @@ -336,11 +336,10 @@ "\n", " return filtered_kwargs\n", "\n", - " def _is_valid(\n", + " def is_valid(\n", " self,\n", " context,\n", " usr_input_kwargs,\n", - " code_item_id,\n", " ):\n", " filtered_input_kwargs = self.filter_kwargs(\n", " kwargs=usr_input_kwargs,\n", diff --git a/notebooks/api/0.8/08-code-version.ipynb b/notebooks/api/0.8/08-code-version.ipynb index f9730077df0..c1d60295d8e 100644 --- a/notebooks/api/0.8/08-code-version.ipynb +++ b/notebooks/api/0.8/08-code-version.ipynb @@ -77,8 +77,8 @@ "outputs": [], "source": [ "datasite_client.register(\n", - " name=\"Jane Doe\",\n", - " email=\"jane@caltech.edu\",\n", + " name=\"Janet Doe\",\n", + " email=\"janet@caltech.edu\",\n", " password=\"abc123\",\n", " password_verify=\"abc123\",\n", " institution=\"Caltech\",\n", @@ -92,7 +92,7 @@ "metadata": {}, "outputs": [], "source": [ - "jane_client = server.login(email=\"jane@caltech.edu\", password=\"abc123\")" + "janet_client = server.login(email=\"janet@caltech.edu\", password=\"abc123\")" ] }, { @@ -128,7 +128,7 @@ "metadata": {}, "outputs": [], "source": [ - "jane_client.code.request_code_execution(code=test_func)" + "janet_client.code.request_code_execution(code=test_func)" ] }, { @@ -137,7 +137,7 @@ "metadata": {}, "outputs": [], "source": [ - "jane_client.code" + "janet_client.code" ] }, { @@ -153,7 +153,7 @@ "metadata": {}, "outputs": [], "source": [ - "jane_client.code_history" + "janet_client.code_history" ] }, { @@ -189,7 +189,7 @@ "metadata": {}, "outputs": [], "source": [ - "jane_client.code.request_code_execution(code=test_func)" + "janet_client.code.request_code_execution(code=test_func)" ] }, { @@ -198,7 +198,7 @@ "metadata": {}, "outputs": [], "source": [ - "jane_client.code_history.test_func" + "janet_client.code_history.test_func" ] }, { @@ -232,7 +232,7 @@ "metadata": {}, "outputs": [], "source": [ - "admin_client.code_histories[\"jane@caltech.edu\"]" + "admin_client.code_histories[\"janet@caltech.edu\"]" ] }, { @@ -241,7 +241,7 @@ "metadata": {}, "outputs": [], "source": [ - "admin_client.code_histories[\"jane@caltech.edu\"].test_func[0]" + "admin_client.code_histories[\"janet@caltech.edu\"].test_func[0]" ] }, { @@ -250,7 +250,7 @@ "metadata": {}, "outputs": [], "source": [ - "test_func_history = admin_client.code_histories[\"jane@caltech.edu\"].test_func" + "test_func_history = admin_client.code_histories[\"janet@caltech.edu\"].test_func" ] }, { @@ -260,7 +260,7 @@ "outputs": [], "source": [ "with sy.raises(sy.SyftException, show=True):\n", - " admin_client.code_histories[\"jane@caltech.edu\"].test_func[-1]" + " admin_client.code_histories[\"janet@caltech.edu\"].test_func[-1]" ] }, { diff --git a/notebooks/api/0.8/12-custom-api-endpoint.ipynb b/notebooks/api/0.8/12-custom-api-endpoint.ipynb index 3db886b66b9..aa60e30dd87 100644 --- a/notebooks/api/0.8/12-custom-api-endpoint.ipynb +++ b/notebooks/api/0.8/12-custom-api-endpoint.ipynb @@ -68,7 +68,7 @@ "def public_endpoint_method(\n", " context,\n", " query: str,\n", - ") -> Any:\n", + ") -> \"Any\":\n", " return context.settings[\"key\"] == \"value\"\n", "\n", "\n", @@ -673,14 +673,16 @@ " _print=False\n", " )" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -691,7 +693,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/00-start-and-configure-server-and-admins.ipynb b/notebooks/scenarios/bigquery/00-start-and-configure-server-and-admins.ipynb index 8235576b5f5..8a438cbc935 100644 --- a/notebooks/scenarios/bigquery/00-start-and-configure-server-and-admins.ipynb +++ b/notebooks/scenarios/bigquery/00-start-and-configure-server-and-admins.ipynb @@ -222,11 +222,6 @@ } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -237,7 +232,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/001-scale-delete-worker-pools.ipynb b/notebooks/scenarios/bigquery/001-scale-delete-worker-pools.ipynb index 0549593495b..4741a74ebce 100644 --- a/notebooks/scenarios/bigquery/001-scale-delete-worker-pools.ipynb +++ b/notebooks/scenarios/bigquery/001-scale-delete-worker-pools.ipynb @@ -415,11 +415,6 @@ } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -430,7 +425,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/01-setup-datasite.ipynb b/notebooks/scenarios/bigquery/01-setup-datasite.ipynb index c734b07298e..6ce2e541480 100644 --- a/notebooks/scenarios/bigquery/01-setup-datasite.ipynb +++ b/notebooks/scenarios/bigquery/01-setup-datasite.ipynb @@ -490,11 +490,6 @@ } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -505,7 +500,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb b/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb index c585aa55a07..b3ca595d812 100644 --- a/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb +++ b/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb @@ -412,11 +412,6 @@ } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -427,7 +422,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/02-configure-api.ipynb b/notebooks/scenarios/bigquery/02-configure-api.ipynb index 854190b1861..9f0051c141c 100644 --- a/notebooks/scenarios/bigquery/02-configure-api.ipynb +++ b/notebooks/scenarios/bigquery/02-configure-api.ipynb @@ -529,11 +529,6 @@ } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -544,7 +539,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/021-create-jobs.ipynb b/notebooks/scenarios/bigquery/021-create-jobs.ipynb index c889100e86b..ea549d3625d 100644 --- a/notebooks/scenarios/bigquery/021-create-jobs.ipynb +++ b/notebooks/scenarios/bigquery/021-create-jobs.ipynb @@ -417,11 +417,6 @@ } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -432,7 +427,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/04-do-review-requests.ipynb b/notebooks/scenarios/bigquery/04-do-review-requests.ipynb index 011c4bf3e25..716eb756c43 100644 --- a/notebooks/scenarios/bigquery/04-do-review-requests.ipynb +++ b/notebooks/scenarios/bigquery/04-do-review-requests.ipynb @@ -70,6 +70,15 @@ ")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "high_client.requests.get_all_pending()" + ] + }, { "cell_type": "code", "execution_count": null, @@ -211,6 +220,24 @@ "save_jobs(jobs)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "high_client.requests.get_all_approved()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "high_client.requests.get_all_rejected()" + ] + }, { "cell_type": "code", "execution_count": null, @@ -238,11 +265,6 @@ } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -253,7 +275,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/042-data_review.ipynb b/notebooks/scenarios/bigquery/042-data_review.ipynb deleted file mode 100644 index 283e8a32e2c..00000000000 --- a/notebooks/scenarios/bigquery/042-data_review.ipynb +++ /dev/null @@ -1,273 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# stdlib\n", - "import os\n", - "\n", - "environment = os.environ.get(\"ORCHESTRA_DEPLOYMENT_TYPE\", \"python\")\n", - "environment" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# third party\n", - "\n", - "# syft absolute\n", - "import syft as sy" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "SERVER_PORT = \"8080\"\n", - "SERVER_URL = f\"http://localhost:{SERVER_PORT}\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "server = sy.orchestra.launch(\n", - " name=\"bigquery-high\",\n", - " dev_mode=True,\n", - " server_side_type=\"high\",\n", - " # reset=True,\n", - " port=SERVER_PORT,\n", - " n_consumers=4, # How many workers to be spawned\n", - " create_producer=True, # Can produce more workers\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ADMIN_EMAIL, ADMIN_PW = \"admin2@bigquery.org\", \"bqpw2\"\n", - "high_client = sy.login(\n", - " url=\"http://localhost:8080\", email=ADMIN_EMAIL, password=ADMIN_PW\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "high_client.requests" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "high_client.requests.get_all_approved()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "high_client.requests[2].code" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "high_client.requests[2].code()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "job = high_client.requests[2].code(blocking=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "job.wait().get()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "high_client.requests.get_all_pending()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for request in high_client.requests.get_all_pending():\n", - " if request.code.service_func_name.startswith(\"wrong_syntax_query\"):\n", - " bad_request = request\n", - " if request.code.service_func_name.startswith(\"simple_query\"):\n", - " good_request = request" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "good_job = good_request.code(blocking=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "good_job.wait()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "good_request.deposit_result(good_job.info, approve=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "high_client.requests.get_all_approved()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# stdlib\n", - "import json\n", - "\n", - "# third party\n", - "from job_helpers import resolve_request\n", - "\n", - "request_dict = {}\n", - "\n", - "for request in high_client.requests:\n", - " request_id, request_status = resolve_request(request)\n", - " request_dict[str(request_id)] = str(request_status)\n", - "\n", - "with open(\".requests.json\", \"w\") as fp:\n", - " json.dump(request_dict, fp)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "bad_job = bad_request.code(blocking=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "bad_job" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "retry_good_job = good_request.code(blocking=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "retry_good_job.wait()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "syft_3.12", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/notebooks/scenarios/bigquery/05-ds-get-results.ipynb b/notebooks/scenarios/bigquery/05-ds-get-results.ipynb index f9f7a36ae84..843fdefcaf6 100644 --- a/notebooks/scenarios/bigquery/05-ds-get-results.ipynb +++ b/notebooks/scenarios/bigquery/05-ds-get-results.ipynb @@ -125,39 +125,39 @@ "outputs": [], "source": [ "for job in reviewed_jobs:\n", - " print(f\"> Checking job: {job.job_type} {job.func_name} for user {job.user_email}\")\n", + " print(\n", + " f\"> Checking job: {job.job_type} {job.func_name} for user {job.user_email} {job.should_succeed}\"\n", + " )\n", " api_method = job.code_method\n", "\n", " if job.should_succeed:\n", - " print(\"Expecting job to succeed\")\n", + " # print(\"Expecting job to succeed\")\n", " j = api_method(blocking=False)\n", - " result = j.wait().get()\n", - " print(\n", - " \"> Got result of type\",\n", - " type(result),\n", - " \"expecting limit\",\n", - " job.settings[\"limit\"],\n", - " )\n", + " res = j.wait()\n", + " if isinstance(res, sy.SyftError):\n", + " job.result_as_expected = False\n", + " print(\"Expected success, got error\")\n", + " continue\n", + "\n", + " result = res.get()\n", " if hasattr(result, \"__len__\"):\n", - " print(\"> Result length\", len(result))\n", - " assert len(result) == job.settings[\"limit\"]\n", + " pass\n", + " # print(\"> Result length\", len(result))\n", + "\n", + " # assert len(result) == job.settings[\"limit\"]\n", + " print(\"success\")\n", " job.result_as_expected = True\n", " save_jobs(jobs)\n", " else:\n", - " print(\"Expecting job to fail\")\n", - " # with sy.raises(\n", - " # sy.SyftException(public_message=\"*UserCodeStatus.DENIED*\"), show=True\n", - " # ):\n", - " # with sy.raises(\n", - " # sy.SyftException, show=True\n", - " # ):\n", - " try:\n", - " j = api_method(blocking=False)\n", + " # print(\"Expecting job to fail\")\n", + " j = api_method(blocking=False)\n", + " res = j.wait()\n", + " if isinstance(res, sy.SyftError):\n", + " job.result_as_expected = True\n", + " print(\"Expected to error, success\")\n", + " else:\n", " print(\"failed job didnt raise\", type(j))\n", " job.result_as_expected = False\n", - " except Exception as e:\n", - " job.result_as_expected = True\n", - " print(\"failed job raised\", type(e))\n", "\n", " save_jobs(jobs)" ] @@ -180,7 +180,7 @@ "source": [ "# TODO fix\n", "print(f\"got expected_jobs: {len(expected_jobs)} == reviewed_jobs: {len(reviewed_jobs)}\")\n", - "# assert len(reviewed_jobs) == len(expected_jobs)" + "assert len(reviewed_jobs) == len(expected_jobs)" ] }, { @@ -210,11 +210,6 @@ } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -225,7 +220,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/job_helpers.py b/notebooks/scenarios/bigquery/job_helpers.py index 69695939ccd..777a781836d 100644 --- a/notebooks/scenarios/bigquery/job_helpers.py +++ b/notebooks/scenarios/bigquery/job_helpers.py @@ -312,7 +312,7 @@ def resolve_request(request): if service_func_name.startswith("job_too_much_text"): request.deny(reason="too long, boring!") # deny because it is bad if service_func_name.startswith("job_long_name"): - request.deny(reason="too long, boring!") # deny because it is bad + request.approve() if service_func_name.startswith("job_funcname_xss"): request.deny(reason="too long, boring!") # never reach doesnt matter if service_func_name.startswith("job_query_xss"): @@ -330,7 +330,6 @@ def resolve_request(request): create_simple_query_job, create_simple_query_job, create_simple_query_job, - create_wrong_asset_query, create_wrong_syntax_query, create_long_query_job, create_query_long_name, diff --git a/notebooks/tutorials/data-owner/02-account-management.ipynb b/notebooks/tutorials/data-owner/02-account-management.ipynb index 66e01be2644..85e7b2fdfeb 100644 --- a/notebooks/tutorials/data-owner/02-account-management.ipynb +++ b/notebooks/tutorials/data-owner/02-account-management.ipynb @@ -352,12 +352,13 @@ "metadata": {}, "outputs": [], "source": [ - "new_user.register(\n", - " email=\"batman@test.com\",\n", - " password=\"batman123\",\n", - " password_verify=\"batman123\",\n", - " name=\"Batman\",\n", - ")" + "with sy.raises(sy.SyftException, show=True):\n", + " new_user.register(\n", + " email=\"batman@test.com\",\n", + " password=\"batman123\",\n", + " password_verify=\"batman123\",\n", + " name=\"Batman\",\n", + " )" ] }, { @@ -428,12 +429,13 @@ "metadata": {}, "outputs": [], "source": [ - "new_user.register(\n", - " email=\"harley@test.com\",\n", - " password=\"harley123\",\n", - " password_verify=\"harley123\",\n", - " name=\"Harley\",\n", - ")" + "with sy.raises(sy.SyftException, show=True):\n", + " new_user.register(\n", + " email=\"harley@test.com\",\n", + " password=\"harley123\",\n", + " password_verify=\"harley123\",\n", + " name=\"Harley\",\n", + " )" ] }, { @@ -460,14 +462,17 @@ "source": [ "client.users" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "46", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -478,7 +483,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.12.5" }, "toc": { "base_numbering": 1, diff --git a/notebooks/tutorials/data-scientist/04-syft-functions.ipynb b/notebooks/tutorials/data-scientist/04-syft-functions.ipynb index b0787b96356..74724c12fee 100644 --- a/notebooks/tutorials/data-scientist/04-syft-functions.ipynb +++ b/notebooks/tutorials/data-scientist/04-syft-functions.ipynb @@ -427,7 +427,8 @@ "metadata": {}, "outputs": [], "source": [ - "guest_client.code.mean(data=asset)" + "with sy.raises(sy.SyftException, show=True):\n", + " guest_client.code.mean(data=asset)" ] }, { @@ -557,8 +558,8 @@ "metadata": {}, "outputs": [], "source": [ - "res_denied = guest_client.code.mean(data=asset)\n", - "res_denied" + "with sy.raises(sy.SyftException, show=True):\n", + " guest_client.code.mean(data=asset)" ] }, { @@ -623,14 +624,17 @@ "source": [ "type(real_res)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -641,7 +645,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.12.5" }, "toc": { "base_numbering": 1, diff --git a/packages/syft/src/syft/service/code/user_code.py b/packages/syft/src/syft/service/code/user_code.py index de096a3afba..3ba1b20a00f 100644 --- a/packages/syft/src/syft/service/code/user_code.py +++ b/packages/syft/src/syft/service/code/user_code.py @@ -12,6 +12,7 @@ from io import StringIO import json import keyword +import logging import random import re import sys @@ -102,6 +103,8 @@ from .utils import parse_code from .utils import submit_subjobs_code +logger = logging.getLogger(name=__name__) + if TYPE_CHECKING: # relative from ...service.sync.diff_state import AttrDiff @@ -1871,13 +1874,11 @@ def to_str(arg: Any) -> str: if context.job is not None: time = datetime.datetime.now().strftime("%d/%m/%y %H:%M:%S") - original_print( - f"{time} EXCEPTION LOG ({job_id}):\n{error_msg}", file=sys.stderr - ) + logger.error(f"{time} EXCEPTION LOG ({job_id}):\n{error_msg}") else: # for local execution time = datetime.datetime.now().strftime("%d/%m/%y %H:%M:%S") - original_print(f"{time} EXCEPTION LOG:\n{error_msg}\n", file=sys.stderr) + logger.error(f"{time} EXCEPTION LOG:\n{error_msg}\n") if ( context.server is not None diff --git a/packages/syft/src/syft/service/notifier/notifier.py b/packages/syft/src/syft/service/notifier/notifier.py index cb000d823f5..8400082303d 100644 --- a/packages/syft/src/syft/service/notifier/notifier.py +++ b/packages/syft/src/syft/service/notifier/notifier.py @@ -136,7 +136,6 @@ def send( return SyftSuccess(message="Email sent successfully!") except Exception as e: message = f"> Error sending email: {subject} to {receiver_email} from: {sender}. {e}" - print(message) logger.error(message) return SyftError(message="Failed to send an email.") # raise SyftException.from_exception( diff --git a/packages/syft/src/syft/store/linked_obj.py b/packages/syft/src/syft/store/linked_obj.py index 3301a95861b..5d9c29c9d9d 100644 --- a/packages/syft/src/syft/store/linked_obj.py +++ b/packages/syft/src/syft/store/linked_obj.py @@ -1,4 +1,5 @@ # stdlib +import logging from typing import Any # third party @@ -16,6 +17,8 @@ from ..types.syft_object import SyftObject from ..types.uid import UID +logger = logging.getLogger(__name__) + @serializable() class LinkedObject(SyftObject): @@ -47,7 +50,7 @@ def resolve(self) -> SyftObject: self._resolve_cache = resolve return resolve except Exception as e: - print(">>> Failed to resolve object", type(api), e) + logger.error(">>> Failed to resolve object", type(api), e) raise e @as_result(SyftException) diff --git a/packages/syft/src/syft/types/errors.py b/packages/syft/src/syft/types/errors.py index 501c6c90048..72e7181f92c 100644 --- a/packages/syft/src/syft/types/errors.py +++ b/packages/syft/src/syft/types/errors.py @@ -15,6 +15,7 @@ from IPython import get_ipython from IPython.display import HTML from IPython.display import display +import psutil from typing_extensions import Self # relative @@ -337,7 +338,19 @@ def syft_exception_handler( display(HTML(evalue._repr_html_())) -try: - get_ipython().set_custom_exc((SyftException,), syft_exception_handler) # noqa: F821 -except Exception: - pass # nosec +runs_in_pytest = False +for pid in psutil.pids(): + try: + if "PYTEST_CURRENT_TEST" in psutil.Process(pid).environ(): + runs_in_pytest = True + except Exception: + pass # nosec + + +# be very careful when changing this. pytest (with nbmake) will +# not pick up exceptions if they have a custom exception handler (fail silently) +if not runs_in_pytest: + try: + get_ipython().set_custom_exc((SyftException,), syft_exception_handler) # noqa: F821 + except Exception: + pass # nosec