|
16 | 16 | from rich.console import Console
|
17 | 17 | from rich.progress import track
|
18 | 18 | from ubiquerg import is_url
|
| 19 | +from copy import deepcopy |
19 | 20 |
|
20 | 21 | from .const import (
|
21 | 22 | ACTIVE_AMENDMENTS_KEY,
|
|
27 | 28 | CONFIG_FILE_KEY,
|
28 | 29 | CONFIG_KEY,
|
29 | 30 | CONFIG_VERSION_KEY,
|
30 |
| - CONSTANT_KEY, |
| 31 | + APPEND_KEY, |
31 | 32 | DERIVED_ATTRS_KEY,
|
32 | 33 | DERIVED_KEY,
|
33 | 34 | DERIVED_SOURCES_KEY,
|
|
59 | 60 | SUBSAMPLE_RAW_LIST_KEY,
|
60 | 61 | SUBSAMPLE_TABLE_INDEX_KEY,
|
61 | 62 | SUBSAMPLE_TABLES_FILE_KEY,
|
| 63 | + ORIGINAL_CONFIG_KEY, |
62 | 64 | )
|
63 | 65 | from .exceptions import (
|
64 | 66 | InvalidSampleTableFileException,
|
@@ -137,7 +139,6 @@ def __init__(
|
137 | 139 |
|
138 | 140 | self._samples = []
|
139 | 141 | self[SAMPLE_EDIT_FLAG_KEY] = False
|
140 |
| - self.is_private = False |
141 | 142 | self.progressbar = False
|
142 | 143 |
|
143 | 144 | # table indexes can be specified in config or passed to the object constructor
|
@@ -200,6 +201,19 @@ def from_pandas(
|
200 | 201 | )
|
201 | 202 | return tmp_obj
|
202 | 203 |
|
| 204 | + @classmethod |
| 205 | + def from_pephub(cls, registry_path: str) -> "Project": |
| 206 | + """ |
| 207 | + Init project from pephubclient. |
| 208 | +
|
| 209 | + :param registry_path: PEPhub registry path |
| 210 | + :return: peppy Project |
| 211 | + """ |
| 212 | + from pephubclient import PEPHubClient |
| 213 | + |
| 214 | + phc = PEPHubClient() |
| 215 | + return phc.load_project(project_registry_path=registry_path) |
| 216 | + |
203 | 217 | @classmethod
|
204 | 218 | def from_dict(cls, pep_dictionary: dict):
|
205 | 219 | """
|
@@ -317,13 +331,13 @@ def to_dict(
|
317 | 331 | else:
|
318 | 332 | sub_df = None
|
319 | 333 | try:
|
320 |
| - self[CONFIG_KEY][NAME_KEY] = self.name |
| 334 | + self[ORIGINAL_CONFIG_KEY][NAME_KEY] = self.name |
321 | 335 | except NotImplementedError:
|
322 |
| - self[CONFIG_KEY][NAME_KEY] = "unnamed" |
323 |
| - self[CONFIG_KEY][DESC_KEY] = self.description |
| 336 | + self[ORIGINAL_CONFIG_KEY][NAME_KEY] = "unnamed" |
| 337 | + self[ORIGINAL_CONFIG_KEY][DESC_KEY] = self.description |
324 | 338 | p_dict = {
|
325 | 339 | SAMPLE_RAW_DICT_KEY: self[SAMPLE_DF_KEY].to_dict(orient=orient),
|
326 |
| - CONFIG_KEY: dict(self[CONFIG_KEY]), |
| 340 | + CONFIG_KEY: dict(self[ORIGINAL_CONFIG_KEY]), |
327 | 341 | SUBSAMPLE_RAW_LIST_KEY: sub_df,
|
328 | 342 | }
|
329 | 343 | else:
|
@@ -438,6 +452,7 @@ def parse_config_file(
|
438 | 452 | )
|
439 | 453 |
|
440 | 454 | self[CONFIG_KEY].update(**config)
|
| 455 | + self[ORIGINAL_CONFIG_KEY] = deepcopy(self[CONFIG_KEY]) |
441 | 456 | # Parse yaml into the project.config attributes
|
442 | 457 | _LOGGER.debug("Adding attributes: {}".format(", ".join(config)))
|
443 | 458 | # Overwrite any config entries with entries in the amendments
|
@@ -587,8 +602,8 @@ def attr_constants(self):
|
587 | 602 | Update each Sample with constants declared by a Project.
|
588 | 603 | If Project does not declare constants, no update occurs.
|
589 | 604 | """
|
590 |
| - if self._modifier_exists(CONSTANT_KEY): |
591 |
| - to_append = self[CONFIG_KEY][SAMPLE_MODS_KEY][CONSTANT_KEY] |
| 605 | + if self._modifier_exists(APPEND_KEY): |
| 606 | + to_append = self[CONFIG_KEY][SAMPLE_MODS_KEY][APPEND_KEY] |
592 | 607 | _LOGGER.debug("Applying constant attributes: {}".format(to_append))
|
593 | 608 |
|
594 | 609 | for s in track(
|
@@ -1309,14 +1324,17 @@ def _read_sample_data(self):
|
1309 | 1324 | _LOGGER.info("No config key in Project, or reading project from dict")
|
1310 | 1325 | return
|
1311 | 1326 | if CFG_SAMPLE_TABLE_KEY not in self[CONFIG_KEY]:
|
1312 |
| - _LOGGER.debug("no {} found".format(CFG_SAMPLE_TABLE_KEY)) |
| 1327 | + _LOGGER.debug(f"No {CFG_SAMPLE_TABLE_KEY} found in config file") |
1313 | 1328 | return
|
1314 | 1329 | st = self[CONFIG_KEY][CFG_SAMPLE_TABLE_KEY]
|
1315 | 1330 |
|
1316 | 1331 | if self[SUBSAMPLE_TABLES_FILE_KEY] is not None:
|
1317 | 1332 | sst = self[SUBSAMPLE_TABLES_FILE_KEY]
|
1318 | 1333 | else:
|
1319 |
| - if CONFIG_KEY in self and CFG_SUBSAMPLE_TABLE_KEY in self[CONFIG_KEY]: |
| 1334 | + if ( |
| 1335 | + CONFIG_KEY in self |
| 1336 | + and self[CONFIG_KEY].get(CFG_SUBSAMPLE_TABLE_KEY) is not None |
| 1337 | + ): |
1320 | 1338 | sst = make_list(self[CONFIG_KEY][CFG_SUBSAMPLE_TABLE_KEY], str)
|
1321 | 1339 | else:
|
1322 | 1340 | sst = None
|
|
0 commit comments