project-lovelace / lovelace-problems

🧪 Project Lovelace problem modules for generating test cases.
https://projectlovelace.net/
MIT License
33 stars 2 forks source link

Engine should use the solutions repo #21

Closed bazadactyl closed 5 years ago

bazadactyl commented 5 years ago

Instead of using solve_test_case(test_case) the engine should load the correct solution/function from the lovelace-solutions repo. This way we don’t repeat the solution code.

ali-ramadhan commented 5 years ago

Moving to lovelace-problems as solve_test_case is defined in the problem modules.

ali-ramadhan commented 5 years ago

Should note that because the solution files use dashes in the filenames (e.g. rocket-science.py) importing the solutions is awkward and we have to use __import__ like:

_m = __import__('solutions.rocket-science', globals(), locals(), fromlist=['rocket_fuel'], level=0)
_m.rocket_fuel(45)

See: https://docs.python.org/3/library/functions.html#__import__

I think we need the dashes so that the solution filename matches the "problem name" in Django, but if not, would be nice to switch back to dashes.

X-ref: https://github.com/project-lovelace/lovelace-website/issues/38

ali-ramadhan commented 5 years ago

Never mind, importlib.import_module('solutions.rocket-science') works in the REPL but not in production. I also don't fully understand python relative imports.