Skip to content
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

Incorporating JLD into package, and using custom types from that package #247

Open
IanButterworth opened this issue Feb 26, 2019 · 4 comments

Comments

@IanButterworth
Copy link
Member

IanButterworth commented Feb 26, 2019

I'd like to use JLD within a package to save custom types from that same package. What's the correct way to do this? Call the package itself from within addrequire() (which causes an error if I do it as below)? Or should the package in addrequire() be a lighter-weight types-only package? Is there a performance hit if it's the former?

i.e. within the package ThisPackage, this errors

jldopen(filepath, "w") do file
        addrequire(file,ThisPackage)
        write(file, "x", x)
    end
ERROR: UndefVarError: module_parent not defined
Stacktrace:
 [1] _istoplevel(::Module) at C:\Users\IanB\.julia\packages\JLD\1BoSz\src\JLD.jl:1253
 [2] addrequire(::JLD.JldFile, ::Module) at C:\Users\IanB\.julia\packages\JLD\1BoSz\src\JLD.jl:1256
...
@IanButterworth
Copy link
Member Author

Also, is there any reason to not do this with JLD, over HDF5.jl etc.? I'm using JLD as there were examples, and I couldn't immediately find how to use custom types in HDF5

@IanButterworth
Copy link
Member Author

I just realized that the error above is a <1.0 error that's fixed in master. It would be good to push a new release out to catch that @JeffBezanson

@virgodi
Copy link

virgodi commented Jun 26, 2019

Hi ! Is there a plan to make a tag a out of the latest master ? Facing the same issue...

@truedichotomy
Copy link

Have the same issue, gives me ERROR: LoadError: UndefVarError: module_parent not defined error. Test code attached.

debugCode.jl:

using JLD
push!(LOAD_PATH, pwd());

import debugTypes: Type1, Type2
import debugTypes

a = Type1(3.14);
b = Type2(100.0);

filepath = "test_data.jld"
jldopen(filepath,"w") do file
    addrequire(file, debugTypes)
    write(file, "a", a, "b", b)
end

debugTypes.jl:

module debugTypes

using Dates
export Type1, Type2

mutable struct Type1
    var1::Float64
end

struct Type2
    var2::Float64
end

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants