Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile: do not leak repository implementation in interface #4891

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Apr 29, 2021

Fixes #4890

The Profile interface was leaking implementation details of the
repository. For example, the method get_repository_container returned
the Container class of the disk-objectstore library, but this is an
implementation detail. If this ever were to change all client code would
break.

Instead, we add the get_repository method which returns an instance of
the generic Repository class that will be common to all repository
implementations. The backend implementation can still be obtained
through this object but this should only be done in exceptional cases.

The Repository class now has three additional properties and methods:

  • def uuid(self) -> typing.Optional[str]:
  • def initialise(self, **kwargs) -> None:
  • def is_initialised(self) -> bool:

These simply call through to the exact same method/property on the
backend instance. The AbstractRepositoryBackend also now has the exact
same attributes and they are implemented for the two currently existing
implementations DiskObjectStoreRepositoryBackend and the
SandboxRepositoryBackend.

@sphuber sphuber requested a review from mbercx April 29, 2021 11:22
@sphuber
Copy link
Contributor Author

sphuber commented Apr 29, 2021

Haven't gone over all the comments of @CasperWA of the other PR yet, but will do later. I propose @mbercx already goes over the suggested interface changes here. Will have time to get back to this later in the afternoon.

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well perhaps I should say, approved after it doesn't break all the tests lol

@CasperWA
Copy link
Contributor

Haven't gone over all the comments of @CasperWA of the other PR yet, but will do later (...)

They're all syntax and style, essentially. So no worries.

mbercx
mbercx previously requested changes Apr 29, 2021
Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sphuber. Gave the PR a first pass.

aiida/manage/configuration/profile.py Outdated Show resolved Hide resolved
aiida/manage/manager.py Outdated Show resolved Hide resolved
aiida/manage/configuration/profile.py Outdated Show resolved Hide resolved
@sphuber sphuber force-pushed the fix/4890/profile-repository-interface branch 2 times, most recently from 00bb1a0 to 1934981 Compare April 29, 2021 13:41
@sphuber
Copy link
Contributor Author

sphuber commented Apr 29, 2021

Alright, this should be much better. If you guys are happy with the design, I will add the necessary tests for the new Repository and RepositoryBackend properties and methods.

@mbercx
Copy link
Member

mbercx commented Apr 29, 2021

Alright, this should be much better. If you guys are happy with the design, I will add the necessary tests for the new Repository and RepositoryBackend properties and methods.

Looking very good indeed! Much cleaner to have these methods on the Repository class. 👌 Will do a proper review and some testing after the wrap-up meeting.

@chrisjsewell
Copy link
Member

Looking very good indeed!

not that it means much to have @mbercx 's seal of a approval

@CasperWA
Copy link
Contributor

Looking very good indeed!

not that it means much to have @mbercx 's seal of a approval

Indeed. I quickly jumped in to review when I saw I blanketed this PR ... tsk tsk tsk... 😂

@mbercx
Copy link
Member

mbercx commented Apr 29, 2021

Looking very good indeed!

not that it means much to have @mbercx 's seal of a approval

Does that mean I don't have to review PR's anymore? 🥳

aiida/cmdline/commands/cmd_status.py Show resolved Hide resolved
aiida/repository/backend/sandbox.py Show resolved Hide resolved
aiida/repository/repository.py Show resolved Hide resolved
tests/cmdline/commands/test_setup.py Outdated Show resolved Hide resolved
tests/cmdline/commands/test_setup.py Outdated Show resolved Hide resolved
@CasperWA
Copy link
Contributor

Looking very good indeed!

not that it means much to have @mbercx 's seal of a approval

Does that mean I don't have to review PR's anymore? 🥳

Nah. Just means more work for the rest of us 😂

@sphuber sphuber force-pushed the fix/4890/profile-repository-interface branch 2 times, most recently from aab092a to 04cd181 Compare April 29, 2021 15:21
@sphuber
Copy link
Contributor Author

sphuber commented Apr 29, 2021

Ok, the docs are failing with the following:

