Skip to content

Commit e47b794

Browse files
authored
Merge pull request #921 from timholy/avi/simple-non-jl
remove the interface to support non .jl files
2 parents a335cf6 + 0ea7485 commit e47b794

File tree

12 files changed

+42
-83
lines changed

12 files changed

+42
-83
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Revise"
22
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
3-
version = "3.7.6"
3+
version = "3.8.0"
44

55
[deps]
66
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"

docs/src/dev_reference.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,3 @@ Revise.git_repo
152152
```@docs
153153
Revise.init_worker
154154
```
155-
156-
## Teaching Revise about non-julia source codes
157-
Revise can be made to work for transpilers from non-Julia languages to Julia with a little effort.
158-
For example, if you wrote a transpiler from C to Julia, you can define a `struct CFile`
159-
which overrides enough of the common `String` methods (`abspath`,`isabspath`, `joinpath`, `normpath`,`isfile`,`findfirst`, and `String`),
160-
it will be supported by Revise if you define a method like
161-
```julia
162-
function Revise.parse_source!(mod_exprs_sigs::Revise.ModuleExprsSigs, file::CFile, mod::Module; kwargs...)
163-
ex = # julia Expr returned from running transpiler
164-
Revise.process_source!(mod_exprs_sigs, ex, file, mod; kwargs...)
165-
end
166-
```

src/callbacks.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ Global variable, maps callback keys to user hooks.
3030
"""
3131
const user_callbacks_by_key = Dict{Any, Any}()
3232

33-
34-
3533
"""
3634
key = Revise.add_callback(f, files, modules=nothing; key=gensym())
3735

src/packagedef.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,13 @@ end
537537
init_watching(files) = init_watching(pkgdatas[NOPACKAGE], files)
538538

