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

Formats supported in package submodules #194

Closed
TransGirlCodes opened this issue Aug 7, 2018 · 2 comments
Closed

Formats supported in package submodules #194

TransGirlCodes opened this issue Aug 7, 2018 · 2 comments

Comments

@TransGirlCodes
Copy link

Hi, when adding format and specifying a package that supports the reader and writer for a format, if the reader and writer are in some submodule do I have to qualify the submodule or is the package name adequate? e.g. which of these two possibilities is the correct one?

add_format(format"FASTA", (), [".fasta", ".fa"], [Symbol("BioSequences.FASTA")])

or

add_format(format"FASTA", (), [".fasta", ".fa"], [:BioSequences])

Thanks!

@alhirzel
Copy link
Contributor

Here is an idiom that works for me.

using FileIO

module ManyLoadersSavers
	import FileIO
	using FileIO: @format_str

	function load end

	"""implement loader for a fictional filetype, .FileType"""
	module FileTypeIO
		using Test: @test
		using ..ManyLoadersSavers
		using ..ManyLoadersSavers: load
		import FileIO
		using FileIO: @format_str

		function ManyLoadersSavers.load(f::FileIO.File{format"filetype"})
			@test "MagicString" == read(f.filename, String)
		end

		function __init__()
			FileIO.add_format(format"filetype", (), [".FileType"])
			FileIO.add_loader(format"filetype", :ManyLoadersSavers)
		end
	end

	# artifically pass a module check in FileIO
	abstract type DummyTypeWithAnyName end
	load(f::DummyTypeWithAnyName) = error("never gets called")
end

# this is what the current check uses
mods = map(m -> m.module, methods(ManyLoadersSavers.load))
@info "here are the modules detected" mods

mktempdir() do dir

	# generate test file
	fn = joinpath(dir, "asdf.FileType")
	open(fn, "w") do fh
		write(fh, "MagicString")
	end

	# attempt to load using FileIO
	@info "Loaded" load(fn)
end

@timholy
Copy link
Member

timholy commented Mar 3, 2021

In #295 it because possible to supply the module directly, so this can be closed. Thanks @alhirzel for posting the workaround.

@timholy timholy closed this as completed Mar 3, 2021
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