/home/circleci/.local/lib/python3.7/site-packages/aiida/manage/configuration/profile.py:docstring of aiida.manage.configuration.Profile.get_repository:: WARNING: py:class reference target not found: Repository
/home/circleci/.local/lib/python3.7/site-packages/aiida/manage/configuration/profile.py:docstring of aiida.manage.configuration.profile.Profile.get_repository:: WARNING: py:class reference target not found: Repository

This is most likely becuase of the return type, which I put as a string. The reason being that I cannot import Repository at the top of the module, because this leads to a circular import. For the typing, I put a guard in if typing.TYPE_CHECKING which makes sure mypy can properly import it, but for the docs this doesn't work. Not sure how to get around this. Any ideas? Other than maybe trying to break the circular import in the aiida.repository.Repository path, but that might not be trivial.

@chrisjsewell
Copy link
Member

This is most likely becuase of the return type, which I put as a string.

yeh its an annoying sphinx thing (sphinx-doc/sphinx#8498), just add it to the docs/source/nitpick-exceptions

The `Profile` interface was leaking implementation details of the
repository. For example, the method `get_repository_container` returned
the `Container` class of the `disk-objectstore` library, but this is an
implementation detail. If this ever were to change all client code would
break.

Instead, we add the `get_repository` method which returns an instance of
the generic `Repository` class that will be common to all repository
implementations. The backend implementation can still be obtained
through this object but this should only be done in exceptional cases.

The `Repository` class now has three additional properties and methods:

 * `def uuid(self) -> typing.Optional[str]:`
 * `def initialise(self, **kwargs) -> None:`
 * `def is_initialised(self) -> bool:`

These simply call through to the exact same method/property on the
backend instance. The `AbstractRepositoryBackend` also now has the exact
same attributes and they are implemented for the two currently existing
implementations `DiskObjectStoreRepositoryBackend` and the
`SandboxRepositoryBackend`.
@sphuber sphuber force-pushed the fix/4890/profile-repository-interface branch from 04cd181 to 8145703 Compare April 30, 2021 07:58
@codecov
Copy link

codecov bot commented Apr 30, 2021

Codecov Report

Merging #4891 (8145703) into develop (975affe) will increase coverage by 0.03%.
The diff coverage is 90.55%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4891      +/-   ##
===========================================
+ Coverage    80.10%   80.12%   +0.03%     
===========================================
  Files          517      517              
  Lines        36617    36659      +42     
===========================================
+ Hits         29327    29368      +41     
- Misses        7290     7291       +1     
Flag Coverage Δ
django 74.58% <89.19%> (+0.01%) ⬆️
sqlalchemy 73.53% <89.19%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/cmdline/commands/cmd_setup.py 49.13% <0.00%> (ø)
aiida/manage/manager.py 81.36% <0.00%> (+0.91%) ⬆️
aiida/backends/general/migrations/utils.py 88.89% <62.50%> (-0.97%) ⬇️
aiida/repository/backend/sandbox.py 98.04% <91.67%> (-1.96%) ⬇️
aiida/manage/configuration/profile.py 95.06% <92.31%> (-0.05%) ⬇️
...ds/djsite/db/migrations/0047_migrate_repository.py 70.97% <100.00%> (ø)
...ations/versions/1feaea71bd5a_migrate_repository.py 81.14% <100.00%> (ø)
aiida/cmdline/commands/cmd_status.py 74.74% <100.00%> (ø)
aiida/orm/nodes/node.py 96.03% <100.00%> (-0.02%) ⬇️
aiida/orm/nodes/repository.py 93.59% <100.00%> (-0.08%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 975affe...8145703. Read the comment docs.

@sphuber
Copy link
Contributor Author

sphuber commented Apr 30, 2021

@mbercx would you still like a gander before we merge?

@mbercx
Copy link
Member

mbercx commented Apr 30, 2021

@mbercx would you still like a gander before we merge?

LGMT! 🚀

@sphuber sphuber merged commit fa8d05f into aiidateam:develop Apr 30, 2021
@sphuber sphuber deleted the fix/4890/profile-repository-interface branch April 30, 2021 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not leak disk-objectstore specificities in the public interface of the Profile
4 participants