Skip to content

Commit

Permalink
Merge pull request #94 from pepkit/dev
Browse files Browse the repository at this point in the history
Release v0.5.3
  • Loading branch information
khoroshevskyi authored Jul 14, 2023
2 parents 81fbdb5 + 888f6d0 commit 833bba3
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 33 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.

## [0.5.3] -- 2023-07-13
- Fixed bugs in updating dates and descriptions

## [0.5.2] -- 2023-07-13
- Fixed error in updating date in overwriting function

Expand Down
2 changes: 1 addition & 1 deletion pepdbagent/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.2"
__version__ = "0.5.3"
1 change: 1 addition & 0 deletions pepdbagent/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
DEFAULT_TAG = "default"

DESCRIPTION_KEY = "description"
NAME_KEY = "name"

# from peppy.const import SAMPLE_RAW_DICT_KEY, SUBSAMPLE_RAW_LIST_KEY

Expand Down
13 changes: 4 additions & 9 deletions pepdbagent/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ def receive_after_create(target, connection, tables, **kw):
_LOGGER.info("A table was not created")


def deliver_description(context):
try:
return context.get_current_parameters()["config"]["description"]
except KeyError:
return ""
# def deliver_description(context):
# return context.get_current_parameters()["config"]["description"]


def deliver_update_date(context):
Expand All @@ -86,15 +83,13 @@ class Projects(Base):
name: Mapped[str] = mapped_column()
tag: Mapped[str] = mapped_column()
digest: Mapped[str] = mapped_column(String(32))
description: Mapped[Optional[str]] = mapped_column(
default=deliver_description, onupdate=deliver_description
)
description: Mapped[Optional[str]]
config: Mapped[dict] = mapped_column(JSON, server_default=FetchedValue())
private: Mapped[bool]
number_of_samples: Mapped[int]
submission_date: Mapped[datetime.datetime]
last_update_date: Mapped[Optional[datetime.datetime]] = mapped_column(
onupdate=deliver_update_date,
onupdate=deliver_update_date, default=deliver_update_date
)
pep_schema: Mapped[Optional[str]]
samples_mapping: Mapped[List["Samples"]] = relationship(
Expand Down
2 changes: 2 additions & 0 deletions pepdbagent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class UpdateItems(BaseModel):
config: Optional[dict]
samples: Optional[List[dict]]
subsamples: Optional[List[List[dict]]]
description: Optional[str]

class Config:
arbitrary_types_allowed = True
Expand All @@ -105,6 +106,7 @@ class UpdateModel(BaseModel):
digest: Optional[str]
number_of_samples: Optional[int]
pep_schema: Optional[str]
description: Optional[str] = ""
# last_update_date: Optional[datetime.datetime] = datetime.datetime.now(datetime.timezone.utc)

@validator("tag", "name")
Expand Down
70 changes: 47 additions & 23 deletions pepdbagent/modules/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,18 @@ def create(
proj_dict = project.to_dict(extended=True, orient="records")
if not description:
description = project.description
proj_dict[CONFIG_KEY]["description"] = description
proj_dict[CONFIG_KEY][DESCRIPTION_KEY] = description

namespace = namespace.lower()
if name:
name = name.lower()
proj_name = name
proj_dict[CONFIG_KEY]["name"] = proj_name
elif proj_dict[CONFIG_KEY]["name"]:
proj_name = proj_dict[CONFIG_KEY]["name"].lower()
proj_name = name.lower()
elif proj_dict[CONFIG_KEY][NAME_KEY]:
proj_name = proj_dict[CONFIG_KEY][NAME_KEY].lower()
else:
raise ValueError(f"Name of the project wasn't provided. Project will not be uploaded.")

proj_dict[CONFIG_KEY][NAME_KEY] = proj_name

proj_digest = create_digest(proj_dict)
number_of_samples = len(project.samples)

Expand All @@ -250,6 +250,7 @@ def create(
number_of_samples=number_of_samples,
private=is_private,
pep_schema=pep_schema,
description=description,
)
return None
else:
Expand All @@ -266,6 +267,7 @@ def create(
submission_date=datetime.datetime.now(datetime.timezone.utc),
last_update_date=datetime.datetime.now(datetime.timezone.utc),
pep_schema=pep_schema,
description=description,
)

self._add_samples_to_project(new_prj, proj_dict[SAMPLE_RAW_DICT_KEY])
Expand All @@ -291,6 +293,7 @@ def create(
number_of_samples=number_of_samples,
private=is_private,
pep_schema=pep_schema,
description=description,
)
return None

Expand All @@ -311,6 +314,7 @@ def _overwrite(
number_of_samples: int,
private: bool = False,
pep_schema: str = None,
description: str = "",
) -> None:
"""
Update existing project by providing all necessary information.
Expand All @@ -323,6 +327,7 @@ def _overwrite(
:param number_of_samples: number of samples in project
:param private: boolean value if the project should be visible just for user that creates it.
:param pep_schema: assign PEP to a specific schema. [DefaultL: None]
:param description: project description
:return: None
"""
proj_name = proj_name.lower()
Expand All @@ -332,7 +337,7 @@ def _overwrite(
statement = self._create_select_statement(proj_name, namespace, tag)

with Session(self._sa_engine) as session:
found_prj = session.scalars(statement).one()
found_prj = session.scalar(statement)

if found_prj:
_LOGGER.debug(
Expand All @@ -343,8 +348,8 @@ def _overwrite(
found_prj.number_of_samples = number_of_samples
found_prj.private = private
found_prj.pep_schema = pep_schema
found_prj.last_update_date = datetime.datetime.now(datetime.timezone.utc)
found_prj.description = project_dict[CONFIG_KEY].get("description")
found_prj.config = project_dict[CONFIG_KEY]
found_prj.description = description

# Deleting old samples and subsamples
if found_prj.samples_mapping:
Expand Down Expand Up @@ -426,12 +431,12 @@ def update(
setattr(found_prj, k, v)

# standardizing project name
if k == "name":
if k == NAME_KEY:
if "config" in update_values:
update_values["config"]["name"] = v
update_values["config"][NAME_KEY] = v
else:
found_prj.config["name"] = v
found_prj.name = found_prj.config["name"]
found_prj.config[NAME_KEY] = v
found_prj.name = found_prj.config[NAME_KEY]

if "samples" in update_dict:
if found_prj.samples_mapping:
Expand All @@ -451,6 +456,8 @@ def update(
if update_dict["subsamples"]:
self._add_subsamples_to_project(found_prj, update_dict["subsamples"])

found_prj.last_update_date = datetime.datetime.now(datetime.timezone.utc)

session.commit()

return None
Expand All @@ -470,14 +477,37 @@ def __create_update_dict(update_values: UpdateItems) -> dict:
"""
update_final = UpdateModel()

if update_values.name is not None:
if update_values.config is not None:
update_values.config[NAME_KEY] = update_values.name
update_final = UpdateModel(
name=update_values.name,
**update_final.dict(exclude_unset=True),
)

if update_values.description is not None:
if update_values.config is not None:
update_values.config[DESCRIPTION_KEY] = update_values.description
update_final = UpdateModel(
description=update_values.description,
**update_final.dict(exclude_unset=True),
)
if update_values.config is not None:
if update_values.description is not None:
update_values.config["description"] = update_values.description
if update_values.name is not None:
update_values.config["name"] = update_values.name
update_final = UpdateModel(
config=update_values.config, **update_final.dict(exclude_unset=True)
)
name = update_values.config.get(NAME_KEY)
description = update_values.config.get(DESCRIPTION_KEY)
if name:
update_final = UpdateModel(
name=name,
**update_final.dict(exclude_unset=True, exclude={NAME_KEY}),
)
if description:
update_final = UpdateModel(
description=description,
**update_final.dict(exclude_unset=True, exclude={DESCRIPTION_KEY}),
)

if update_values.tag is not None:
update_final = UpdateModel(
Expand All @@ -490,12 +520,6 @@ def __create_update_dict(update_values: UpdateItems) -> dict:
**update_final.dict(exclude_unset=True),
)

if update_values.name is not None:
update_final = UpdateModel(
name=update_values.name,
**update_final.dict(exclude_unset=True),
)

if update_values.pep_schema is not None:
update_final = UpdateModel(
pep_schema=update_values.pep_schema,
Expand Down

0 comments on commit 833bba3

Please sign in to comment.