Skip to content

Commit 561767b

Browse files
committed
Adding changes for set and get
1 parent 4f7a747 commit 561767b

8 files changed

Lines changed: 183 additions & 47 deletions

File tree

synapseclient/__main__.py

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ def onweb(args, syn):
379379
syn.onweb(args.id)
380380

381381

382-
def setProvenance(args, syn):
383-
"""Set provenance information on a synapse entity."""
382+
def set_activity(args, syn: synapseclient.Synapse):
383+
"""Set activity information on a synapse entity."""
384384

385385
activity = Activity(name=args.name, description=args.description)
386386

@@ -390,7 +390,7 @@ def setProvenance(args, syn):
390390
if args.executed:
391391
for item in syn._convertProvenanceList(args.executed, args.limitSearch):
392392
activity.used(item, wasExecuted=True)
393-
activity = syn.setProvenance(args.id, activity)
393+
activity = syn.set_activity(args.id, activity)
394394

395395
# Display the activity record, if -o or -output specified
396396
if args.output:
@@ -403,10 +403,22 @@ def setProvenance(args, syn):
403403
f.write("\n")
404404
else:
405405
syn.logger.info(
406-
"Set provenance record %s on entity %s\n", str(activity["id"]), str(args.id)
406+
"Set activity record %s on entity %s\n", str(activity["id"]), str(args.id)
407407
)
408408

409409

410+
@deprecated.sphinx.deprecated(
411+
version="3.1.0",
412+
reason="deprecated and replaced with :py:meth:`set_activity`",
413+
)
414+
def setProvenance(args, syn):
415+
"""Set provenance information on a synapse entity."""
416+
syn.logger.warn(
417+
"deprecated and replaced with `set_activity` -- Deprecated since version 3.1.0"
418+
)
419+
set_activity(args, syn)
420+
421+
410422
def get_activity(args, syn: synapseclient.Synapse):
411423
activity = syn.get_activity(args.id, args.version)
412424

@@ -423,6 +435,9 @@ def get_activity(args, syn: synapseclient.Synapse):
423435
reason="deprecated and replaced with :py:meth:`get_activity`",
424436
)
425437
def getProvenance(args, syn: synapseclient.Synapse):
438+
syn.logger.warn(
439+
"deprecated and replaced with `get_activity` -- Deprecated since version 3.1.0"
440+
)
426441
get_activity(args, syn)
427442

428443

@@ -1417,7 +1432,8 @@ def build_parser():
14171432
parser_config.set_defaults(func=config)
14181433

14191434
parser_set_provenance = subparsers.add_parser(
1420-
"set-provenance", help="create provenance records"
1435+
"set-provenance",
1436+
help="create provenance records. This is *deprecated* - Swap to using `set-activity` instead.",
14211437
)
14221438
parser_set_provenance.add_argument(
14231439
"--id",
@@ -1465,8 +1481,58 @@ def build_parser():
14651481
)
14661482
parser_set_provenance.set_defaults(func=setProvenance)
14671483

