singularityhub / singularity-cli

streamlined singularity python client (spython) for singularity
https://singularityhub.github.io/singularity-cli/
Mozilla Public License 2.0
57 stars 31 forks source link

Getting an instance object using client.instances('instance_name') returns list of all instances #83

Closed adl2db closed 5 years ago

adl2db commented 5 years ago

Expected Behavior

using client.instances('name_of_instance') should return an Instance object

Following Sample from Documentation

Actual Behavior

using client.instances('name_of_instance') should returns list of instances

Steps to Reproduce

>>> from spython.main import Client as client  
>>> client.instances()
INSTANCE NAME    PID      IMAGE
instance0        23991    /redacted/alpine_latest.sif
instance1        24313    /redacted/alpine_latest.sif
>>> myinstance = client.instances('instance0')
INSTANCE NAME    PID      IMAGE
instance0        23991   /redacted/alpine_latest.sif
instance1        24313    /redacted/alpine_latest.sif
>>>print(type(myinstance))
<class 'list'>
>>>myinstance = myinstance[0]
>>>print(type(myinstance))
<class 'spython.instance.Instance'>

Context

[provide more detailed introduction to the issue itself . This is for make a reproducible issue.]

vsoch commented 5 years ago

What is the issue? I don't see it. The return is a list as you suggested.

vsoch commented 5 years ago

Do you mean you expect a return of one instance and not a list?

vsoch commented 5 years ago

@adl2db this is expected behavior - if you look here the general "instances" command will return a list given that there are more than one instances found. It only returns a single instance given that one instance is found:

    # If we are given a name, return just one
    if name is not None and instances is not None:
        if len(instances) == 1:
            instances = instances[0]

Given that you provided a name, it could be that the statement needs to be:

    # If we are given a name, return just one
    if name != None and instances != None:
        if len(instances) == 1:
            instances = instances[0]

I can either reproduce this for you if you provide the full sequence of creating the instances, or I can do a PR that tests that change. It looks like the bug is that if name is provided, the list of instances isn't actually filtered down.

vsoch commented 5 years ago

hey @adl2db ! I understand your issue - and agreed, if you provide a name a single instance should be returned! Here is a pull request for you to test -> https://github.com/singularityhub/singularity-cli/pull/84 could you let me know if it resolves your issue?