espeed / bulbs

A Python persistence framework for graph databases like Neo4j, OrientDB and Titan.
http://bulbflow.org
Other
622 stars 83 forks source link

Can't load any Gremlin scripts file other that 'gremlin.groovy' #116

Closed Sitin closed 10 years ago

Sitin commented 10 years ago

Assuming that rank_items function defined in both files:

The following works, ok:

g.scripts.update('gremlins/gremlin.groovy')
script = g.scripts.get('rank_items')

But the next causing an error:

g.scripts.update('gremlins/other_file_name.groovy')
script = g.scripts.get('rank_items')

It seems that file loaded but Gremlin function wasn't added to methods dictionary.

espeed commented 10 years ago

What version of Bulbs are you using?

$ pip freeze | grep bulbs
espeed commented 10 years ago

Scripts are stored in namespaces that correspond to their file name.

All the Bulbs built-in scripts are defined in gremlin.groovy files so gremlin is the default namespace.

When you define a Gremlin function in a file named something other than gremlin.groovy, you need to specify the namespace when getting the script.

For example, in Bulbs 0.3.25 you should be able to do...

>>> from bulbs.rexster import Graph
>>> g = Graph()
>>> g.scripts.update('somefile.groovy')

>>> g.scripts.namespace_map.keys()       # list of namespaces
>>> g.scripts.get_methods('somefile')    # all methods for the 'somefile' namespace

>>> g.scripts.get("somefile:rank_items")      # get script by prefixing the namespace
>>> g.scripts.get("rank_items", "somefile")   # get script via the namespace arg

See https://github.com/espeed/bulbs/blob/master/bulbs/groovy.py

Sitin commented 10 years ago

Thank you for your answer. I still think that letting the user specify namespaces explicitly is much better. For example:

g.scripts.update('any_file.groovy', namespace='where_i_want_to_put_it')

But this is a Rexter's convention. So, let's consider this as a documentation issue.

espeed commented 10 years ago

You can specify the namespace explicity, i.e. this works...

>>> g.scripts.update('somefile.groovy', namespace='where_i_want_to_put_it')
>>> g.scripts.get("where_i_want_to_put_it:rank_items")      
>>> g.scripts.get("rank_items", "where_i_want_to_put_it") 
espeed commented 10 years ago

Resolved.

Sitin commented 10 years ago

Perfect. Thank you.