1484+
parser_set_activity = subparsers.add_parser(
1485+
"set-activity", help="create activity records"
1486+
)
1487+
parser_set_activity.add_argument(
1488+
"--id",
1489+
metavar="syn123",
1490+
type=str,
1491+
required=True,
1492+
help="Synapse ID of entity whose activity we are accessing.",
1493+
)
1494+
parser_set_activity.add_argument(
1495+
"--name",
1496+
metavar="NAME",
1497+
type=str,
1498+
required=False,
1499+
help="Name of the activity that generated the entity",
1500+
)
1501+
parser_set_activity.add_argument(
1502+
"--description",
1503+
metavar="DESCRIPTION",
1504+
type=str,
1505+
required=False,
1506+
help="Description of the activity that generated the entity",
1507+
)
1508+
parser_set_activity.add_argument(
1509+
"-o",
1510+
"--output",
1511+
metavar="OUTPUT_FILE",
1512+
dest="output",
1513+
const="STDOUT",
1514+
nargs="?",
1515+
type=str,
1516+
help="Output the activity record in JSON format",
1517+
)
1518+
parser_set_activity.add_argument(
1519+
"--used", metavar="target", type=str, nargs="*", help=USED_HELP
1520+
)
1521+
parser_set_activity.add_argument(
1522+
"--executed", metavar="target", type=str, nargs="*", help=EXECUTED_HELP
1523+
)
1524+
parser_set_activity.add_argument(
1525+
"--limitSearch",
1526+
metavar="projId",
1527+
type=str,
1528+
help="Synapse ID of a container such as project or folder to limit search for "
1529+
"activity files.",
1530+
)
1531+
parser_set_activity.set_defaults(func=set_activity)
1532+
14681533
parser_get_provenance = subparsers.add_parser(
1469-
"get-provenance", help="show provenance records"
1534+
"get-provenance",
1535+
help="show provenance records. This is *deprecated* - Swap to using `get-activity` instead.",
14701536
)
14711537
parser_get_provenance.add_argument(
14721538
"--id",
@@ -1493,7 +1559,37 @@ def build_parser():
14931559
type=str,
14941560
help="Output the provenance record in JSON format",
14951561
)
1496-
parser_get_provenance.set_defaults(func=get_activity)
1562+
parser_get_provenance.set_defaults(func=getProvenance)
1563+
1564+
parser_get_activity = subparsers.add_parser(
1565+
"get-activity", help="show activity records."
1566+
)
1567+
parser_get_activity.add_argument(
1568+
"--id",
1569+
metavar="syn123",
1570+
type=str,
1571+
required=True,
1572+
help="Synapse ID of entity whose activity we are accessing.",
1573+
)
1574+
parser_get_activity.add_argument(
1575+
"--version",
1576+
metavar="version",
1577+
type=int,
1578+
required=False,
1579+
help="version of Synapse entity whose activity we are accessing.",
1580+
)
1581+
1582+
parser_get_activity.add_argument(
1583+
"-o",
1584+
"--output",
1585+
metavar="OUTPUT_FILE",
1586+
dest="output",
1587+
const="STDOUT",
1588+
nargs="?",
1589+
type=str,
1590+
help="Output the activity record in JSON format",
1591+
)
1592+
parser_get_activity.set_defaults(func=get_activity)
14971593

