Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
name: isort (python)

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 26.3.1
hooks:
- id: black
language_version: python3
Expand Down
192 changes: 146 additions & 46 deletions Pipfile.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

All steps also include setting a number of annotations for the objects.
"""

import os
import uuid
from datetime import datetime, timedelta, timezone
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorials/python/tutorial_scripts/upload_data_in_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@

# After finding the row we want to update let's go ahead and add a relationship to
# another file in our manifest. This allows us to say "We used 'this' file in some way".
df.loc[
row_index, "used"
] = f"{DIRECTORY_FOR_MY_PROJECT}/single_cell_RNAseq_batch_1/SRR12345678_R1.fastq.gz"
df.loc[row_index, "used"] = (
f"{DIRECTORY_FOR_MY_PROJECT}/single_cell_RNAseq_batch_1/SRR12345678_R1.fastq.gz"
)

# Let's also link to the pipeline that we ran in order to produce these results. In a
# real scenario you may want to link to a specific run of the tool where the results
# were produced.
df.loc[row_index, "executed"] = "https://nf-co.re/rnaseq/3.14.0"

# Let's also add a description for this Activity/Provenance
df.loc[
row_index, "activityDescription"
] = "Experiment results created as a result of the linked data while running the pipeline."
df.loc[row_index, "activityDescription"] = (
"Experiment results created as a result of the linked data while running the pipeline."
)

# Write the DataFrame back to the manifest file
df.to_csv(PATH_TO_MANIFEST_FILE, sep="\t", index=False)
Expand Down
1 change: 1 addition & 0 deletions docs/tutorials/python/tutorial_scripts/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
7. Delete wiki pages

"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to cause the line numbers in the tutorial to be incorrect by 1 line.

import os

from synapseclient import Synapse
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/python/wiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In this tutorial you will:
## 1. Create a Wiki page
### Initial setup
```python
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=15-31}
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=16-31}
```
A Wiki page requires an owner object, a title, and markdown. Here is an example to create a new root Wiki page for your project with plain text markdown:
```python
Expand Down
12 changes: 6 additions & 6 deletions synapseclient/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def used(

resource = target
if "concreteType" not in resource:
resource[
"concreteType"
] = "org.sagebionetworks.repo.model.provenance.UsedEntity"
resource["concreteType"] = (
"org.sagebionetworks.repo.model.provenance.UsedEntity"
)

# -- Used URL
elif is_used_url(target):
Expand All @@ -234,9 +234,9 @@ def used(

resource = target
if "concreteType" not in resource:
resource[
"concreteType"
] = "org.sagebionetworks.repo.model.provenance.UsedURL"
resource["concreteType"] = (
"org.sagebionetworks.repo.model.provenance.UsedURL"
)

# -- Synapse Entity
elif is_synapse_entity(target):
Expand Down
1 change: 1 addition & 0 deletions synapseclient/api/docker_commit_services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module is responsible for exposing the services defined at:
<https://rest-docs.synapse.org/rest/#org.sagebionetworks.repo.web.controller.DockerCommitController>
"""

