Skip to content

Commit 3006d1a

Browse files
committed
Merge branch 'develop' into develop-compliant-annotations-FDS-481
2 parents 11cbbe8 + 9959ea1 commit 3006d1a

File tree

5 files changed

+46
-43
lines changed

5 files changed

+46
-43
lines changed

poetry.lock

Lines changed: 29 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Flask-Cors = "^3.0.10"
7070
pdoc = "^12.2.0"
7171
dateparser = "^1.1.4"
7272
pandarallel = "^1.6.4"
73-
schematic-db = {version = "^0.0.20", extras = ["synapse"]}
73+
schematic-db = {version = "^0.0.29", extras = ["synapse"]}
7474
pyopenssl = "^23.0.0"
7575
typing-extensions = "<4.6.0"
7676

schematic/manifest/generator.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pathlib import Path
1010
import pygsheets as ps
1111
from tempfile import NamedTemporaryFile
12-
from typing import Dict, List, Tuple, Union
12+
from typing import Dict, List, Tuple, Union, Optional
1313

1414
from schematic.schemas.generator import SchemaGenerator
1515
from schematic.utils.google_api_utils import (
@@ -1236,18 +1236,19 @@ def _gather_all_fields(self, fields, json_schema):
12361236
)
12371237
return required_metadata_fields
12381238

1239-
def get_empty_manifest(self, json_schema_filepath=None, strict=None):
1239+
def get_empty_manifest(self, strict: Optional[bool], json_schema_filepath: str=None):
12401240
"""Create an empty manifest using specifications from the
12411241
json schema.
12421242
Args:
1243+
strict (bool): strictness with which to apply validation rules to google sheets. If true, blocks incorrect entries; if false, raises a warning
12431244
json_schema_filepath (str): path to json schema file
12441245
Returns:
12451246
manifest_url (str): url of the google sheet manifest.
12461247
TODO:
12471248
Refactor to not be dependent on GS.
12481249
"""
12491250
spreadsheet_id = self._create_empty_manifest_spreadsheet(self.title)
1250-
json_schema = self._get_json_schema(json_schema_filepath)
1251+
json_schema = self._get_json_schema(json_schema_filepath=json_schema_filepath)
12511252

