Skip to content

Commit 459e13e

Browse files
committed
Review
1 parent 7c15022 commit 459e13e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/aiida/cmdline/commands/cmd_code.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def set_code_builder(ctx, param, value):
8585
"""Set the code spec for defaults of following options."""
8686
from aiida.orm.utils.builders.code import CodeBuilder
8787

88+
# TODO(danielhollas): CodeBuilder is deprecated, rewrite this somehow?
8889
with warnings.catch_warnings(record=True):
8990
ctx.code_builder = CodeBuilder.from_code(value)
9091
return value
@@ -125,6 +126,7 @@ def setup_code(ctx, non_interactive, **kwargs):
125126
if kwargs['input_plugin']:
126127
kwargs['input_plugin'] = kwargs['input_plugin'].name
127128

129+
# TODO(danielhollas): CodeBuilder is deprecated
128130
with warnings.catch_warnings(record=True):
129131
code_builder = CodeBuilder(**kwargs)
130132

@@ -227,10 +229,16 @@ def show(code):
227229
table.append(['PK', code.pk])
228230
table.append(['UUID', code.uuid])
229231
table.append(['Type', code.entry_point.name])
232+
# TODO(danielhollas): This code is a bit too clever, make it simpler!
233+
# It generates warnings because it accessess deprecated attributes such as
234+
# Code.repository_metadata -> Code.base.repository.metadata
235+
# Code.attributes -> Code.base.attributes.all
236+
# Code.extras -> Code.base.extras.all
237+
# Also also, the blanket `except AttributeError` is evil and can hide bugs.
230238
for key in code.Model.model_fields.keys():
231239
try:
232-
with warnings.catch_warnings(record=True):
233-
table.append([key.capitalize().replace('_', ' '), getattr(code, key)])
240+
# with warnings.catch_warnings(record=True):
241+
table.append([key.capitalize().replace('_', ' '), getattr(code, key)])
234242
except AttributeError:
235243
continue
236244
if is_verbose():

tests/transports/test_all_plugins.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
# TODO : test for exotic cases of copy with source = destination
3434
# TODO : silly cases of copy/put/get from self to self
3535

36+
CHDIR_WARNING = re.escape('`chdir()` is deprecated and will be removed')
37+
3638

3739
@pytest.fixture(scope='function')
3840
def tmp_path_remote(tmp_path_factory):
@@ -323,7 +325,7 @@ def test_chdir_to_empty_string(custom_transport):
323325
return
324326

325327
with custom_transport as transport:
326-
with pytest.warns(AiidaDeprecationWarning, match=re.escape('`chdir()` is deprecated and will be removed')):
328+
with pytest.warns(AiidaDeprecationWarning, match=CHDIR_WARNING):
327329
new_dir = transport.normalize(os.path.join('/', 'tmp'))
328330
transport.chdir(new_dir)
329331
transport.chdir('')
@@ -988,15 +990,15 @@ def test_exec_pwd(custom_transport, tmp_path_remote):
988990
subfolder = """_'s f"#""" # A folder with characters to escape
989991
subfolder_fullpath = os.path.join(location, subfolder)
990992

991-
with pytest.warns(AiidaDeprecationWarning, match=re.escape('`chdir()` is deprecated and will be removed')):
993+
with pytest.warns(AiidaDeprecationWarning, match=CHDIR_WARNING):
992994
transport.chdir(location)
993995
if not transport.isdir(subfolder):
994996
# Since I created the folder, I will remember to
995997
# delete it at the end of this test
996998
transport.mkdir(subfolder)
997999

9981000
assert transport.isdir(subfolder)
999-
with pytest.warns(AiidaDeprecationWarning, match=re.escape('`chdir()` is deprecated and will be removed')):
1001+
with pytest.warns(AiidaDeprecationWarning, match=CHDIR_WARNING):
10001002
transport.chdir(subfolder)
10011003

10021004
assert subfolder_fullpath == transport.getcwd()

0 commit comments

Comments
 (0)