from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion synapseclient/api/file_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ async def post_external_filehandle(
"contentSize": file_size,
}
if mimetype is None:
(mimetype, _) = mimetypes.guess_type(external_url, strict=False)
mimetype, _ = mimetypes.guess_type(external_url, strict=False)
if mimetype is not None:
file_handle["contentType"] = mimetype
return await client.rest_post_async(
Expand Down
42 changes: 23 additions & 19 deletions synapseclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The `Synapse` object encapsulates a connection to the Synapse service and is used for building projects, uploading and
retrieving data, and recording provenance of data analysis.
"""

import asyncio
import collections
import collections.abc
Expand Down Expand Up @@ -607,9 +608,7 @@ def _init_logger(self):
logger_name = (
SILENT_LOGGER_NAME
if self.silent
else DEBUG_LOGGER_NAME
if self.debug
else DEFAULT_LOGGER_NAME
else DEBUG_LOGGER_NAME if self.debug else DEFAULT_LOGGER_NAME
)
self.logger = logging.getLogger(logger_name)
logging.getLogger("py.warnings").handlers = self.logger.handlers
Expand Down Expand Up @@ -2672,9 +2671,11 @@ async def main():
fileHandle = await upload_file_handle_async(
self,
parent_id_for_upload,
local_state["path"]
if (synapseStore or local_state_fh.get("externalURL") is None)
else local_state_fh.get("externalURL"),
(
local_state["path"]
if (synapseStore or local_state_fh.get("externalURL") is None)
else local_state_fh.get("externalURL")
),
synapse_store=synapseStore,
md5=local_file_md5_hex or local_state_fh.get("contentMd5"),
file_size=local_state_fh.get("contentSize"),
Expand Down Expand Up @@ -3243,9 +3244,10 @@ def get_download_list(self, downloadLocation: str = None) -> str:
dl_list_path = self.get_download_list_manifest()
downloaded_files = []
new_manifest_path = f"manifest_{time.time_ns()}.csv"
with open(dl_list_path) as manifest_f, open(
new_manifest_path, "w"
) as write_obj:
with (
open(dl_list_path) as manifest_f,
open(new_manifest_path, "w") as write_obj,
):
reader = csv.DictReader(manifest_f)
columns = reader.fieldnames
columns.extend(["path", "error"])
Expand Down Expand Up @@ -4925,9 +4927,11 @@ def _convertProvenanceList(self, usedList: list, limitSearch: str = None) -> lis
if usedList is None:
return None
usedList = [
self.get(target, limitSearch=limitSearch)
if (os.path.isfile(target) if isinstance(target, str) else False)
else target
(
self.get(target, limitSearch=limitSearch)
if (os.path.isfile(target) if isinstance(target, str) else False)
else target
)
for target in usedList
]
return usedList
Expand Down Expand Up @@ -5468,7 +5472,7 @@ def _createExternalFileHandle(
"contentSize": fileSize,
}
if mimetype is None:
(mimetype, enc) = mimetypes.guess_type(externalURL, strict=False)
mimetype, enc = mimetypes.guess_type(externalURL, strict=False)
if mimetype is not None:
fileHandle["contentType"] = mimetype
return self.restPOST(
Expand Down Expand Up @@ -5893,16 +5897,16 @@ async def create_s3_storage_location_async(
}

if bucket_name:
storage_location_kwargs[
"concreteType"
] = concrete_types.EXTERNAL_S3_STORAGE_LOCATION_SETTING
storage_location_kwargs["concreteType"] = (
concrete_types.EXTERNAL_S3_STORAGE_LOCATION_SETTING
)
storage_location_kwargs["bucket"] = bucket_name
if base_key:
storage_location_kwargs["baseKey"] = base_key
else:
storage_location_kwargs[
"concreteType"
] = concrete_types.SYNAPSE_S3_STORAGE_LOCATION_SETTING
storage_location_kwargs["concreteType"] = (
concrete_types.SYNAPSE_S3_STORAGE_LOCATION_SETTING
)

storage_location_setting = self.restPOST(
"/storageLocation", json.dumps(storage_location_kwargs)
Expand Down
14 changes: 7 additions & 7 deletions synapseclient/core/download/download_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ async def download_by_file_handle(

while retries > 0:
try:
file_handle_result: Dict[
str, str
] = await get_file_handle_for_download_async(
file_handle_id=file_handle_id,
synapse_id=synapse_id,
entity_type=entity_type,
synapse_client=syn,
file_handle_result: Dict[str, str] = (
await get_file_handle_for_download_async(
file_handle_id=file_handle_id,
synapse_id=synapse_id,
entity_type=entity_type,
synapse_client=syn,
)
)
file_handle = file_handle_result["fileHandle"]
concrete_type = file_handle["concreteType"]
Expand Down
1 change: 1 addition & 0 deletions synapseclient/core/dozer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

sleep while checking registered _listeners
"""

import time

from opentelemetry import trace
Expand Down
1 change: 1 addition & 0 deletions synapseclient/core/models/custom_json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
When imported, monkey-patches the 'json' module's encoder with a custom json encoding function.
"""

import datetime
import json

Expand Down
1 change: 1 addition & 0 deletions synapseclient/core/otel_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""OpenTelemetry configuration for Synapse Python Client."""

import os
import sys
from typing import Any, Dict, List, Optional
Expand Down
1 change: 1 addition & 0 deletions synapseclient/core/transfer_bar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Logic used to handle progress bars for file uploads and downloads."""

try:
import threading as _threading
except ImportError:
Expand Down
6 changes: 3 additions & 3 deletions synapseclient/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def id_of(obj: typing.Union[str, collections.abc.Mapping, numbers.Number]) -> st


def validate_submission_id(
submission_id: typing.Union[str, int, collections.abc.Mapping]
submission_id: typing.Union[str, int, collections.abc.Mapping],
) -> str:
"""
Ensures that a given submission ID is either an integer or a string that
Expand Down Expand Up @@ -462,7 +462,7 @@ def is_synapse_id_str(obj: str) -> typing.Union[str, None]:


def get_synid_and_version(
obj: typing.Union[str, collections.abc.Mapping]
obj: typing.Union[str, collections.abc.Mapping],
) -> typing.Tuple[str, typing.Union[int, None]]:
"""Extract the Synapse ID and version number from input entity

Expand Down Expand Up @@ -698,7 +698,7 @@ def to_unix_epoch_time(dt: typing.Union[datetime.date, datetime.datetime, str])


def to_unix_epoch_time_secs(
dt: typing.Union[datetime.date, datetime.datetime]
dt: typing.Union[datetime.date, datetime.datetime],
) -> float:
"""
Convert either [datetime.date or datetime.datetime objects](http://docs.python.org/2/library/datetime.html) to UNIX time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This module provides library functions for creating record-based metadata curation tasks
in Synapse, including RecordSet creation, CurationTask setup, and Grid view initialization.
"""

import tempfile
from typing import Any, Dict, List, Optional, Tuple, Union

Expand Down
15 changes: 8 additions & 7 deletions synapseclient/extensions/curator/schema_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,18 @@ def find_and_convert_ints(
if (
dataframe.size < large_manifest_cutoff_size
): # If small manifest, iterate as normal for improved performance
ints = dataframe.map( # type:ignore
ints = dataframe.map( # type: ignore
lambda cell: convert_ints(cell), na_action="ignore"
).fillna(False)

else: # parallelize iterations for large manifests
pandarallel.initialize(verbose=1)
ints = dataframe.parallel_applymap( # type:ignore
ints = dataframe.parallel_applymap( # type: ignore
lambda cell: convert_ints(cell), na_action="ignore"
).fillna(False)

# Identify cells converted to integers
is_int = ints.map(is_integer) # type:ignore
is_int = ints.map(is_integer) # type: ignore

assert isinstance(ints, DataFrame)
assert isinstance(is_int, DataFrame)
Expand Down Expand Up @@ -2049,6 +2049,7 @@ class PropertyTemplate:
@dataclass
class ClassTemplate:
"Class Template"

magic_id: str = field(default="", metadata=config(field_name="@id"))
magic_type: str = field(default="rdfs:Class", metadata=config(field_name="@type"))
magic_comment: str = field(default="", metadata=config(field_name="rdfs:comment"))
Expand Down Expand Up @@ -3876,7 +3877,7 @@ def match_node_names_with_reserved_names(


def create_reserve_name_error_messages(
reserved_names_found: list[Tuple[str, str]]
reserved_names_found: list[Tuple[str, str]],
) -> list[str]:
"""Creates the error messages when a reserved name is used

Expand Down Expand Up @@ -3943,7 +3944,7 @@ def get_missing_fields_from(


def create_missing_fields_error_messages(
missing_fields: list[Tuple[str, str]]
missing_fields: list[Tuple[str, str]],
) -> list[str]:
"""Creates the error message for when a node is missing a required field

Expand Down Expand Up @@ -4119,7 +4120,7 @@ def export_schema(schema: dict, file_path: str, logger: Logger) -> None:


def parsed_model_as_dataframe(
parsed_model: dict[str, dict[str, Any]]
parsed_model: dict[str, dict[str, Any]],
) -> DATA_FRAME_TYPE:
"""Convert parsed model dictionary to an unpacked pandas DataFrame.
Args:
Expand Down Expand Up @@ -5168,7 +5169,7 @@ def add_conditional_dependency(

@staticmethod
def _convert_conditional_properties_to_all_of(
conditional_dependencies: dict[tuple[str, str], list[str]]
conditional_dependencies: dict[tuple[str, str], list[str]],
) -> list[AllOf]:
"""
Converts the conditional dependencies dict to a list of JSON Schema allOf conditions
Expand Down
6 changes: 3 additions & 3 deletions synapseclient/models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ class AgentSession(AgentSessionSynchronousProtocol):
"""The unique ID of the agent session.
Can only be used by the user that created it."""

access_level: Optional[
AgentSessionAccessLevel
] = AgentSessionAccessLevel.PUBLICLY_ACCESSIBLE
access_level: Optional[AgentSessionAccessLevel] = (
AgentSessionAccessLevel.PUBLICLY_ACCESSIBLE
)
"""The access level of the agent session.
One of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA, or
WRITE_YOUR_PRIVATE_DATA. Defaults to PUBLICLY_ACCESSIBLE.
Expand Down
4 changes: 1 addition & 3 deletions synapseclient/models/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ async def store_async(
return self

@classmethod
def from_dict(
cls, synapse_annotations: dict
) -> Union[
def from_dict(cls, synapse_annotations: dict) -> Union[
Dict[
str,
Union[
Expand Down
2 changes: 1 addition & 1 deletion synapseclient/models/curation.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def to_synapse_request(self) -> Dict[str, Any]:


def _create_task_properties_from_dict(
properties_dict: Dict[str, Any]
properties_dict: Dict[str, Any],
) -> Union[FileBasedMetadataTaskProperties, RecordBasedMetadataTaskProperties]:
"""
Factory method to create the appropriate FileBasedMetadataTaskProperties/RecordBasedMetadataTaskProperties
Expand Down
Loading
Loading