Page MenuHomeSoftware Heritage

client: support optional date in Revision and Release
ClosedPublic

Authored by ardumont on Apr 3 2020, 4:50 PM.

Details

Summary

From the model specification, the date attribute in Revision and
Release objects is optional. This commit handles the date attribute
set to the None value.

It also tests the "typification" of a minimal Revision object to avoid
regressions on this usecase.

Diff Detail

Repository
rDWCLI Web client
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build has FAILED

Patch application report for D2958 (id=10533)

Could not rebase; Attempt merge onto 492be567e2...

Updating 492be56..cbdab1f
Fast-forward
 swh/web/client/__init__.py                  |   2 +-
 swh/web/client/client.py                    |  55 +++++++-
 swh/web/client/tests/api_data.py            | 210 ++++++++++++++++++++++++++++
 swh/web/client/tests/conftest.py            |  10 +-
 swh/web/client/tests/gen-api-data.sh        |   2 +
 swh/web/client/tests/test_web_api_client.py |  31 ++++
 6 files changed, 304 insertions(+), 6 deletions(-)
Changes applied before test
commit cbdab1f549e21975e1923a4e874c9635936b9442
Author: Antoine Eiche <lewo@abesis.fr>
Date:   Fri Apr 3 16:44:44 2020 +0200

    client: support optional date in Revision and Release
    
    From the model specification, the date attribute in Revision and
    Release objects is optional. This commit handles the date attribute
    set to the None value.
    
    It also tests the "typification" of a minimal Revision object to avoid
    regressions on this usecase.

commit 8d47566785824aa219ddb44e51e7b364b2fca54c
Author: Antoine Eiche <lewo@abesis.fr>
Date:   Wed Mar 25 17:52:19 2020 +0100

    client: add `visits` method to get the list of an origin visits
    
    A test is added to ensure the pagination and the data typing are
    working as expected.

Link to build: https://jenkins.softwareheritage.org/job/DWCLI/job/tests-on-diff/5/
See console output for more information: https://jenkins.softwareheritage.org/job/DWCLI/job/tests-on-diff/5/console

Build is green

Patch application report for D2958 (id=10534)

Could not rebase; Attempt merge onto 492be567e2...

Updating 492be56..64fa0f3
Fast-forward
 swh/web/client/__init__.py                  |   2 +-
 swh/web/client/client.py                    |  55 +++++++-
 swh/web/client/tests/api_data.py            | 210 ++++++++++++++++++++++++++++
 swh/web/client/tests/conftest.py            |  10 +-
 swh/web/client/tests/gen-api-data.sh        |   2 +
 swh/web/client/tests/test_web_api_client.py |  32 +++++
 6 files changed, 305 insertions(+), 6 deletions(-)
Changes applied before test
commit 64fa0f34079e4597ca98d265d36047bd8e421b55
Author: Antoine Eiche <lewo@abesis.fr>
Date:   Fri Apr 3 16:44:44 2020 +0200

    client: support optional date in Revision and Release
    
    From the model specification, the date attribute in Revision and
    Release objects is optional. This commit handles the date attribute
    set to the None value.
    
    It also tests the "typification" of a minimal Revision object to avoid
    regressions on this usecase.

commit 8d47566785824aa219ddb44e51e7b364b2fca54c
Author: Antoine Eiche <lewo@abesis.fr>
Date:   Wed Mar 25 17:52:19 2020 +0100

    client: add `visits` method to get the list of an origin visits
    
    A test is added to ensure the pagination and the data typing are
    working as expected.

See https://jenkins.softwareheritage.org/job/DWCLI/job/tests-on-diff/6/ for more details.

ardumont added a subscriber: ardumont.
ardumont added inline comments.
swh/web/client/client.py
73

since we are touching it, we can add its type:

def to_date(s: Optional[str], optional: Optional[bool] = False) -> datetime.datetime:
This revision is now accepted and ready to land.Apr 3 2020, 5:51 PM

Fix ardumont comment and rebase

Build has FAILED

Patch application report for D2958 (id=11446)

Rebasing onto bbf8d237af...

Current branch diff-target is up to date.
Changes applied before test
commit 3e42d0c70216af958c6a0f75c8b6dd53f8f3ef1a
Author: Antoine Eiche <lewo@abesis.fr>
Date:   Fri Apr 3 16:44:44 2020 +0200

    client: support optional date in Revision and Release
    
    From the model specification, the date attribute in Revision and
    Release objects is optional. This commit handles the date attribute
    set to the None value.
    
    It also tests the "typification" of a minimal Revision object to avoid
    regressions on this usecase.

Link to build: https://jenkins.softwareheritage.org/job/DWCLI/job/tests-on-diff/9/
See console output for more information: https://jenkins.softwareheritage.org/job/DWCLI/job/tests-on-diff/9/console

Build has FAILED

because mypy is unhappy about the current types:

09:59:31 swh/web/client/client.py:73: error: Incompatible return value type (got "None", expected "datetime")
09:59:31 swh/web/client/client.py:74: error: Argument 1 to "parse" has incompatible type "Optional[str]"; expected "Union[bytes, str, IO[str], IO[Any]]"

I've added comment in related line for the respective fix ;)

Cheers,

swh/web/client/client.py
73

-> Optional[datetime] and it should be mypy good

74–80

add an "assert s is not None" before this so mypy is happy as well.

tenma added inline comments.
swh/web/client/client.py
73

Hm, optional: Optional[bool] does not make sense, it is either True or False, and defaults to False. Use bool.

74–80

does mypy really requires it?

swh/web/client/client.py
74–80

Tested. Using -> Optional[datetime] is sufficient to typecheck this correctly.

tenma requested changes to this revision.Oct 15 2020, 10:59 AM
This revision now requires changes to proceed.Oct 15 2020, 10:59 AM
swh/web/client/client.py
74–80

i did not even realize Optional[bool], yeah, bool is enough ;)

This diff is now too old to land, pid references no longer exist, they got renamed.

swh/web/client/client.py
74–80

Ah, the part about parse call does not typecheck because of this... My bad.

ardumont edited reviewers, added: lewo; removed: ardumont.
  • Rebase according to latest changes in the repository
  • Adapt according to multiple reviews

Build is green

Patch application report for D2958 (id=15074)

Rebasing onto 5d04bc970f...

Current branch diff-target is up to date.
Changes applied before test
commit 0d962ea355439689ce6247f1efb9bbaee947d82c
Author: Antoine Eiche <lewo@abesis.fr>
Date:   Thu Oct 15 11:06:57 2020 +0200

    client: support optional date in Revision and Release
    
    From the model specification, the date attribute in Revision and
    Release objects is optional. This commit handles the date attribute
    set to the None value.
    
    It also tests the "typification" of a minimal Revision object to avoid
    regressions on this usecase.

See https://jenkins.softwareheritage.org/job/DWCLI/job/tests-on-diff/24/ for more details.

This revision is now accepted and ready to land.Oct 15 2020, 11:43 AM