-
Notifications
You must be signed in to change notification settings - Fork 11
Move JLD2.jl dependency to a package extension #50
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
Open
simsurace
wants to merge
5
commits into
master
Choose a base branch
from
jld2-ext
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
943c590
Move JLD2.jl dependency to a package extension
simsurace 9ea2746
Set compat and CI to Julia LTS version
simsurace ea2141e
Use error hint instead of explicit error
simsurace cb5f1ab
Move savedot stuff back to package
simsurace 1b90d74
Correct typos
simsurace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,26 @@ | ||
| name = "MetaGraphs" | ||
| uuid = "626554b9-1ddb-594c-aa3c-2596fe9399a5" | ||
| version = "0.8.1" | ||
| version = "0.9.0" | ||
|
|
||
| [deps] | ||
| Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" | ||
| JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" | ||
| Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
|
|
||
| [weakdeps] | ||
| JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" | ||
|
|
||
| [extensions] | ||
| MetaGraphsJLD2Ext = ["Graphs", "JLD2"] | ||
|
|
||
| [compat] | ||
| Graphs = "1.4" | ||
| JLD2 = "0.1.11, 0.2, 0.3, 0.4, 0.5, 0.6" | ||
| julia = "1" | ||
| julia = "1.10" | ||
|
|
||
| [extras] | ||
| Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" | ||
| JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" | ||
| Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
|
||
| [targets] | ||
| test = ["Test", "Base64"] | ||
| test = ["Test", "Base64", "JLD2"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| module MetaGraphsJLD2Ext | ||
|
|
||
| using Graphs | ||
| using JLD2 | ||
| using MetaGraphs | ||
|
|
||
| function MetaGraphs.loadmg(fn::AbstractString) | ||
| @load fn g | ||
| return g | ||
| end | ||
|
|
||
| function MetaGraphs.savemg(fn::AbstractString, g::AbstractMetaGraph) | ||
| @save fn g | ||
| return 1 | ||
| end | ||
|
|
||
| # escaping unescaped quotation marks | ||
| # i.e. replacing `"`` with `\"` while leaving `\"` as is | ||
| escape_quotes(s::AbstractString) = replace(s, r"([^\\])\"" => s"\1\\\\\"") | ||
|
|
||
| # According to the DOT language specification https://graphviz.org/doc/info/lang.html | ||
| # we can quote everyhthing that's not an XML/HTML literal | ||
| function quote_prop(p::AbstractString) | ||
| if occursin(r"<+.*>+$", p) | ||
| # The label is an HTML string, no additional quotes here. | ||
| return p | ||
| else | ||
| return "\"" * escape_quotes(p) * "\"" | ||
| end | ||
| end | ||
| # if the property value is _not_ a string it cannot be XML/HTML literal, so just put it in quotes | ||
| quote_prop(p::Any) = "\"" * escape_quotes(string(p)) * "\"" | ||
| # NOTE: down there I only quote property _values_. DOT allows quoting property _names_ too | ||
| # I don't do that as long as names are Symbols and can't have spaces and commas and stuff. | ||
| # That will break if someone uses a DOT keyword as a property name, as they must be quoted. | ||
|
|
||
| function MetaGraphs.savedot(io::IO, g::AbstractMetaGraph) | ||
| if is_directed(g) | ||
| write(io, "digraph G {\n") | ||
| dash = "->" | ||
| else | ||
| write(io, "graph G {\n") | ||
| dash = "--" | ||
| end | ||
|
|
||
| for p in props(g) | ||
| write(io, "$(p[1])=$(quote_prop(p[2]));\n") | ||
| end | ||
|
|
||
| for v in vertices(g) | ||
| write(io, "$v") | ||
| if length(props(g, v)) > 0 | ||
| write(io, " [ ") | ||
|
|
||
| for p in props(g, v) | ||
| write(io, "$(p[1])=$(quote_prop(p[2])), ") | ||
| end | ||
|
|
||
| write(io, "];") | ||
| end | ||
| write(io, "\n") | ||
| end | ||
|
|
||
| for e in edges(g) | ||
| write(io, "$(src(e)) $dash $(dst(e)) [ ") | ||
| for p in props(g,e) | ||
| write(io, "$(p[1])=$(quote_prop(p[2])), ") | ||
| end | ||
| write(io, "]\n") | ||
| end | ||
| write(io, "}\n") | ||
| end | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| using Graphs | ||
| using MetaGraphs | ||
|
|
||
| using JLD2 | ||
| using Test | ||
|
|
||
| import Graphs.SimpleGraphs: SimpleGraph, SimpleDiGraph | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these functions in any way connected to the JLD2 backend?
I think these should stay in the main package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, they don't look like they are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the dot format stuff back to the package. Note that the
savedotfunction is neither tested, documented, or exported.