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

Deprecate getter and setter methods of Computer properties #4252

Merged
merged 1 commit into from
Jul 27, 2020

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Jul 10, 2020

Prepares for #2926

From aiida-core==1.0.0, we have started using properties for getters
and setters of the basic attributes of ORM entities. Rule of thumb here
is that if the attribute corresponds to a column on the underlying
database model, a property is used.

In addition, label is the preferred name for the third entity
identifier, alongside the ID and UUID. This is already the case for most
entities, except for Computer which is still using name. Here,
name is deprecated and replaced for label. The changes are not yet
propagated to the backend, which will be done once the deprecated
resources are fully removed. This is fine because the backend is not
part of the public API so doesn't have to go through a deprecation path.
The name keyword in Computer.objects.get is also deprecated and
replaced by label.

@sphuber sphuber requested a review from giovannipizzi July 10, 2020 17:58
@sphuber sphuber force-pushed the fix/2926/deprecate-computer-name branch from c64dbef to eb9b4aa Compare July 14, 2020 14:10
@codecov
Copy link

codecov bot commented Jul 14, 2020

Codecov Report

Merging #4252 into develop will decrease coverage by 0.01%.
The diff coverage is 88.89%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4252      +/-   ##
===========================================
- Coverage    79.24%   79.23%   -0.00%     
===========================================
  Files          468      468              
  Lines        34502    34559      +57     
===========================================
+ Hits         27336    27379      +43     
- Misses        7166     7180      +14     
Flag Coverage Δ
#django 71.14% <88.89%> (+0.02%) ⬆️
#sqlalchemy 72.01% <88.89%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
aiida/backends/testimplbase.py 84.85% <ø> (ø)
aiida/orm/computers.py 80.71% <88.24%> (+0.36%) ⬆️
aiida/manage/tests/pytest_fixtures.py 89.48% <100.00%> (ø)
aiida/orm/utils/builders/computer.py 88.05% <100.00%> (ø)
aiida/orm/implementation/django/computers.py 80.56% <0.00%> (-2.77%) ⬇️
aiida/orm/implementation/sqlalchemy/computers.py 78.75% <0.00%> (-2.50%) ⬇️

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 bced84e...429491d. Read the comment docs.

@sphuber sphuber requested a review from ltalirz July 15, 2020 09:08
Copy link
Member

@ltalirz ltalirz 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 for taking care of fixing this!

Definitely agree with these deprecations; just a couple of minor comments & questions

"""
return self._backend.computers.list_names()

def list_labels(self):
"""Return a list with all the names of the computers in the DB."""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""Return a list with all the names of the computers in the DB."""
"""Return a list with all the labels of the computers in the DB."""


:rtype: :class:`aiida.orm.Computer`
.. deprecated:: 1.4.0
The keyword name will be removed in `v2.0.0`, use `label` instead.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The keyword name will be removed in `v2.0.0`, use `label` instead.
The `name` keyword will be removed in `v2.0.0`, use `label` instead.

def transport_type(self, value: str):
"""Set the computer transport_type.

:param value: the transport_type to set.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:param value: the transport_type to set.
:param value: the transport type to set.

Will be removed in `v2.0.0`, use the `label` property instead.
"""
warnings.warn('this property is deprecated, use `label` instead', AiidaDeprecationWarning) # pylint: disable=no-member
return self._backend_entity.name
Copy link
Member

Choose a reason for hiding this comment

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

you might want to use the label property instead (in case we need to change something there)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the backend entity doesn't have a label property though. The plan was to correct this once all the name related code is ripped out just before v2.0. Since it is not public facing API we can change that at any time

Copy link
Member

Choose a reason for hiding this comment

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

I meant. self.label

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, will do

Copy link
Member

Choose a reason for hiding this comment

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

Not sure I was clear - I meant to simply replace this by return self.label, since we're repeating ourselves here which might (in principle) lead to divergence between self.label and self.get_label().

In any case, since this is just one line and is going to be removed eventually, it's just minor and I'll approve now.

Comment on lines 156 to 158
self.assertEqual(new_computer.get_mpirun_command(), options_dict_full['mpirun-command'].split())
self.assertEqual(new_computer.get_shebang(), options_dict_full['shebang'])
self.assertEqual(new_computer.get_workdir(), options_dict_full['work-dir'])
Copy link
Member

Choose a reason for hiding this comment

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

What about these - shouldn't these also become properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When making these changes I have followed the following:

Rule of thumb here is that if the attribute corresponds to a column on the underlying
database model, a property is used.

Since these properties here are stored in the metadata column, and in a sense are comparable to a node's attributes, I am not sure if we should give properties for all of them. This is an arbitrary choice ultimately, but one that at least tries to keep consistency with the other entities such as the Node class. The database columns are exposed through properties, while anything else gets normal methods. In the latter, we should even ask ourselves to what level we want to give individual methods to all these sub attributes. Giving too many clutters the interface, however, it does make it tab-discoverable. Putting them behind a generic Computer.get_property('shebang') makes the interface cleaner and more maintainable but maybe less discoverable. I am not sure yet what the best solution is here

@sphuber sphuber force-pushed the fix/2926/deprecate-computer-name branch from eb9b4aa to f433b7e Compare July 24, 2020 14:07
From `aiida-core==1.0.0`, we have started using properties for getters
and setters of the basic attributes of ORM entities. Rule of thumb here
is that if the attribute corresponds to a column on the underlying
database model, a property is used.

In addition, `label` is the preferred name for the third entity
identifier, alongside the ID and UUID. This is already the case for most
entities, except for `Computer` which is still using `name`. Here,
`name` is deprecated and replaced for `label`. The changes are not yet
propagated to the backend, which will be done once the deprecated
resources are fully removed. This is fine because the backend is not
part of the public API so doesn't have to go through a deprecation path.
The `name` keyword in `Computer.objects.get` is also deprecated and
replaced by `label`.
@sphuber sphuber force-pushed the fix/2926/deprecate-computer-name branch from f433b7e to 429491d Compare July 24, 2020 14:18
@sphuber sphuber requested a review from ltalirz July 24, 2020 14:24
Copy link
Member

@ltalirz ltalirz 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 !

@sphuber sphuber merged commit 592dd36 into aiidateam:develop Jul 27, 2020
@sphuber sphuber deleted the fix/2926/deprecate-computer-name branch July 27, 2020 06:29
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.

2 participants