Skip to content

Commit

Permalink
Merge pull request #89 from pepkit/new_desc_column
Browse files Browse the repository at this point in the history
v0.4.3
  • Loading branch information
khoroshevskyi authored Jun 30, 2023
2 parents 9e623b5 + 4ff495a commit 53d7c03
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 40 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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.4.3] -- 2023-06-30
- Changed the orientation of the raw project dictionary to "records" and updated peppy version to 0.35.6.
- Added description column
- Added sql description search
- Deleted unused files

## [0.4.2] -- 2023-06-27
- Added validation of question mark in name and tag
- Fixed description and name in config file
Expand Down
2 changes: 1 addition & 1 deletion manual_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def upload_sample_pep_to_db(connection: pepdbagent.PEPDatabaseAgent):
"/home/bnt4me/virginia/repos/pepdbagent/tests/data/namespace1/basic/project_config.yaml"
)
fgf = prj.to_dict()
rr = prj.to_dict(extended=True)
rr = prj.to_dict(extended=True, orient="records")
con.project.create(project=prj, namespace="dog_namespace", name="testttt", tag="test1", overwrite=True)


Expand Down
23 changes: 0 additions & 23 deletions pep_db/pep_db.sql

This file was deleted.

2 changes: 1 addition & 1 deletion pepdbagent/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.2"
__version__ = "0.4.3"
2 changes: 1 addition & 1 deletion pepdbagent/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

DESCRIPTION_KEY = "description"

from peppy.const import SAMPLE_RAW_DICT_KEY, SUBSAMPLE_RAW_DICT_KEY
from peppy.const import SAMPLE_RAW_DICT_KEY, SUBSAMPLE_RAW_LIST_KEY

DEFAULT_OFFSET = 0
DEFAULT_LIMIT = 100
Expand Down
10 changes: 10 additions & 0 deletions pepdbagent/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ 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()["project_value"]["_config"]["description"]
except KeyError:
return ""


class Projects(Base):
__tablename__ = "projects"

Expand All @@ -67,6 +74,9 @@ class Projects(Base):
name: Mapped[str] = mapped_column(primary_key=True)
tag: Mapped[str] = mapped_column(primary_key=True)
digest: Mapped[str] = mapped_column(String(32))
description: Mapped[Optional[str]] = mapped_column(
default=deliver_description, onupdate=deliver_description
)
project_value: Mapped[dict] = mapped_column(JSON, server_default=FetchedValue())
private: Mapped[bool]
number_of_samples: Mapped[int]
Expand Down
1 change: 1 addition & 0 deletions pepdbagent/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class UpdateModel(BaseModel):
last_update_date: Optional[datetime.datetime]
number_of_samples: Optional[int]
pep_schema: Optional[str]
description: Optional[str]

@validator("tag", "name")
def value_must_not_be_empty(cls, v):
Expand Down
5 changes: 3 additions & 2 deletions pepdbagent/modules/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _get_single_annotation(
Projects.name,
Projects.tag,
Projects.private,
Projects.project_value["description"].astext.label("description"),
Projects.description,
Projects.number_of_samples,
Projects.submission_date,
Projects.last_update_date,
Expand Down Expand Up @@ -256,7 +256,7 @@ def _get_projects(
Projects.name,
Projects.tag,
Projects.private,
Projects.project_value["description"].astext.label("description"),
Projects.description,
Projects.number_of_samples,
Projects.submission_date,
Projects.last_update_date,
Expand Down Expand Up @@ -349,6 +349,7 @@ def _add_condition(
search_query = or_(
Projects.name.ilike(sql_search_str),
Projects.tag.ilike(sql_search_str),
Projects.description.ilike(sql_search_str),
)
statement = statement.where(search_query)
if namespace:
Expand Down
22 changes: 12 additions & 10 deletions pepdbagent/modules/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def create(
namespace: str,
name: str = None,
tag: str = DEFAULT_TAG,
description: str = None,
is_private: bool = False,
pep_schema: str = None,
overwrite: bool = False,
Expand All @@ -187,19 +188,21 @@ def create(
:param overwrite: if project exists overwrite the project, otherwise upload it.
[Default: False - project won't be overwritten if it exists in db]
:param update_only: if project exists overwrite it, otherwise do nothing. [Default: False]
:param description: description of the project
:return: None
"""
proj_dict = project.to_dict(extended=True)
proj_dict["_config"]["description"] = project.description
proj_dict = project.to_dict(extended=True, orient="records")
if not description:
description = project.description
proj_dict["_config"]["description"] = description

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

Expand Down Expand Up @@ -336,7 +339,6 @@ def update(
tag: Optional[str]
name: Optional[str]
}
*project_value should contain name and description
:param namespace: project namespace
:param name: project name
:param tag: project tag
Expand Down Expand Up @@ -383,13 +385,13 @@ def __create_update_dict(update_values: UpdateItems) -> dict:
update_final = UpdateModel()

if update_values.project_value is not None:
proj_dict = update_values.project_value.to_dict(extended=True)
proj_dict["_config"]["description"] = proj_dict["description"]
proj_dict["_config"]["name"] = proj_dict["name"]
proj_dict = update_values.project_value.to_dict(extended=True, orient="records")
update_final = UpdateModel(
project_value=proj_dict,
name=update_values.project_value.name,
digest=create_digest(update_values.project_value.to_dict(extended=True)),
digest=create_digest(
update_values.project_value.to_dict(extended=True, orient="records")
),
last_update_date=datetime.datetime.now(datetime.timezone.utc),
number_of_samples=len(update_values.project_value.samples),
)
Expand Down
4 changes: 2 additions & 2 deletions requirements/requirements-all.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
sqlalchemy>=2.0.0
logmuse
peppy>=0.35.5
peppy>=0.35.6
ubiquerg>=0.6.2
coloredlogs>=15.0.1
pytest-mock
pydantic
pydantic<2.0
psycopg2

0 comments on commit 53d7c03

Please sign in to comment.