Movatterモバイル変換


[0]ホーム

URL:


GitHub

Introduction to Revise

Revise.jl may help you keep your Julia sessions running longer, reducing the need to restart when you make changes to code. With Revise, you can be in the middle of a session and then edit source code, update packages, switch git branches, and/or stash/unstash code; typically, the changes will be incorporated into the very next command you issue from the REPL. This can save you the overhead of restarting, loading packages, and waiting for code to JIT-compile.

Using Revise also improves your experience when using thedebuggers. Revise will keep track of changed locations of your methods in file, and ensure that the debugger displays the source code of what you're actually debugging.

Automatically loading Revise

Many users automatically load Revise on startup. On versions of Julia older than 1.5, this is slightly more involved than just addingusing Revise to.julia/config/startup.jl: seeUsing Revise by default for details.

Installation

You can obtain Revise using Julia's Pkg REPL-mode (hitting] as the first character of the command prompt):

(v1.0) pkg> add Revise

or withusing Pkg; Pkg.add("Revise").

Usage example

We'll make changes to Julia's "Example" package (a trivial package designed to illustrate the file and directory organization of typical packages). We have to "develop" it in order to make changes:

(v1.0) pkg> dev Example[...output related to installation...]

Now we load Revise (if we haven't already done so) and Example:

julia> using Revise        # importantly, this must come before `using Example`julia> using Examplejulia> hello("world")"Hello, world"

Now we're going to check that theExample module currently lacks a function namedf:

julia> Example.f()ERROR: UndefVarError: f not defined

But say we really wantf, so let's add it. You can either navigate to the source code (at.julia/dev/Example/src/Example.jl) in an editor manually, or you can use Julia to open it for you:

julia> edit(hello)   # opens Example.jl in the editor you have configured

Now, add a functionf() = π and save the file. Go back to the REPL (thesame REPL, don't restart Julia) and try this:

julia> Example.f()π = 3.1415926535897...

Voila! Even though we'd loaded Example before adding this function, Revise noticed the change and inserted it into our running session.

Warning

Revise's first revision has latency of several seconds–it's compiling all of its internal code, which includes a completeJulia interpreter and all of Revise's parse/diff/patch/cache machinery. After your first revision, future revisions will generally be fast enough that they will seem nearly instantaneous. (There are exceptions, but they occur only in specific circumstances, for example when Revise's own code getsinvalidated by your changes.)

Now suppose we realize we've made a horrible mistake: thatf method will mess up everything, because it's part of a more complicated dispatch process and incorrectly intercepts certainf calls. No problem, just deletef in your editor, save the file, and you're back to this:

julia> Example.f()ERROR: UndefVarError: f not defined

all without restarting Julia. While you can evaluatenew methods without Revise usinginline evaluation through your IDE, methoddeletion is just one example of a change that can only be made easily by Revise.

If you need more examples, seeRevise usage: a cookbook.

Other key features of Revise

Revise updates its internal paths when you change versions of a package. To try this yourself, first re-insert that definition off in thedev version ofExample and save the file. Now try toggling back and forth between thedev and released versions ofExample:

(v1.0) pkg> free Example   # switch to the released version of Examplejulia> Example.f()ERROR: UndefVarError: f not defined(v1.0) pkg> dev Examplejulia> Example.f()π = 3.1415926535897...

Revise is not tied to any particular editor. (TheEDITOR or JULIA_EDITOR environment variables can be used to specify your preference for which editor gets launched by Julia'sedit function.)

Warn

Some editors (likevim) may requireconfiguration to function properly.

If you don't want to have to remember to sayusing Revise each time you start Julia, seeUsing Revise by default.

What Revise can track

Revise is fairly ambitious: if all is working, subject to a fewLimitations you should be able to track changes to

The last one requires that you clone Julia and build it yourself from source.

Secrets of Revise "wizards"

Revise can assist with methodologies liketest-driven development. While it's often desirable to write the test first, sometimes when fixing a bug it's very difficult to write a good test until you understand the bug better. Often that means basically fixing the bug before your write the test. With Revise, you can

all without restarting your Julia session.

Other Revise workflows

Revise can be used to perform work when files update. For example, let's say you want to regenerate a set of web pages whenever your code changes. Suppose you've placed your Julia code in a package calledMyWebCode, and the pages depend on "file.js" and all files in the "assets/" directory; then

entr(["file.js", "assets"], [MyWebCode]) do    build_webpages(args...)end

will executebuild_webpages(args...) whenever you save updates to the listed files orMyWebCode.

If you want to regenerate the web page as soon as any change is detected, not only inMyWebCode but also in any package tracked by Revise, you can provide theall keyword argument toentr:

entr(["file.js", "assets"]; all=true) do    build_webpages(args...)end

Taking advantage of Revise in other packages

To make it easier for other packages to benefit from Revise without needing to add it as a dependency or understand Revise's internals, Revise interfaces withCodeTracking, which is a small package acting as Revise's "query" interface.

What else do I need to know?

Except in cases of problems (see below), that's it! Revise is a tool that runs in the background, and when all is well it should be essentially invisible, except that you don't have to restart Julia so often.

Revise can also be used as a "library" by developers who want to add other new capabilities to Julia; the sectionsHow Revise works andDeveloper reference are particularly relevant for them.

If Revise doesn't work as expected

If Revise isn't working for you, here are some steps to try:

If you still encounter problems, pleasefile an issue. Especially if you think Revise is making mistakes in adding or deleting methods, please see the page onDebugging Revise for information about how to attach logs to your bug report.

Settings


This document was generated withDocumenter.jl version 1.10.1 onTuesday 27 May 2025. Using Julia version 1.11.5.


[8]ページ先頭

©2009-2025 Movatter.jp