Skip to content

Commit 914e50c

Browse files
committed
Add an extension to support Revise
1 parent 764ceec commit 914e50c

File tree

5 files changed

+105
-5
lines changed

5 files changed

+105
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
version:
2626
- 'nightly'
2727
- '1'
28-
- '1.9'
28+
- '1.10'
2929
os:
3030
- ubuntu-latest
3131
- macOS-latest
@@ -36,8 +36,6 @@ jobs:
3636
exclude:
3737
- os: macOS-latest
3838
arch: x86
39-
- os: windows-latest # Killing workers doesn't work on windows in 1.9
40-
version: '1.9'
4139

4240
steps:
4341
- uses: actions/checkout@v4

Project.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
77
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
88
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
99

10+
[weakdeps]
11+
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
12+
13+
[extensions]
14+
ReviseExt = "Revise"
15+
1016
[compat]
1117
Distributed = "1"
1218
Random = "1"
19+
Revise = "3.7.0"
1320
Serialization = "1"
1421
Sockets = "1"
15-
julia = "1.9"
22+
julia = "1.10"
1623

1724
[extras]
1825
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
@@ -21,4 +28,4 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2128
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2229

2330
[targets]
24-
test = ["LinearAlgebra", "Test", "LibSSH", "Distributed"]
31+
test = ["LinearAlgebra", "Test", "LibSSH", "Distributed", "Revise"]

docs/src/_changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This documents notable changes in DistributedNext.jl. The format is based on
1919
- [`other_workers()`](@ref) and [`other_procs()`](@ref) were implemented and
2020
exported ([#18]).
2121
- Implemented callback support for workers being added/removed etc ([#17]).
22+
- Added a package extension to support Revise.jl ([#17]).
2223

2324
## [v1.0.0] - 2024-12-02
2425

ext/ReviseExt.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module ReviseExt
2+
3+
import DistributedNext
4+
import DistributedNext: myid, workers, remotecall
5+
6+
import Revise
7+
8+
9+
struct DistributedNextWorker <: Revise.AbstractWorker
10+
id::Int
11+
end
12+
13+
function get_workers()
14+
map(DistributedNextWorker, workers())
15+
end
16+
17+
function Revise.remotecall_impl(f, worker::DistributedNextWorker, args...; kwargs...)
18+
remotecall(f, worker.id, args...; kwargs...)
19+
end
20+
21+
Revise.is_master_worker(::typeof(get_workers)) = myid() == 1
22+
Revise.is_master_worker(worker::DistributedNextWorker) = worker.id == 1
23+
24+
function __init__()
25+
Revise.register_workers_function(get_workers)
26+
DistributedNext.add_worker_started_callback(pid -> Revise.init_worker(DistributedNextWorker(pid));
27+
key="DistributedNext-integration")
28+
end
29+
30+
end

test/distributed_exec.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Revise
34
using DistributedNext, Random, Serialization, Sockets
45
import DistributedNext
56
import DistributedNext: launch, manage
@@ -2004,6 +2005,69 @@ end
20042005
@test exit_state == DistributedNext.WorkerState_exterminated
20052006
end
20062007

2008+
# This is a simplified copy of a test from Revise.jl's tests
2009+
@testset "Revise.jl integration" begin
2010+
function rm_precompile(pkgname::AbstractString)
2011+
filepath = Base.cache_file_entry(Base.PkgId(pkgname))
2012+
isa(filepath, Tuple) && (filepath = filepath[1]*filepath[2]) # Julia 1.3+
2013+
for depot in DEPOT_PATH
2014+
fullpath = joinpath(depot, filepath)
2015+
isfile(fullpath) && rm(fullpath)
2016+
end
2017+
end
2018+
2019+
pid = only(addprocs(1))
2020+
2021+
# Test that initialization succeeds by checking that Main.whichtt is defined
2022+
# on the worker, which is defined by Revise.init_worker().
2023+
@test timedwait(() ->remotecall_fetch(() -> hasproperty(Main, :whichtt), pid), 10) == :ok
2024+
2025+
tmpdir = mktempdir()
2026+
@everywhere push!(LOAD_PATH, $tmpdir) # Don't want to share this LOAD_PATH
2027+
2028+
# Create a fake package
2029+
module_file = joinpath(tmpdir, "ReviseDistributed", "src", "ReviseDistributed.jl")
2030+
mkpath(dirname(module_file))
2031+
write(module_file,
2032+
"""
2033+
module ReviseDistributed
2034+
2035+
f() = π
2036+
g(::Int) = 0
2037+
2038+
end
2039+
""")
2040+
2041+
# Check that we can use it
2042+
@everywhere using ReviseDistributed
2043+
for p in procs()
2044+
@test remotecall_fetch(ReviseDistributed.f, p) == π
2045+
@test remotecall_fetch(ReviseDistributed.g, p, 1) == 0
2046+
end
2047+
2048+
# Test changing and deleting methods
2049+
write(module_file,
2050+
"""
2051+
module ReviseDistributed
2052+
2053+
f() = 3.0
2054+
2055+
end
2056+
""")
2057+
Revise.revise()
2058+
for p in procs()
2059+
# We use timedwait() here because worker updates from Revise are asynchronous
2060+
@test timedwait(() -> remotecall_fetch(ReviseDistributed.f, p) == 3.0, 10) == :ok
2061+
2062+
@test_throws RemoteException remotecall_fetch(ReviseDistributed.g, p, 1)
2063+
end
2064+
2065+
rmprocs(workers())
2066+
rm_precompile("ReviseDistributed")
2067+
pop!(LOAD_PATH)
2068+
end
2069+
2070+
20072071
# Run topology tests last after removing all workers, since a given
20082072
# cluster at any time only supports a single topology.
20092073
if nprocs() > 1

0 commit comments

Comments
 (0)