Skip to content

Commit aa5629d

Browse files
committed
Merge branch 'dev' into asset-repr-displays-entire-list
2 parents 2a86684 + a0de849 commit aa5629d

8 files changed

Lines changed: 171 additions & 74 deletions

File tree

notebooks/tutorials/version-upgrades/0-prepare-migration-data.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
" name=\"test_upgradability\",\n",
7070
" dev_mode=True,\n",
7171
" reset=True,\n",
72-
" local_db=True,\n",
7372
" n_consumers=2,\n",
7473
" create_producer=True,\n",
74+
" port=\"auto\",\n",
7575
")"
7676
]
7777
},
@@ -251,7 +251,7 @@
251251
"name": "python",
252252
"nbconvert_exporter": "python",
253253
"pygments_lexer": "ipython3",
254-
"version": "3.12.2"
254+
"version": "3.10.13"
255255
}
256256
},
257257
"nbformat": 4,

notebooks/tutorials/version-upgrades/1-dump-database-to-file.ipynb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"outputs": [],
99
"source": [
1010
"# stdlib\n",
11+
"import os\n",
1112
"from pathlib import Path\n",
1213
"\n",
1314
"# syft absolute\n",
@@ -24,9 +25,8 @@
2425
"server = sy.orchestra.launch(\n",
2526
" name=\"test_upgradability\",\n",
2627
" dev_mode=True,\n",
27-
" local_db=True,\n",
28-
" n_consumers=2,\n",
29-
" create_producer=True,\n",
28+
" reset=False,\n",
29+
" port=\"auto\",\n",
3030
" migrate=False,\n",
3131
")\n",
3232
"\n",
@@ -83,8 +83,11 @@
8383
"metadata": {},
8484
"outputs": [],
8585
"source": [
86-
"blob_path = Path(\"./migration.blob\")\n",
87-
"yaml_path = Path(\"migration.yaml\")\n",
86+
"migration_data_dir = Path(os.getenv(\"MIGRATION_DATA_DIR\", \".\"))\n",
87+
"migration_data_dir.mkdir(exist_ok=True)\n",
88+
"\n",
89+
"blob_path = migration_data_dir / \"migration.blob\"\n",
90+
"yaml_path = migration_data_dir / \"migration.yaml\"\n",
8891
"\n",
8992
"blob_path.unlink(missing_ok=True)\n",
9093
"yaml_path.unlink(missing_ok=True)"
@@ -141,7 +144,7 @@
141144
"name": "python",
142145
"nbconvert_exporter": "python",
143146
"pygments_lexer": "ipython3",
144-
"version": "3.12.2"
147+
"version": "3.10.13"
145148
}
146149
},
147150
"nbformat": 4,

