-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restructuring API #199
Comments
Rather than a |
Since Python standard libraries use factory functions as API too, e.g.: https://docs.python.org/3/library/ipaddress.html Having said that, it's not super difficult to support multiple signatures of class Julia:
def __init__(self, libjulia=None, **kwargs):
if libjulia is None:
libjulia, kwargs = self.default_libjulia(**kwargs)
self.setup(libjulia, **kwargs)
@staticmethod
def default_libjulia(runtime=None, bindir=None, **unused):
return (LibJulia(JuliaInfo.load(runtime=runtime, bindir=bindir)),
unused)
def setup(self, libjulia, init_julia=True):
self.libjulia = libjulia
if init_julia:
libjulia.init_julia() |
My thinking is that 99% of pyjulia users will want the default options, so it seems nicer to just support this with |
My guess is that most Julia users would just use I'm still slightly uneasy to do all the initializations in For Julia users, most of the reason why they call the custom initialization routine ( import julia
julia.setup("julia-0.7") # a Julia instance would be returned but it's OK to ignore
from julia import Main
Main.eval('@assert VERSION < v"1"') If they want to use |
This was implemented in #235. See: https://pyjulia.readthedocs.io/en/latest/api.html It turned out I didn't need to touch |
Here are some ideas on refactoring PyJulia APIs and internals. Mainly, I suggest to introduce two new classes
JuliaInfo
andLibJulia
.JuliaInfo
---libjulia
discovery mechanismI suggest to turn
JuliaInfo
into a proper class. It is at the moment a namedtuple:pyjulia/julia/core.py
Lines 263 to 267 in cdbefb1
For example, we have
is_compatible_python
which is better be organized as a method.LibJulia
--- Low-level C APIJulia
has a rather lengthy__init__
which mainly setting up another objectJulia.api
. This is probably better be organized into another class.Importantly, I suggest to make
LibJulia.init_julia
lazy (by default) and idempotent. It lets users to run functions that cannot be called after the initialization (e.g.,jl_parse_opts
; ok I'm not sure if there are something else) while integrating with high-level API provided by PyJulia.I added some
jl_unbox_*
functions in another PR #186 (a954914). Adding those C API could be useful, too.Julia
--- High-level PyCall-based APISince low-lvel libjulia handling is decoupled,
Julia
class now can focus on high-level API based on PyCall. I also suggest to move some "free functions" (e.g.,isdefined
) whose first argument wasjulia
to methods.get_julia
Since initializing
Julia
API now takes a few steps, I suggest to add a factory function which is equivalent to currentjulia.core.Julia
.The text was updated successfully, but these errors were encountered: