threefoldtecharchive / jumpscaleX_core

Apache License 2.0
1 stars 6 forks source link

autocompletion broken [development_3git] #246

Closed despiegk closed 4 years ago

despiegk commented 5 years ago

image

used

`kosmos -p 'j.tutorials.worldtest.scheduling.test()'

    def test(self):
        """
        to run:

        kosmos -p 'j.tutorials.worldtest.scheduling.test()'
        """

        ships = Ships()
        ships.delete()
        r = ships.find()
        assert r == []

        ship1 = ships.get(name="ibizaboat")
        assert ship1.name == "ibizaboat"

        ship2 = ships.get(name="ibizaboat2")
        assert ship2.name == "ibizaboat2"

        res = {}
        for i in range(10):
            res[i] = ship2.scheduler.schedule("wait", ship1.wait_test)

        ship2.scheduler.schedule("waitrecurring", ship1.wait_test, period=2)

        event = ship2.scheduler.event_get("wait_event_1")

        for i in range(10):
            ship2.scheduler.schedule("waitb", ship1.wait_test, event=event)

        j.shell()

        print("TEST OK")
abom commented 5 years ago
3BOTDEVEL:3bottest:~: kosmos -p 'j.tutorials.worldtest.scheduling.test()'
Mon 18 09:03:03 <string>             -   1 - <module>                           : EXCEPTION: 
    AttributeError("'group_j__tutorials' object has no attribute 'worldtest'",)
--TRACEBACK------------------
<string> in <module>
    1
-----------------------------

Is this code pushed? i've latest development_3git in all repos (also re-did jsx generate).

abom commented 5 years ago

Code was pushed and still investigating. It seems like _properties_names_get for j.basclasses.object based objects only, it returns empty list. Any class that inherits j.baseclasses.object might have this problem (not e.g. j.baseclasses.object_config).

abom commented 5 years ago

So, JSBase._inspect() get called earlier and newer properties defined in _init cannot be listed.

Till now, i didn't get the root cause of the problem, only calling obj._insepct() before trying to list properties would work, and don't know if it's the right solution.

abom commented 5 years ago

I found the main issue here, in JSBase we call self.__init_class() first:

https://github.com/threefoldtech/jumpscaleX_core/blob/d6282eedc1140630d414261b5ab3691a1ab365c8/JumpscaleCore/core/BASECLASSES/JSBase.py#L61-L66

which results in calling other methods that call properties, which if called once, will just get old values if called again, so if _init is called after, and it introduces some new properties set as self.prop.... inside the method, they won't get listed by calling properties again.

https://github.com/threefoldtech/jumpscaleX_core/blob/d6282eedc1140630d414261b5ab3691a1ab365c8/JumpscaleCore/core/BASECLASSES/JSBase.py#L71-L75

Screenshot from 2019-11-19 14-12-32

Now i don't know the what should be the actual order of calling __init_class and _init inside JSBase (even got confused by how much inits are there!):

https://github.com/threefoldtech/jumpscaleX_core/blob/d6282eedc1140630d414261b5ab3691a1ab365c8/JumpscaleCore/core/BASECLASSES/JSBase.py#L59-L66

abom commented 5 years ago

I added this fix https://github.com/threefoldtech/jumpscaleX_core/pull/248/commits/7a9040e73ce511e0e442cd997aeb70920c99f8d4.

It contains the solution mentioned earlier

...only calling obj._insepct() before trying to list properties would work, and don't know if it's the right solution.

Pishoy commented 5 years ago

not working with me as below steps

3BOTDEVEL:3bot:~: kosmos -p 'j.tutorials.worldtest.scheduling.test()'
Wed 20 11:07:26 BCDB.py              - 448 - bcdb                               : load model:jumpscale.bcdb.acl.circle.2
Wed 20 11:07:26 BCDB.py              - 448 - bcdb                               : load model:jumpscale.bcdb.acl.user.2
Wed 20 11:07:26 BCDB.py              - 448 - bcdb                               : load model:jumpscale.example.ship.1
Wed 20 11:07:26 BCDB.py              -  87 - bcdb                               : BCDB INIT DONE:system
Wed 20 11:07:26 6551e65f3b187bf1b.py -  31 - 1_0efba627421ce096551e65f3b187bf1b : init index:jumpscale.example.ship.1
waittest:1
waittest:1
waittest:1
waittest:1
waittest:1
waittest:1
waittest:1
abom commented 4 years ago

@Pishoy the code was changed, you cannot test it this way kosmos -p 'j.tutorials.worldtest.scheduling.test()'

Maybe you can put a j.shell() before or so.

Also, this won't work in new kosmos sessions, only using j.shell() as it's embedded and you can access local variables.

Pishoy commented 4 years ago

after adding js_shell before ship2.scheduler.sleep_time, it works image