12521253
required_metadata_fields = self._gather_all_fields(
12531254
json_schema["properties"].keys(), json_schema
@@ -1378,7 +1379,7 @@ def get_manifest_with_annotations(
13781379
self.additional_metadata = annotations_dict
13791380

13801381
# Generate empty manifest using `additional_metadata`
1381-
manifest_url = self.get_empty_manifest(strict)
1382+
manifest_url = self.get_empty_manifest(strict=strict)
13821383
manifest_df = self.get_dataframe_by_url(manifest_url)
13831384

13841385
# Annotations clashing with manifest attributes are skipped
@@ -1514,7 +1515,7 @@ def get_manifest(
15141515
manifest_record = store.updateDatasetManifestFiles(self.sg, datasetId = dataset_id, store = False)
15151516

15161517
# get URL of an empty manifest file created based on schema component
1517-
empty_manifest_url = self.get_empty_manifest(strict)
1518+
empty_manifest_url = self.get_empty_manifest(strict=strict)
15181519

15191520
# Populate empty template with existing manifest
15201521
if manifest_record:
@@ -1545,7 +1546,7 @@ def get_manifest(
15451546

15461547
# if there are no files with annotations just generate an empty manifest
15471548
if annotations.empty:
1548-
manifest_url = self.get_empty_manifest(strict)
1549+
manifest_url = self.get_empty_manifest(strict=strict)
15491550
manifest_df = self.get_dataframe_by_url(manifest_url)
15501551
else:
15511552
# Subset columns if no interested in user-defined annotations and there are files present

schematic/store/synapse.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
import uuid
4242

43-
from schematic_db.synapse.synapse import SynapseConfig
4443
from schematic_db.rdb.synapse_database import SynapseDatabase
4544

4645

@@ -2098,29 +2097,25 @@ def replaceTable(self, specifySchema: bool = True, columnTypeDict: dict = None,)
20982097
return self.existingTableId
20992098

21002099

2101-
def _get_schematic_db_creds(self,):
2102-
username = None
2100+
def _get_auth_token(self,):
21032101
authtoken = None
21042102

2105-
21062103
# Get access token from environment variable if available
21072104
# Primarily useful for testing environments, with other possible usefulness for containers
21082105
env_access_token = os.getenv("SYNAPSE_ACCESS_TOKEN")
21092106
if env_access_token:
21102107
authtoken = env_access_token
2111-
return username, authtoken
2108+
return authtoken
21122109

21132110
# Get token from authorization header
21142111
# Primarily useful for API endpoint functionality
21152112
if 'Authorization' in self.synStore.syn.default_headers:
21162113
authtoken = self.synStore.syn.default_headers['Authorization'].split('Bearer ')[-1]
2117-
return username, authtoken
2114+
return authtoken
21182115

21192116
# retrive credentials from synapse object
21202117
# Primarily useful for local users, could only be stored here when a .synapseConfig file is used, but including to be safe
21212118
synapse_object_creds = self.synStore.syn.credentials
2122-
if hasattr(synapse_object_creds, 'username'):
2123-
username = synapse_object_creds.username
21242119
if hasattr(synapse_object_creds, '_token'):
21252120
authtoken = synapse_object_creds.secret
21262121

@@ -2130,24 +2125,16 @@ def _get_schematic_db_creds(self,):
21302125
config = self.synStore.syn.getConfigFile(CONFIG.synapse_configuration_path)
21312126

21322127
# check which credentials are provided in file
2133-
if config.has_option('authentication', 'username'):
2134-
username = config.get('authentication', 'username')
21352128
if config.has_option('authentication', 'authtoken'):
21362129
authtoken = config.get('authentication', 'authtoken')
21372130

21382131
# raise error if required credentials are not found
2139-
# providing an authtoken without a username did not prohibit upsert functionality,
2140-
# but including username gathering for completeness for schematic_db
2141-
if not username and not authtoken:
2142-
raise NameError(
2143-
"Username and authtoken credentials could not be found in the environment, synapse object, or the .synapseConfig file"
2144-
)
21452132
if not authtoken:
21462133
raise NameError(
21472134
"authtoken credentials could not be found in the environment, synapse object, or the .synapseConfig file"
21482135
)
21492136

2150-
return username, authtoken
2137+
return authtoken
21512138

21522139
def upsertTable(self, sg: SchemaGenerator,):
21532140
"""
@@ -2164,10 +2151,9 @@ def upsertTable(self, sg: SchemaGenerator,):
21642151
existingTableId: synID of the already existing table that had its metadata replaced
21652152
"""
21662153

2167-
username, authtoken = self._get_schematic_db_creds()
2154+
authtoken = self._get_auth_token()
21682155

2169-
synConfig = SynapseConfig(username, authtoken, self.synStore.getDatasetProject(self.datasetId))
2170-
synapseDB = SynapseDatabase(synConfig)
2156+
synapseDB = SynapseDatabase(auth_token=authtoken, project_id=self.synStore.getDatasetProject(self.datasetId))
21712157

21722158
try:
21732159
# Try performing upsert

tests/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,11 @@ def ifPandasDataframe(self, response_dt):
405405
def test_generate_existing_manifest(self, client, data_model_jsonld, data_type, output_format, caplog):
406406
# set dataset
407407
if data_type == "Patient":
408-
dataset_id = ["syn42171373"] #Mock Patient Manifest folder on synapse
408+
dataset_id = ["syn51730545"] #Mock Patient Manifest folder on synapse
409409
elif data_type == "Biospecimen":
410-
dataset_id = ["syn42171508"] #Mock biospecimen manifest folder
410+
dataset_id = ["syn51730547"] #Mock biospecimen manifest folder
411411
elif data_type == ["Biospecimen", "Patient"]:
412-
dataset_id = ["syn42171508", "syn42171373"]
412+
dataset_id = ["syn51730547", "syn51730545"]
413413
else:
414414
dataset_id = None #if "all manifests", dataset id is None
415415

0 commit comments

Comments
 (0)