Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Jun 24, 2024
1 parent 45e52f1 commit 70f94fb
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions pepdbagent/modules/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ def fork(
fork_tag: str = None,
description: str = None,
private: bool = False,
):
) -> None:
"""
Fork project from one namespace to another
Expand All @@ -834,6 +834,7 @@ def fork(
:param private: boolean value if the project should be visible just for user that creates it.
:return: None
"""

self.create(
project=self.get(
namespace=original_namespace,
Expand All @@ -848,27 +849,31 @@ def fork(
is_private=private,
)
original_statement = select(Projects).where(
Projects.namespace == original_namespace,
Projects.name == original_name,
Projects.tag == original_tag,
and_(
Projects.namespace == original_namespace,
Projects.name == original_name,
Projects.tag == original_tag,
)
)
fork_statement = select(Projects).where(
Projects.namespace == fork_namespace,
Projects.name == fork_name,
Projects.tag == fork_tag,
and_(
Projects.namespace == fork_namespace,
Projects.name == fork_name,
Projects.tag == fork_tag,
)
)

with Session(self._sa_engine) as session:
original_prj = session.scalar(original_statement)
fork_prj = session.scalar(fork_statement)

fork_prj.forked_from_id = original_prj.id
fork_prj.pop = original_prj.pop
fork_prj.submission_date = original_prj.submission_date
fork_prj.pep_schema = original_prj.pep_schema
fork_prj.description = description or original_prj.description

session.commit()
return None

def get_config(self, namespace: str, name: str, tag: str) -> Union[dict, None]:
"""
Expand Down Expand Up @@ -921,23 +926,26 @@ def get_subsamples(self, namespace: str, name: str, tag: str) -> Union[list, Non
f"Did you supply a valid namespace and project?"
)

def get_samples(self, namespace: str, name: str, tag: str, raw: bool = True) -> list:
def get_samples(
self, namespace: str, name: str, tag: str, raw: bool = True, with_ids: bool = False
) -> list:
"""
Get project samples by providing namespace, name, and tag
:param namespace: project namespace
:param name: project name
:param tag: project tag
:param raw: if True, retrieve unprocessed (raw) PEP dict. [Default: True]
:param with_ids: if True, retrieve samples with ids. [Default: False]
:return: list with project samples
"""
if raw:
return self.get(namespace=namespace, name=name, tag=tag, raw=True).get(
SAMPLE_RAW_DICT_KEY
)
return self.get(
namespace=namespace, name=name, tag=tag, raw=True, with_id=with_ids
).get(SAMPLE_RAW_DICT_KEY)
return (
self.get(namespace=namespace, name=name, tag=tag, raw=False)
self.get(namespace=namespace, name=name, tag=tag, raw=False, with_id=with_ids)
.sample_table.replace({np.nan: None})
.to_dict(orient="records")
)

0 comments on commit 70f94fb

Please sign in to comment.