diff --git a/CHANGELOG.md b/CHANGELOG.md index 958933ba413af1b526e49b0fcacdaf2ffd7cf344..de363eb791697fcc53171b6e4d0694da1036e34a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.15.1] - 2024-08-21 ## + +### Deprecated ### + +* `connection.get_username`. Use `la.Info().user_info.name` instead. + +### Fixed ### + +* [#128](https://gitlab.com/linkahead/linkahead-pylib/-/issues/128) + Assign `datetime.date` or `datetime.datetime` values to `DATETIME` + properties. + +### Documentation ### + +* Added docstrings for `linkahead.models.Info` and `linkahead.models.UserInfo`. + ## [0.15.0] - 2024-07-09 ## ### Added ### diff --git a/CITATION.cff b/CITATION.cff index 148cccb1804f7ae254224074dfef408e014f5438..3f51bdf839a5e0451f3d3aaf7f128f61b29927fc 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -20,6 +20,6 @@ authors: given-names: Stefan orcid: https://orcid.org/0000-0001-7214-8125 title: CaosDB - Pylib -version: 0.15.0 +version: 0.15.1 doi: 10.3390/data4020083 -date-released: 2024-07-09 +date-released: 2024-08-21 diff --git a/setup.py b/setup.py index 1a8a754219ddf84c0b9e088a13fd0283fa63a00f..6ad2d0b9ef1e4c07d6519562a0c75c72c51b5b75 100755 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ from setuptools import find_packages, setup ISRELEASED = True MAJOR = 0 MINOR = 15 -MICRO = 0 +MICRO = 1 # Do not tag as pre-release until this commit # https://github.com/pypa/packaging/pull/515 # has made it into a release. Probably we should wait for pypa/packaging>=21.4 diff --git a/src/doc/conf.py b/src/doc/conf.py index 4a528d9e287daeeacd50e94cfba4e479b0430212..7b127420c281e37e82ee0e64768ae831e30e2798 100644 --- a/src/doc/conf.py +++ b/src/doc/conf.py @@ -29,10 +29,10 @@ copyright = '2023, IndiScale GmbH' author = 'Daniel Hornung' # The short X.Y version -version = '0.15.0' +version = '0.15.1' # The full version, including alpha/beta/rc tags # release = '0.5.2-rc2' -release = '0.15.0' +release = '0.15.1' # -- General configuration --------------------------------------------------- diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index 96851f34bd7558e03fb60d92ca001d8cd7c43171..a8144286fdacefacadf2b823160e0eb9bfe00c77 100644 --- a/src/linkahead/common/models.py +++ b/src/linkahead/common/models.py @@ -39,6 +39,7 @@ import re import sys from builtins import str from copy import deepcopy +from datetime import date, datetime from functools import cmp_to_key from hashlib import sha512 from os import listdir @@ -50,7 +51,6 @@ from typing import TYPE_CHECKING from typing import Any, Final, Literal, Optional, TextIO, Union if TYPE_CHECKING: - from datetime import datetime from .datatype import DATATYPE from tempfile import _TemporaryFileWrapper from io import BufferedWriter @@ -1687,6 +1687,9 @@ def _parse_value(datatype, value): if isinstance(value, str): return value + if datatype == DATETIME and (isinstance(value, date) or isinstance(value, datetime)): + return value + # deal with collections if isinstance(datatype, str): matcher = re.compile(r"^(?P<col>[^<]+)<(?P<dt>[^>]+)>$") diff --git a/src/linkahead/connection/connection.py b/src/linkahead/connection/connection.py index 294d9457d064f03bbe06a3347b2d2064dcf12b8c..c95134fed3fd6b031b01b518c6362bf3b371c960 100644 --- a/src/linkahead/connection/connection.py +++ b/src/linkahead/connection/connection.py @@ -757,6 +757,8 @@ class _Connection(object): # pylint: disable=useless-object-inheritance Shortcut for: get_connection()._authenticator._credentials_provider.username """ + warnings.warn("Deprecated. Please use ``la.Info().user_info.name`` instead.", + DeprecationWarning) if self._authenticator is None: raise ValueError( "No authenticator set. Please call configure_connection() first.") diff --git a/src/linkahead/utils/get_entity.py b/src/linkahead/utils/get_entity.py index f84dc107e275390e53c6127834f53e5e5c6521cd..0ffd89e4dc7f214bbc72d4508f6ca4481dad7d9c 100644 --- a/src/linkahead/utils/get_entity.py +++ b/src/linkahead/utils/get_entity.py @@ -30,7 +30,13 @@ from .escape import escape_squoted_text def get_entity_by_name(name: str, role: Optional[str] = None) -> Entity: """Return the result of a unique query that uses the name to find the correct entity. - Submits the query "FIND ENTITY WITH name='{name}'". +Submits the query "FIND {role} WITH name='{name}'". + +Parameters +---------- + +role: str, optional + The role for the query, defaults to ``ENTITY``. """ name = escape_squoted_text(name) if role is None: @@ -42,7 +48,13 @@ def get_entity_by_name(name: str, role: Optional[str] = None) -> Entity: def get_entity_by_id(eid: Union[str, int], role: Optional[str] = None) -> Entity: """Return the result of a unique query that uses the id to find the correct entity. - Submits the query "FIND ENTITY WITH id='{eid}'". +Submits the query "FIND {role} WITH id='{eid}'". + +Parameters +---------- + +role: str, optional + The role for the query, defaults to ``ENTITY``. """ if role is None: role = "ENTITY" @@ -53,7 +65,13 @@ def get_entity_by_id(eid: Union[str, int], role: Optional[str] = None) -> Entity def get_entity_by_path(path: str) -> Entity: """Return the result of a unique query that uses the path to find the correct file. - Submits the query "FIND FILE WHICH IS STORED AT '{path}'". +Submits the query "FIND {role} WHICH IS STORED AT '{path}'". + +Parameters +---------- + +role: str, optional + The role for the query, defaults to ``ENTITY``. """ # type hint can be ignored, it's a unique query return execute_query(f"FIND FILE WHICH IS STORED AT '{path}'", unique=True) # type: ignore diff --git a/tox.ini b/tox.ini index bbaaa1fc9eec2aba87c247d783818d215d8a7d5e..592c660c5bbbf5805a3ecbb3e60c41f597182a55 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ deps = . mypy jsonschema>=4.4.0 setuptools -commands=py.test --cov=caosdb -vv {posargs} +commands=py.test --cov=linkahead -vv {posargs} [flake8] max-line-length=100 diff --git a/unittests/test_issues.py b/unittests/test_issues.py index 7472f710cea32c1d76f11e52fe7c3c3617804c3c..e24afbe8b7be8d9a87d85819eccd3a4bf0d453e8 100644 --- a/unittests/test_issues.py +++ b/unittests/test_issues.py @@ -24,6 +24,7 @@ import os import lxml import linkahead as db +from datetime import date, datetime from pytest import raises @@ -64,3 +65,28 @@ def test_issue_156(): # </ParentList> assert value is project assert parents[0].name == "RTName" + + +def test_issue_128(): + """Test assigning datetime.date(time) values to DATETIME + properties: + https://gitlab.com/linkahead/linkahead-pylib/-/issues/128. + + """ + # Test assignement correct assignment for both datatype=DATETIME + # and datatype=LIST<DATETIME>, just to be sure. + prop = db.Property(name="TestDatetime", datatype=db.DATETIME) + prop_list = db.Property(name="TestListDatetime", datatype=db.LIST(db.DATETIME)) + + today = date.today() + now = datetime.now() + + prop.value = today + assert prop.value == today + prop.value = now + assert prop.value == now + + prop_list.value = [today, today] + assert prop_list.value == [today, today] + prop_list.value = [now, now] + assert prop_list.value == [now, now]