Coder Social home page Coder Social logo

Strategies are `.pyx` only ? about gryphon HOT 6 CLOSED

garethdmm avatar garethdmm commented on August 30, 2024 1
Strategies are `.pyx` only ?

from gryphon.

Comments (6)

rgdagir avatar rgdagir commented on August 30, 2024

I had a similar bug. I don't know how the runner is parsing the strategy argument, so I just cd'ed into the strategies folder and ran gryphon-exec strategy mystrat (no .py at the end). Should work.

from gryphon.

garethdmm avatar garethdmm commented on August 30, 2024

The code that loads strategies is right here:

def get_strategy_class_from_filepath(strategy_path):
"""
Load a strategy that the library user has written and is specified as a filepath
from the current working directory to a .pyx file.
"""
module_path = strategy_path.replace('/', '.').replace('.pyx', '')
# Since in this case we're importing a file outside of the library, we have to
# add our current directory to the python path.
sys.path.append(os.getcwd())
module = importlib.import_module(module_path)
strategy_class = get_strategy_class_from_module(module)
return strategy_class

Looking at it now, yes it does expect .pyx and not .py. and because of the way importlib works, it will work if you don't give a filetype suffix. So:

gryphon-exec strategy strats/mystrat.py -> FAIL
gryphon-exec strategy strats/mystrat -> SUCCESS
gryphon-exec strategy strats/mystrat.pyx -> SUCCESS

Seems to me the simplest fix here would be to truncate both .py and .pyx suffixes from any strategy file and then let importlib succeed/fail on it's own. That will let users use .py or .pyx on their own whim. On the other hand, maybe we want to enforce one or the other filetype so that users get the biggest performance benefit possible from cython.

What do you guys think? I'm open to options.

from gryphon.

asmodehn avatar asmodehn commented on August 30, 2024

importlib already has a way to import a module from a filepath.
So I wouldn't want to add any logic on top of that.
Meaning :

  • argument is a file path, load the file path with importlib.
  • argument is a module name, load the module name with importlib.

However it can be quite troublesome to support between different python versions (see https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path)
So I guess this might depend on gryphon's expected minimum python version ?

If backward compatibility is needed, I made a while ago for other projects a backport of the python3 import logic into python2 : https://github.com/asmodehn/filefinder2, but that might add extra complexity that is not really needed, since python2 is dying already.

from gryphon.

garethdmm avatar garethdmm commented on August 30, 2024

Definitely looks like there's considerations with importlib as we move towards python3, but I think we can consider that as part of the python3 project.

I think the initial bug you identified, that loading strategies from .py files is broken, is big enough to fix immediately, and the fix is pretty simple: we just add one more 'replace' call on line 152 to strip '.py' suffixes as well as '.pyx'.

Do you want to make that edit and create a PR? You identified the bug so feels appropriate. If not I can do it too, just thought I'd offer!

from gryphon.

asmodehn avatar asmodehn commented on August 30, 2024

from gryphon.

asmodehn avatar asmodehn commented on August 30, 2024

I believe the fix left this part aside :
https://github.com/garethdmm/gryphon/blob/master/gryphon/execution/lib/config_helper.py#L96
Which means the configuration file should be named with "strat_name.py.conf" currently, and that is probably not intended

from gryphon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.