Skip to content

Commit

Permalink
Updates for Julia 0.6 and 0.7 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Dec 2, 2017
1 parent d540c4a commit 8b3e8ab
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -2,8 +2,7 @@ language: julia
os:
- linux
julia:
- 0.4
- 0.5
- 0.6
- nightly
notifications:
email: false
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -6,8 +6,7 @@ Functionality to analyze the structure of Julia's METADATA repository.
[![Build Status](https://travis-ci.org/JuliaPackaging/MetadataTools.jl.svg?branch=master)](https://travis-ci.org/JuliaPackaging/MetadataTools.jl)
[![Coverage Status](https://coveralls.io/repos/JuliaPackaging/MetadataTools.jl/badge.svg?branch=master)](https://coveralls.io/r/JuliaPackaging/MetadataTools.jl?branch=master)

[![MetadataTools](http://pkg.julialang.org/badges/MetadataTools_0.4.svg)](http://pkg.julialang.org/?pkg=MetadataTools&ver=0.4)
[![MetadataTools](http://pkg.julialang.org/badges/MetadataTools_0.5.svg)](http://pkg.julialang.org/?pkg=MetadataTools)
[![MetadataTools](http://pkg.julialang.org/badges/MetadataTools_0.6.svg)](http://pkg.julialang.org/?pkg=MetadataTools)

**Installation**: `Pkg.add("MetadataTools")`

Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
@@ -1,2 +1,2 @@
julia 0.4
Compat 0.7.16
julia 0.6
Compat 0.30.0
22 changes: 11 additions & 11 deletions src/MetadataTools.jl
Expand Up @@ -21,10 +21,10 @@ using Compat
Represents a version of a package in METADATA.jl
"""
immutable PkgMetaVersion
struct PkgMetaVersion
ver::VersionNumber
sha::Compat.UTF8String
requires::Vector{Compat.UTF8String}
sha::String
requires::Vector{String}
end
function printer(io::IO, pmv::PkgMetaVersion)
print(io, " ", pmv.ver, ",", pmv.sha[1:6])
Expand All @@ -38,9 +38,9 @@ Base.show( io::IO, pmv::PkgMetaVersion) = printer(io,pmv)
Represents a packages entry in METADATA.jl
"""
immutable PkgMeta
name::Compat.UTF8String
url::Compat.UTF8String
struct PkgMeta
name::String
url::String
versions::Vector{PkgMetaVersion}
end
function printer(io::IO, pm::PkgMeta)
Expand Down Expand Up @@ -80,7 +80,7 @@ function get_pkg(pkg_name::AbstractString;

url_path = joinpath(pkg_path,"url")
!isfile(url_path) && error("Couldn't find url for $pkg_name (expected $url_path)")
url = chomp(readstring(url_path))
url = readchomp(url_path)

vers_path = joinpath(pkg_path,"versions")
!isdir(vers_path) &&
Expand All @@ -91,11 +91,11 @@ function get_pkg(pkg_name::AbstractString;
for dir in readdir(vers_path)
ver_num = convert(VersionNumber, dir)
ver_path = joinpath(vers_path, dir)
sha = strip(readstring(joinpath(ver_path,"sha1")))
sha = strip(read(joinpath(ver_path,"sha1"), String))
req_path = joinpath(ver_path,"requires")
reqs = Compat.UTF8String[]
reqs = String[]
if isfile(req_path)
req_file = map(strip,split(readstring(req_path),"\n"))
req_file = map(strip, split(read(req_path, String), "\n"))
for req in req_file
length(req) == 0 && continue
req[1] == '#' && continue
Expand All @@ -118,7 +118,7 @@ in the METADATA folder.
function get_all_pkg(; meta_path=Pkg.dir("METADATA"))
!isdir(meta_path) && error("Couldn't find METADATA folder at $meta_path")

pkgs = Dict{Compat.UTF8String,PkgMeta}()
pkgs = Dict{String,PkgMeta}()
for fname in readdir(meta_path)
# Skip files
!isdir(joinpath(meta_path, fname)) && continue
Expand Down
15 changes: 7 additions & 8 deletions src/pkg_graph.jl
Expand Up @@ -18,10 +18,10 @@ export make_dep_graph, get_pkg_dep_graph
A lightweight wrapper around a LightGraphs.jl representation of a
package dependency graph.
"""
type PkgGraph
mutable struct PkgGraph
adjlist::Vector{Vector{Int}}
pkgnames::Vector{Compat.UTF8String}
pkgname_idx::Dict{Compat.UTF8String,Int}
pkgnames::Vector{String}
pkgname_idx::Dict{String,Int}
end

"""
Expand Down Expand Up @@ -54,10 +54,9 @@ Given a Dict{UTF8String,PkgMeta} (e.g., from `get_all_pkg`), build a
directed graph with an edge from PkgA to PkgB iff PkgA directly requires
PkgB. Alternatively reverse the direction of the edges if `reverse` is true.
"""
function make_dep_graph(pkgs::Dict{Compat.UTF8String,PkgMeta}; reverse=false)
function make_dep_graph(pkgs::Dict{String,PkgMeta}; reverse=false)
pkgnames = collect(keys(pkgs))
pkgname_idx = Dict{Compat.UTF8String,Int}(
[(pkgname, i) for (i,pkgname) in enumerate(pkgnames)]) # TODO: Dict(pkgname=>i for ...)
pkgname_idx = Dict{String,Int}(pkgname => i for (i, pkgname) in enumerate(pkgnames))
numpkg = length(pkgnames)
adjlist = Vector{Int}[Vector{Int}() for pkgname in pkgnames]

Expand Down Expand Up @@ -139,8 +138,8 @@ function get_pkg_dep_graph(pkgname::AbstractString, pg::PkgGraph; depth=Inf)
end
end
# Build subgraph
new_pkgnames = Compat.UTF8String["" for i in 1:new_n]
new_pkgname_idx = Dict{Compat.UTF8String,Int}()
new_pkgnames = String["" for i in 1:new_n]
new_pkgname_idx = Dict{String,Int}()
new_adjlist = Vector{Int}[Vector{Int}() for i in 1:new_n]
for old_idx in 1:n
!visited[old_idx] && continue
Expand Down
2 changes: 1 addition & 1 deletion test/pkggraph.jl
@@ -1,4 +1,4 @@
using MetadataTools
pkgmeta = get_all_pkg()
pg = make_dep_graph(pkgmeta)
pkg_graph = get_pkg_dep_graph("Gadfly", pg)
pkg_graph = get_pkg_dep_graph("Gadfly", pg)

0 comments on commit 8b3e8ab

Please sign in to comment.