14981594
parser_set_annotations = subparsers.add_parser(
14991595
"set-annotations", help="create annotations records"

synapseclient/client.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ def store(
14601460

14611461
# If we have an Activity, set it as the Entity's provenance record
14621462
if activity:
1463-
self.setProvenance(properties, activity)
1463+
self.set_activity(properties, activity)
14641464

14651465
# 'etag' has changed, so get the new Entity
14661466
properties = self._getEntity(properties)
@@ -2231,7 +2231,7 @@ def setPermissions(
22312231
############################################################
22322232
def get_activity(
22332233
self, entity: typing.Union[Entity, str, numbers.Number], version: str = None
2234-
) -> any:
2234+
) -> Activity:
22352235
"""
22362236
Retrieve provenance information for a Synapse Entity.
22372237
@@ -2259,7 +2259,7 @@ def get_activity(
22592259
)
22602260
def getProvenance(
22612261
self, entity: typing.Union[Entity, str, numbers.Number], version: str = None
2262-
):
2262+
) -> Activity:
22632263
"""
22642264
Deprecated and replaced with :py:meth:`get_activity`.
22652265
@@ -2274,7 +2274,26 @@ def getProvenance(
22742274
"""
22752275
return self.get_activity(entity, version)
22762276

2277-
def setProvenance(self, entity, activity):
2277+
@deprecated.sphinx.deprecated(
2278+
version="3.1.0",
2279+
reason="deprecated and replaced with :py:meth:`set_activity`",
2280+
)
2281+
def setProvenance(
2282+
self, entity: typing.Union[Entity, str, numbers.Number], activity: Activity
2283+
):
2284+
"""
2285+
Stores a record of the code and data used to derive a Synapse entity.
2286+
2287+
:param entity: An Entity or Synapse ID to modify
2288+
:param activity: a :py:class:`synapseclient.activity.Activity`
2289+
2290+
:returns: An updated :py:class:`synapseclient.activity.Activity` object
2291+
"""
2292+
return self.set_activity(entity, activity)
2293+
2294+
def set_activity(
2295+
self, entity: typing.Union[Entity, str, numbers.Number], activity: Activity
2296+
):
22782297
"""
22792298
Stores a record of the code and data used to derive a Synapse entity.
22802299
@@ -2293,10 +2312,26 @@ def setProvenance(self, entity, activity):
22932312

22942313
return activity
22952314

2296-
def deleteProvenance(self, entity):
2315+
@deprecated.sphinx.deprecated(
2316+
version="3.1.0",
2317+
reason="deprecated and replaced with :py:meth:`delete_activity`",
2318+
)
2319+
def deleteProvenance(
2320+
self, entity: typing.Union[Entity, str, numbers.Number]
2321+
) -> None:
22972322
"""
22982323
Removes provenance information from an Entity and deletes the associated Activity.
22992324
2325+
:param entity: An Entity or Synapse ID to modify
2326+
"""
2327+
self.delete_activity(entity)
2328+
2329+
def delete_activity(
2330+
self, entity: typing.Union[Entity, str, numbers.Number]
2331+
) -> None:
2332+
"""
2333+
Removes activity information from an Entity and deletes the associated Activity.
2334+
23002335
:param entity: An Entity or Synapse ID to modify
23012336
"""
23022337

synapseutils/sync.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
import concurrent.futures
33
from contextlib import contextmanager
44
import io
5+
import numbers
56
import os
67
import re
78
import sys
89
import threading
910
import typing
1011

12+
import synapseclient
13+
1114
from .monitor import notifyMe
12-
from synapseclient.entity import is_container
15+
from synapseclient.entity import Entity, is_container
1316
from synapseclient.core import config
1417
from synapseclient.core.utils import id_of, is_url, is_synapse_id_str
1518
from synapseclient import File, table
@@ -764,18 +767,20 @@ def _extract_file_entity_metadata(syn, allFiles, *, provenance_cache=None):
764767
return keys, data
765768

766769

767-
def _get_file_entity_provenance_dict(syn, entity):
770+
def _get_file_entity_provenance_dict(
771+
syn: synapseclient.Synapse, entity: typing.Union[Entity, str, numbers.Number]
772+
) -> dict:
768773
"""
769774
Returns a dict with a subset of the provenance metadata for the entity.
770775
An empty dict is returned if the metadata does not have a provenance record.
771776
"""
772777
try:
773-
prov = syn.getProvenance(entity)
778+
activity = syn.get_activity(entity)
774779
return {
775-
"used": ";".join(prov._getUsedStringList()),
776-
"executed": ";".join(prov._getExecutedStringList()),
777-
"activityName": prov.get("name", ""),
778-
"activityDescription": prov.get("description", ""),
780+
"used": ";".join(activity._getUsedStringList()),
781+
"executed": ";".join(activity._getExecutedStringList()),
782+
"activityName": activity.get("name", ""),
783+
"activityDescription": activity.get("description", ""),
779784
}
780785
except SynapseHTTPError as e:
781786
if e.response.status_code == 404:

tests/integration/synapseclient/integration_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,10 @@ def test_provenance(syn, project, schedule_for_cleanup):
350350
{"name": "Superhack", "url": "https://github.com/joe_coder/Superhack"},
351351
wasExecuted=True,
352352
)
353-
activity = syn.setProvenance(data_entity, activity)
353+
activity = syn.set_activity(data_entity, activity)
354354

355355
# Retrieve and verify the saved Provenance record
356-
retrieved_activity = syn.getProvenance(data_entity)
356+
retrieved_activity = syn.get_activity(data_entity)
357357
assert retrieved_activity == activity
358358

359359
# Test Activity update
@@ -365,7 +365,7 @@ def test_provenance(syn, project, schedule_for_cleanup):
365365

366366
# Test delete
367367
syn.deleteProvenance(data_entity)
368-
pytest.raises(SynapseHTTPError, syn.getProvenance, data_entity["id"])
368+
pytest.raises(SynapseHTTPError, syn.get_activity, data_entity["id"])
369369

370370

371371
def test_annotations(syn, project, schedule_for_cleanup):

tests/integration/synapseclient/integration_test_Entity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def test_store_activity(syn, project, schedule_for_cleanup):
355355
entity = syn.store(entity, activity=honking)
356356

357357
# But this does
358-
honking = syn.getProvenance(entity.id)
358+
honking = syn.get_activity(entity.id)
359359

360360
# Verify the Activity
361361
assert honking["name"] == "Hinkle horn honking"
@@ -384,7 +384,7 @@ def test_store_activity(syn, project, schedule_for_cleanup):
384384
entity = syn.store(entity, activity=honking)
385385

386386
# The Activities should match
387-
honking2 = syn.getProvenance(entity)
387+
honking2 = syn.get_activity(entity)
388388
assert honking["id"] == honking2["id"]
389389

390390

tests/integration/synapseclient/test_command_line_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,10 +701,10 @@ def test_command_copy(test_state):
701701
copied_ent_annot = test_state.syn.get_annotations(copied_id)
702702
copied_url_annot = test_state.syn.get_annotations(copied_URL_id)
703703

704-
copied_prov = test_state.syn.getProvenance(copied_id)["used"][0]["reference"][
704+
copied_prov = test_state.syn.get_activity(copied_id)["used"][0]["reference"][
705705
"targetId"
706706
]
707-
copied_url_prov = test_state.syn.getProvenance(copied_URL_id)["used"][0][
707+
copied_url_prov = test_state.syn.get_activity(copied_URL_id)["used"][0][
708708
"reference"
709709
]["targetId"]
710710

tests/integration/synapseutils/test_synapseutils_copy.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_copy(syn, schedule_for_cleanup):
5151
)
5252
syn.set_annotations(Annotations(file_entity, file_entity.etag, annos))
5353
syn.set_annotations(Annotations(externalURL_entity, externalURL_entity.etag, annos))
54-
syn.setProvenance(externalURL_entity.id, prov)
54+
syn.set_activity(externalURL_entity.id, prov)
5555
schedule_for_cleanup(file_entity.id)
5656
schedule_for_cleanup(externalURL_entity.id)
5757
# ------------------------------------
@@ -71,8 +71,8 @@ def test_copy(syn, schedule_for_cleanup):
7171

7272
copied_ent_annot = syn.get_annotations(copied_ent)
7373
copied_url_annot = syn.get_annotations(copied_URL_ent)
74-
copied_prov = syn.getProvenance(copied_ent)
75-
copied_url_prov = syn.getProvenance(copied_URL_ent)
74+
copied_prov = syn.get_activity(copied_ent)
75+
copied_url_prov = syn.get_activity(copied_URL_ent)
7676
schedule_for_cleanup(copied_ent.id)
7777
schedule_for_cleanup(copied_URL_ent.id)
7878

@@ -111,27 +111,27 @@ def test_copy(syn, schedule_for_cleanup):
111111
syn,
112112
file_entity.id,
113113
destinationId=third_folder.id,
114-
setProvenance="gib",
114+
set_activity="gib",
115115
)
116116
pytest.raises(
117117
ValueError, synapseutils.copy, syn, file_entity.id, destinationId=file_entity.id
118118
)
119119

120-
# Test: setProvenance = None
120+
# Test: set_activity = None
121121
output = synapseutils.copy(
122-
syn, file_entity.id, destinationId=second_folder.id, setProvenance=None
122+
syn, file_entity.id, destinationId=second_folder.id, set_activity=None
123123
)
124-
pytest.raises(SynapseHTTPError, syn.getProvenance, output[file_entity.id])
124+
pytest.raises(SynapseHTTPError, syn.get_activity, output[file_entity.id])
125125
schedule_for_cleanup(output[file_entity.id])
126126

127-
# Test: setProvenance = Existing
127+
# Test: set_activity = Existing
128128
output_URL = synapseutils.copy(
129129
syn,
130130
externalURL_entity.id,
131131
destinationId=second_folder.id,
132-
setProvenance="existing",
132+
set_activity="existing",
133133
)
134-
output_prov = syn.getProvenance(output_URL[externalURL_entity.id])
134+
output_prov = syn.get_activity(output_URL[externalURL_entity.id])
135135
schedule_for_cleanup(output_URL[externalURL_entity.id])
136136
assert output_prov["name"] == prov["name"]
137137
assert output_prov["used"] == prov["used"]

0 commit comments

Comments
 (0)