539539
"""
540-
revise_dir_queued(dirname)
540+
revise_dir_queued(dirname::AbstractString)
541541
542542
Wait for one or more of the files registered in `Revise.watched_files[dirname]` to be
543543
modified, and then queue the corresponding files on [`Revise.revision_queue`](@ref).
544544
This is generally called via a [`Revise.TaskThunk`](@ref).
545545
"""
546-
@noinline function revise_dir_queued(dirname)
546+
@noinline function revise_dir_queued(dirname::AbstractString)
547547
@assert isabspath(dirname)
548548
if !isdir(dirname)
549549
sleep(0.1) # in case git has done a delete/replace cycle
@@ -891,7 +891,7 @@ it defaults to `Main`.
891891
892892
If this produces many errors, check that you specified `mod` correctly.
893893
"""
894-
function track(mod::Module, file; mode=:sigs, kwargs...)
894+
function track(mod::Module, file::AbstractString; mode=:sigs, kwargs...)
895895
isfile(file) || error(file, " is not a file")
896896
# Determine whether we're already tracking this file
897897
id = Base.moduleroot(mod) == Main ? PkgId(mod, string(mod)) : PkgId(mod) # see #689 for `Main`
@@ -935,13 +935,13 @@ function track(mod::Module, file; mode=:sigs, kwargs...)
935935
return nothing
936936
end
937937

938-
function track(file; kwargs...)
938+
function track(file::AbstractString; kwargs...)
939939
startswith(file, juliadir) && error("use Revise.track(Base) or Revise.track(<stdlib module>)")
940940
track(Main, file; kwargs...)
941941
end
942942

943943
"""
944-
includet(filename)
944+
includet(filename::AbstractString)
945945
946946
Load `filename` and track future changes. `includet` is intended for quick "user scripts"; larger or more
947947
established projects are encouraged to put the code in one or more packages loaded with `using`
@@ -1001,7 +1001,7 @@ try fixing it with something like `push!(LOAD_PATH, "/path/to/my/private/repos")
10011001
they will not be automatically tracked.
10021002
(Call [`Revise.track`](@ref) manually on each file, if you've already `included`d all the code you need.)
10031003
"""
1004-
function includet(mod::Module, file)
1004+
function includet(mod::Module, file::AbstractString)
10051005
prev = Base.source_path(nothing)
10061006
file = if prev === nothing
10071007
abspath(file)
@@ -1033,7 +1033,7 @@ function includet(mod::Module, file)
10331033
end
10341034
return nothing
10351035
end
1036-
includet(file) = includet(Main, file)
1036+
includet(file::AbstractString) = includet(Main, file)
10371037

10381038
"""
10391039
Revise.silence(pkg)

src/parsing.jl

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if `filename` defines more module(s) then these will all have separate entries i
99
1010
If parsing `filename` fails, `nothing` is returned.
1111
"""
12-
parse_source(filename, mod::Module; kwargs...) =
12+
parse_source(filename::AbstractString, mod::Module; kwargs...) =
1313
parse_source!(ModuleExprsSigs(mod), filename, mod; kwargs...)
1414

1515
"""
@@ -26,28 +26,27 @@ function parse_source!(mod_exprs_sigs::ModuleExprsSigs, filename::AbstractString
2626
@warn "$filename is not a file, omitting from revision tracking"
2727
return nothing
2828
end
29-
parse_source!(mod_exprs_sigs, read(filename, String), filename, mod; kwargs...)
29+
return parse_source!(mod_exprs_sigs, read(filename, String), filename, mod; kwargs...)
3030
end
3131

32-
"""
33-
success = parse_source!(mod_exprs_sigs::ModuleExprsSigs, src::AbstractString, filename::AbstractString, mod::Module)
34-
35-
Parse a string `src` obtained by reading `file` as a single
36-
string. `pos` is the 1-based byte offset from which to begin parsing `src`.
37-
38-
See also [`Revise.parse_source`](@ref).
39-
"""
4032
function parse_source!(mod_exprs_sigs::ModuleExprsSigs, src::AbstractString, filename::AbstractString, mod::Module; kwargs...)
41-
startswith(src, "# REVISE: DO NOT PARSE") && return DoNotParse()
42-
ex = Base.parse_input_line(src; filename=filename)
43-
ex === nothing && return mod_exprs_sigs
44-
if isexpr(ex, :error) || isexpr(ex, :incomplete)
45-
eval(ex)
33+
if startswith(src, "# REVISE: DO NOT PARSE")
34+
return DoNotParse()
35+
end
36+
ex = Base.parse_input_line(src; filename)
37+
if ex === nothing
38+
return mod_exprs_sigs
39+
elseif ex isa Expr
40+
return process_ex!(mod_exprs_sigs, ex, filename, mod; kwargs...)
41+
else # literals
42+
return nothing
4643
end
47-
return process_source!(mod_exprs_sigs, ex, filename, mod; kwargs...)
4844
end
4945

50-
function process_source!(mod_exprs_sigs::ModuleExprsSigs, ex, filename, mod::Module; mode::Symbol=:sigs)
46+
function process_ex!(mod_exprs_sigs::ModuleExprsSigs, ex::Expr, filename::AbstractString, mod::Module; mode::Symbol=:sigs)
47+
if isexpr(ex, :error) || isexpr(ex, :incomplete)
48+
return eval(ex)
49+
end
5150
for (mod, ex) in ExprSplitter(mod, ex)
5251
if mode === :includet
5352
try

src/pkgs.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ end
390390

391391
# Much of this is adapted from base/loading.jl
392392

393-
function manifest_file(project_file)
393+
function manifest_file(project_file = Base.active_project())
394394
if project_file isa String && isfile(project_file)
395395
mfile = Base.project_file_manifest_path(project_file)
396396
if mfile isa String
@@ -399,7 +399,6 @@ function manifest_file(project_file)
399399
end
400400
return nothing
401401
end
402-
manifest_file() = manifest_file(Base.active_project())
403402

404403
function manifest_paths!(pkgpaths::Dict, manifest_file::String)
405404
d = if isdefined(Base, :get_deps) # `get_deps` is present in versions that support new manifest formats
@@ -427,7 +426,7 @@ end
427426
manifest_paths(manifest_file::String) =
428427
manifest_paths!(Dict{PkgId,String}(), manifest_file)
429428

430-
function watch_manifest(mfile)
429+
function watch_manifest(mfile::String)
431430
while true
432431
try
433432
wait_changed(mfile)

src/recipes.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414

1515
const vstring = "v$(VERSION.major).$(VERSION.minor)"
1616

17-
function inpath(path, dirs)
17+
function inpath(path::AbstractString, dirs::Vector{String})
1818
spath = splitpath(path)
1919
idx = findfirst(isequal(first(dirs)), spath)
2020
idx === nothing && return false
@@ -29,15 +29,15 @@ function inpath(path, dirs)
2929
return true
3030
end
3131

32-
function _track(id, modname; modified_files=revision_queue)
32+
function _track(id::PkgId, modname::Symbol; modified_files=revision_queue)
3333
haskey(pkgdatas, id) && return nothing # already tracked
3434
isbase = modname === :Base
3535
isstdlib = !isbase && modname stdlib_names
3636
if isbase || isstdlib
3737
# Test whether we know where to find the files
3838
if isbase
3939
srcdir = fixpath(joinpath(juliadir, "base"))
40-
dirs = ["base"]
40+
dirs = String["base"]
4141
else
4242
stdlibv = joinpath("stdlib", vstring, String(modname))
4343
srcdir = fixpath(joinpath(juliadir, stdlibv))
@@ -48,7 +48,7 @@ function _track(id, modname; modified_files=revision_queue)
4848
# This can happen for Pkg, since it's developed out-of-tree
4949
srcdir = joinpath(juliadir, "usr", "share", "julia", stdlibv) # omit fixpath deliberately
5050
end
51-
dirs = ["stdlib", String(modname)]
51+
dirs = String["stdlib", String(modname)]
5252
end
5353
if !isdir(srcdir)
5454
@error "unable to find path containing source for $modname, tracking is not possible"

src/relocatable_exprs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function Base.iterate(iter::LineSkippingIterator, i=0)
7373
return (iter.args[i], i)
7474
end
7575

76-
function skip_to_nonline(args, i)
76+
function skip_to_nonline(args::Vector{Any}, i::Int)
7777
while true
7878
i > length(args) && return i
7979
ex = args[i]

src/types.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,14 @@ Base.PkgId(pkgdata::PkgData) = PkgId(pkgdata.info)
145145
CodeTracking.basedir(pkgdata::PkgData) = basedir(pkgdata.info)
146146
CodeTracking.srcfiles(pkgdata::PkgData) = srcfiles(pkgdata.info)
147147

148-
is_same_file(a, b) = String(a) == String(b)
149-
150-
function fileindex(info, file)
148+
function fileindex(info::PkgData, file::AbstractString)
151149
for (i, f) in enumerate(srcfiles(info))
152-
is_same_file(f, file) && return i
150+
String(f) == String(file) && return i
153151
end
154152
return nothing
155153
end
156154

157-
function hasfile(info, file)
155+
function hasfile(info::PkgData, file::AbstractString)
158156
if isabspath(file)
159157
file = relpath(file, info)
160158
end
@@ -168,7 +166,7 @@ function fileinfo(pkgdata::PkgData, file::String)
168166
end
169167
fileinfo(pkgdata::PkgData, i::Int) = pkgdata.fileinfos[i]
170168

171-
function Base.push!(pkgdata::PkgData, pr::Pair{<:Any,FileInfo})
169+
function Base.push!(pkgdata::PkgData, pr::Pair{<:AbstractString,FileInfo})
172170
push!(srcfiles(pkgdata), pr.first)
173171
push!(pkgdata.fileinfos, pr.second)
174172
return pkgdata

src/utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
relpath_safe(path, startpath) = isempty(startpath) ? path : relpath(path, startpath)
1+
relpath_safe(path::AbstractString, startpath::AbstractString) = isempty(startpath) ? path : relpath(path, startpath)
22

33
function Base.relpath(filename::AbstractString, pkgdata::PkgData)
44
if isabspath(filename)
@@ -33,7 +33,7 @@ function unique_dirs(iter)
3333
return udirs
3434
end
3535

36-
function file_exists(filename)
36+
function file_exists(filename::AbstractString)
3737
filename = normpath(filename)
3838
isfile(filename) && return true
3939
alt = get(cache_file_key, filename, nothing)
@@ -87,7 +87,7 @@ function unwrap(ex::Expr)
8787
end
8888
unwrap(rex::RelocatableExpr) = RelocatableExpr(unwrap(rex.ex))
8989

90-
istrivial(a) = a === nothing || isa(a, LineNumberNode)
90+
istrivial(@nospecialize a) = a === nothing || isa(a, LineNumberNode)
9191

9292
function unwrap_where(ex::Expr)
9393
while isexpr(ex, :where)

0 commit comments

Comments
 (0)