Skip to content

Commit

Permalink
Merge pull request #16 from timholy/teh/dont_watch
Browse files Browse the repository at this point in the history
Add exclusion/silencing mechanisms and exclude GSL
  • Loading branch information
timholy authored Jul 4, 2017
2 parents 8cb8b19 + db15f49 commit 76e2ce5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
deps/silence.txt
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
sudo: required
os:
- linux
- osx
Expand Down
39 changes: 39 additions & 0 deletions src/Revise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export revise

const revision_queue = Set{String}() # file names that have changed since last revision

## For excluding packages from tracking by Revise
const dont_watch_pkgs = Set([:GSL])
const silence_pkgs = Set{Symbol}()
const depsdir = joinpath(dirname(@__DIR__), "deps")
const silencefile = Ref(joinpath(depsdir, "silence.txt")) # Ref so that tests don't clobber

## Structures to manipulate parsed files

# We will need to detect new function bodies, compare function bodies
Expand Down Expand Up @@ -400,6 +406,12 @@ function parse_module!(md::ModDict, ex::Expr, file::Symbol, mod::Module, path)
end

function watch_package(modsym::Symbol)
if modsym dont_watch_pkgs
if modsym silence_pkgs
warn("$modsym is excluded from watching by Revise. Use Revise.silence(\"$modsym\") to quiet this warning.")
end
return nothing
end
files = parse_pkg_files(modsym)
for file in files
@schedule revise_file_queued(file)
Expand Down Expand Up @@ -495,6 +507,27 @@ function track(mod::Module)
nothing
end

"""
Revise.silence(pkg)
Silence warnings about not tracking changes to package `pkg`. Some
packages (e.g., GSL) are excluded because they load so many files that
it burdens the file-watcher.
"""
function silence(pkg::Symbol)
push!(silence_pkgs, pkg)
if !isdir(depsdir)
mkpath(depsdir)
end
open(silencefile[], "w") do io
for p in silence_pkgs
println(io, p)
end
end
nothing
end
silence(pkg::AbstractString) = silence(Symbol(pkg))

## Utilities

_module_name(ex::Expr) = ex.args[2]
Expand Down Expand Up @@ -572,6 +605,12 @@ function steal_repl_backend(backend = Base.active_repl_backend)
end

function __init__()
if isfile(silencefile[])
pkgs = readlines(silencefile[])
for pkg in pkgs
push!(silence_pkgs, Symbol(pkg))
end
end
push!(Base.package_callbacks, watch_package)
mode = get(ENV, "JULIA_REVISE", "auto")
if mode == "auto"
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GSL
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,30 @@ end

pop!(LOAD_PATH)
end

@testset "Pkg exclusion" begin
if !(is_windows() && Int == Int32) # GSL install fails on 32-bit Windows
@eval import GSL
for k in keys(Revise.file2modules)
if contains(k, "GSL")
error("Should not track files in GSL")
end
end
# Ensure that silencing works
sfile = Revise.silencefile[] # remember the original
try
sfiletemp = tempname()
Revise.silencefile[] = sfiletemp
Revise.silence("GSL")
@test isfile(sfiletemp)
pkgs = readlines(sfiletemp)
@test contains(==, pkgs, "GSL")
rm(sfiletemp)
finally
Revise.silencefile[] = sfile
end
end
end
end

# These may cause warning messages about "not an existing file", but that's fine
Expand Down

0 comments on commit 76e2ce5

Please sign in to comment.