notebooks/tutorials/version-upgrades/2-migrate-from-file.ipynb

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"outputs": [],
99
"source": [
1010
"# stdlib\n",
11+
"import os\n",
1112
"from pathlib import Path\n",
1213
"\n",
1314
"# syft absolute\n",
@@ -70,16 +71,37 @@
7071
"metadata": {},
7172
"outputs": [],
7273
"source": [
73-
"blob_path = Path(\"./migration.blob\")\n",
74-
"print(f\"Loading migration data from {str(blob_path.resolve())}\")\n",
74+
"migration_data_dir = Path(os.getenv(\"MIGRATION_DATA_DIR\", \".\"))\n",
75+
"blob_path = migration_data_dir / \"migration.blob\"\n",
76+
"yaml_path = migration_data_dir / \"migration.yaml\"\n",
7577
"\n",
78+
"print(f\"Loading migration data from {str(blob_path.resolve())}\")"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"id": "6",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
7688
"res = client.load_migration_data(blob_path)\n",
77-
"assert isinstance(res, sy.SyftSuccess)"
89+
"assert isinstance(res, sy.SyftSuccess), res.message"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"id": "7",
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"res"
78100
]
79101
},
80102
{
81103
"cell_type": "markdown",
82-
"id": "6",
104+
"id": "8",
83105
"metadata": {},
84106
"source": [
85107
"# Post migration tests"
@@ -88,7 +110,7 @@
88110
{
89111
"cell_type": "code",
90112
"execution_count": null,
91-
"id": "7",
113+
"id": "9",
92114
"metadata": {},
93115
"outputs": [],
94116
"source": [
@@ -98,7 +120,7 @@
98120
{
99121
"cell_type": "code",
100122
"execution_count": null,
101-
"id": "8",
123+
"id": "10",
102124
"metadata": {},
103125
"outputs": [],
104126
"source": [
@@ -108,15 +130,15 @@
108130
{
109131
"cell_type": "code",
110132
"execution_count": null,
111-
"id": "9",
133+
"id": "11",
112134
"metadata": {},
113135
"outputs": [],
114136
"source": []
115137
},
116138
{
117139
"cell_type": "code",
118140
"execution_count": null,
119-
"id": "10",
141+
"id": "12",
120142
"metadata": {},
121143
"outputs": [],
122144
"source": [
@@ -127,7 +149,7 @@
127149
{
128150
"cell_type": "code",
129151
"execution_count": null,
130-
"id": "11",
152+
"id": "13",
131153
"metadata": {},
132154
"outputs": [],
133155
"source": [
@@ -137,7 +159,7 @@
137159
{
138160
"cell_type": "code",
139161
"execution_count": null,
140-
"id": "12",
162+
"id": "14",
141163
"metadata": {},
142164
"outputs": [],
143165
"source": [
@@ -147,7 +169,7 @@
147169
{
148170
"cell_type": "code",
149171
"execution_count": null,
150-
"id": "13",
172+
"id": "15",
151173
"metadata": {},
152174
"outputs": [],
153175
"source": [
@@ -157,7 +179,7 @@
157179
{
158180
"cell_type": "code",
159181
"execution_count": null,
160-
"id": "14",
182+
"id": "16",
161183
"metadata": {},
162184
"outputs": [],
163185
"source": [
@@ -171,7 +193,7 @@
171193
{
172194
"cell_type": "code",
173195
"execution_count": null,
174-
"id": "15",
196+
"id": "17",
175197
"metadata": {},
176198
"outputs": [],
177199
"source": [
@@ -182,7 +204,7 @@
182204
{
183205
"cell_type": "code",
184206
"execution_count": null,
185-
"id": "16",
207+
"id": "18",
186208
"metadata": {},
187209
"outputs": [],
188210
"source": [
@@ -193,7 +215,7 @@
193215
{
194216
"cell_type": "code",
195217
"execution_count": null,
196-
"id": "17",
218+
"id": "19",
197219
"metadata": {},
198220
"outputs": [],
199221
"source": [
@@ -203,7 +225,7 @@
203225
{
204226
"cell_type": "code",
205227
"execution_count": null,
206-
"id": "18",
228+
"id": "20",
207229
"metadata": {},
208230
"outputs": [],
209231
"source": [
@@ -213,7 +235,7 @@
213235
{
214236
"cell_type": "code",
215237
"execution_count": null,
216-
"id": "19",
238+
"id": "21",
217239
"metadata": {},
218240
"outputs": [],
219241
"source": [
@@ -223,7 +245,7 @@
223245
{
224246
"cell_type": "code",
225247
"execution_count": null,
226-
"id": "20",
248+
"id": "22",
227249
"metadata": {},
228250
"outputs": [],
229251
"source": [
@@ -233,7 +255,7 @@
233255
{
234256
"cell_type": "code",
235257
"execution_count": null,
236-
"id": "21",
258+
"id": "23",
237259
"metadata": {},
238260
"outputs": [],
239261
"source": [
@@ -243,7 +265,7 @@
243265
{
244266
"cell_type": "code",
245267
"execution_count": null,
246-
"id": "22",
268+
"id": "24",
247269
"metadata": {},
248270
"outputs": [],
249271
"source": [
@@ -254,7 +276,7 @@
254276
{
255277
"cell_type": "code",
256278
"execution_count": null,
257-
"id": "23",
279+
"id": "25",
258280
"metadata": {},
259281
"outputs": [],
260282
"source": [
@@ -265,7 +287,7 @@
265287
{
266288
"cell_type": "code",
267289
"execution_count": null,
268-
"id": "24",
290+
"id": "26",
269291
"metadata": {},
270292
"outputs": [],
271293
"source": []
@@ -287,7 +309,7 @@
287309
"name": "python",
288310
"nbconvert_exporter": "python",
289311
"pygments_lexer": "ipython3",
290-
"version": "3.12.2"
312+
"version": "3.10.13"
291313
}
292314
},
293315
"nbformat": 4,

packages/syft/src/syft/service/migration/migration_service.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ...store.document_store import StorePartition
1515
from ...types.blob_storage import BlobStorageEntry
1616
from ...types.syft_object import SyftObject
17+
from ...types.syft_object_registry import SyftObjectRegistry
1718
from ..action.action_object import Action
1819
from ..action.action_object import ActionObject
1920
from ..action.action_permissions import ActionObjectPermission
@@ -435,11 +436,15 @@ def _migrate_objects(
435436
migrated_objects = []
436437
for klass, objects in migration_objects.items():
437438
canonical_name = klass.__canonical_name__
439+
latest_version = SyftObjectRegistry.get_latest_version(canonical_name)
440+
438441
# Migrate data for objects in document store
439-
print(f"Migrating data for: {canonical_name} table.")
442+
print(
443+
f"Migrating data for: {canonical_name} table to version {latest_version}"
444+
)
440445
for object in objects:
441446
try:
442-
migrated_value = object.migrate_to(klass.__version__, context)
447+
migrated_value = object.migrate_to(latest_version, context)
443448
migrated_objects.append(migrated_value)
444449
except Exception:
445450
# stdlib

packages/syft/src/syft/service/migration/object_migration_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def make_migration_config(self) -> dict[str, Any]:
164164
def from_file(self, path: str | Path) -> Self | SyftError:
165165
path = Path(path)
166166
if not path.exists():
167-
return SyftError(f"File {str(path)} does not exist.")
167+
return SyftError(message=f"File {str(path)} does not exist.")
168168

169169
with open(path, "rb") as f:
170170
res: MigrationData = _deserialize(f.read(), from_bytes=True)

packages/syft/src/syft/types/syft_object_registry.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def get_versions(cls, canonical_name: str) -> list[int]:
3838
)
3939
return list(available_versions.keys())
4040

41+
@classmethod
42+
def get_latest_version(cls, canonical_name: str) -> int:
43+
available_versions = cls.get_versions(canonical_name)
44+
if not available_versions:
45+
return 0
46+
return sorted(available_versions, reverse=True)[0]
47+
4148
@classmethod
4249
def get_identifier_for_type(cls, obj: Any) -> tuple[str, int]:
4350
"""

scripts/latest_pypi_version.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# third party
2+
import requests
3+
4+
PROJECT_NAME = "syft"
5+
PYPI_JSON_URL = f"https://pypi.org/pypi/{PROJECT_NAME}/json"
6+
7+
8+
def get_latest_pypi_version():
9+
response = requests.get(PYPI_JSON_URL)
10+
data = response.json()
11+
return data["info"]["version"]
12+
13+
14+
print(get_latest_pypi_version())

0 commit comments

Comments
 (0)