### Basic Revise.jl Usage Example Source: https://github.com/timholy/revise.jl/blob/master/docs/src/index.md This example demonstrates the core functionality of Revise.jl. It involves developing a sample package, loading Revise and the package, defining a function, and observing how changes to the function in the editor are reflected in the REPL without restarting Julia. ```julia (v1.0) pkg> dev Example ``` ```julia julia> using Revise julia> using Example julia> hello("world") "Hello, world" ``` ```julia julia> Example.f() ERROR: UndefVarError: f not defined ``` ```julia julia> edit(hello) # opens Example.jl in the editor you have configured ``` ```julia julia> Example.f() π = 3.1415926535897... ``` ```julia julia> Example.f() ERROR: UndefVarError: f not defined ``` -------------------------------- ### Install Revise.jl Package Source: https://github.com/timholy/revise.jl/blob/master/docs/src/index.md This snippet shows how to install the Revise.jl package using Julia's Pkg REPL mode or programmatically. It's a prerequisite for using Revise's live code updating capabilities. ```julia (v1.0) pkg> add Revise ``` ```julia using Pkg Pkg.add("Revise") ``` -------------------------------- ### Define a Simple Function in a Julia Package Source: https://github.com/timholy/revise.jl/blob/master/docs/src/cookbook.md This snippet shows how to define a simple function `greet` within the 'MyPkg' Julia module. The function, when called, prints the string "Hello World!". This is a basic example of adding functionality to a package, which can then be revised live using Revise.jl. ```julia module MyPkg greet() = print("Hello World!") end # module ``` -------------------------------- ### Create Revise Configuration File (Unix Shell) Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md This Unix shell command creates the `~/.julia/config/` directory if it doesn't exist and appends the `using Revise` command to the `startup.jl` file. This ensures Revise is loaded automatically every time Julia starts. ```bash mkdir -p ~/.julia/config/ && echo "using Revise" >> ~/.julia/config/startup.jl ``` -------------------------------- ### Function Definition for Revise.jl Example Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md A straightforward Julia function definition `floatwins` that takes an `AbstractFloat` and an `Integer` as arguments and returns the `AbstractFloat`. This is used as a simple example to demonstrate lowered code analysis in Revise.jl. ```julia floatwins(x::AbstractFloat, y::Integer) = x ``` -------------------------------- ### Revise.jl Handling Package Version Changes Source: https://github.com/timholy/revise.jl/blob/master/docs/src/index.md This example illustrates how Revise.jl manages changes when toggling between development and released versions of a package. It shows how Revise correctly reflects the presence or absence of a function based on the active package version. ```julia (v1.0) pkg> free Example # switch to the released version of Example ``` ```julia julia> Example.f() ERROR: UndefVarError: f not defined ``` ```julia (v1.0) pkg> dev Example ``` ```julia julia> Example.f() π = 3.1415926535897... ``` -------------------------------- ### Load Revise and a Custom Package in Julia Source: https://github.com/timholy/revise.jl/blob/master/docs/src/cookbook.md This snippet illustrates the correct order for loading Revise.jl and a custom package ('MyPkg') within a Julia session to enable live code reloading. 'using Revise' must be called *before* loading any packages that you intend to modify. The example shows successful precompilation of 'MyPkg', indicating it's ready to be used and revised. ```julia julia> using Revise # you must do this before loading any revisable packages julia> using MyPkg [Info: Precompiling MyPkg [102b5b08-597c-4d40-b98a-e9249f4d01f4] ``` -------------------------------- ### Define Items Module in Julia Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md Defines a Julia module named 'Items' with functions to print items and include helper functions for indentation. This serves as an example for Revise.jl. ```julia __precompile__(false) module Items include("indents.jl") function print_item(io::IO, item, ntimes::Integer=1, pre::String=indent(item)) print(io, pre) for i = 1:ntimes print(io, item) end end end ``` -------------------------------- ### Example of Code to Avoid Interpreting in Julia Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md This Julia code snippet `init_c_library()` represents a function call that should not be interpreted by Revise.jl due to potential side effects, such as crashing if called twice. Revise.jl skips such blocks during signature computation. ```julia init_c_library() # library crashes if we call this twice ``` -------------------------------- ### Configuring Revise.jl Behavior with Global Variables Source: https://context7.com/timholy/revise.jl/llms.txt This section covers essential configuration variables for Revise.jl, such as enabling/disabling revisions (`Revise.active`), controlling polling for network filesystems (`Revise.polling_files`), and tracking of Main includes (`Revise.tracking_Main_includes`). It also shows how to check the file watching mode and access core tracking data like `Revise.pkgdatas` and `Revise.watched_files`. An example demonstrates temporarily disabling Revise during bulk operations. ```julia # Disable/enable Revise julia> Revise.active[] = false # Stop processing revisions julia> Revise.active[] = true # Resume # Enable polling for network filesystems julia> Revise.polling_files[] = true # Enable tracking of Main includes (default: false) julia> Revise.tracking_Main_includes[] = true # Check file watching mode julia> Revise.watching_files # true on FreeBSD, false elsewhere # Access core tracking data julia> Revise.pkgdatas # Package tracking data julia> Revise.watched_files # Directory watch list julia> Revise.revision_queue # Pending revisions # Example: Temporarily disable Revise during bulk operations julia> original = Revise.active[] julia> Revise.active[] = false julia> # ... perform bulk code changes ... julia> Revise.active[] = original ``` -------------------------------- ### Safe Revise Loading with Error Handling (Julia) Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md This Julia code snippet attempts to load Revise, but includes error handling. If Revise fails to initialize, it logs a warning with the error details and backtrace, preventing startup failure. This is recommended for environments where Revise might not always be available or compatible. ```julia try using Revise catch e @warn "Error initializing Revise" exception=(e, catch_backtrace()) end ``` -------------------------------- ### Automate Revise Initialization in IJulia (Julia) Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md This Julia code configures Revise to automatically launch within IJulia sessions by adding it to the `startup_ijulia.jl` file. It uses `@eval` to ensure Revise is properly integrated into the IJulia environment and includes error handling. ```julia try @eval using Revise catch e @warn "Error initializing Revise" exception=(e, catch_backtrace()) end ``` -------------------------------- ### Create IJulia Revise Configuration (Unix Shell) Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md This Unix shell command creates the `~/.julia/config/` directory and appends the Revise initialization code to `startup_ijulia.jl`. This ensures Revise is automatically loaded when using IJulia. ```bash mkdir -p ~/.julia/config/ && tee -a ~/.julia/config/startup_ijulia.jl << END try @eval using Revise catch e @warn "Error initializing Revise" exception=(e, catch_backtrace()) end END ``` -------------------------------- ### Create a New Julia Package with PkgTemplates.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/cookbook.md This snippet demonstrates how to create a new Julia package named 'MyPkg' using the PkgTemplates.jl library. It initializes a template and then applies it to generate the package structure, including Project.toml and the main module file. The process involves setting up a template object with desired configurations and calling it with the package name. The output shows the file paths where the new package is generated. ```julia julia> using PkgTemplates julia> t = Template() Template: → User: timholy → Host: github.com → License: MIT (Tim Holy 2019) → Package directory: ~/.julia/dev → Minimum Julia version: v1.0 → SSH remote: No → Add packages to main environment: Yes → Commit Manifest.toml: No → Plugins: None julia> t("MyPkg") Generating project MyPkg: /home/tim/.julia/dev/MyPkg/Project.toml /home/tim/.julia/dev/MyPkg/src/MyPkg.jl [lots more output suppressed] ``` -------------------------------- ### Revise.jl Package Loading Functions Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md References functions used for loading and initializing package watching within Revise.jl. These include watching a package, parsing its files, and setting up initial watching mechanisms. ```julia Revise.watch_package Revise.parse_pkg_files Revise.init_watching ``` -------------------------------- ### Re-evaluating Top-Level Code for Signatures in Julia Source: https://github.com/timholy/revise.jl/blob/master/NEWS.md Revise 2.0 re-evaluates top-level code to extract method signatures, allowing it to correctly identify and manage methods defined within constructs like `@eval` blocks. This enables Revise to accurately delete obsolete methods, as demonstrated in the example. ```julia for T in (Float16, Float32, Float32) @eval foo(::Type{$T}) = 1 end ``` -------------------------------- ### Revise.jl Revision and Diffing Functions Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md Highlights the primary entry point for applying changes, `revise`, and a function for immediately revising a file. These are core to Revise.jl's functionality of evaluating changes and computing differences. ```julia Revise.revise_file_now ``` -------------------------------- ### Enable Revise by Default in Julia Startup Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md This snippet configures Julia to automatically load Revise on startup by adding `using Revise` to the `startup.jl` file. It's suitable for users who want Revise available in every session. A slight startup latency is expected. ```julia using Revise ``` -------------------------------- ### Add Package to Environment using Pkg REPL Source: https://github.com/timholy/revise.jl/blob/master/docs/src/cookbook.md This snippet shows how to add a locally developed package ('MyPkg') to the current Julia environment using the Pkg REPL. After entering the Pkg REPL by typing ']', the 'dev' command is used, which automatically looks for the package in the configured development directories (like ~/.julia/dev). This makes the package available for loading in the current Julia session. ```julia () pkg> dev MyPkg # the dev command will look in the ~/.julia/dev folder automatically ``` -------------------------------- ### Access Package File Information with Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md Shows how to access the file information stored within the PkgData object provided by Revise.jl. This includes the base directory and a list of source files. ```julia pkgdata.info ``` -------------------------------- ### Include and Track a Julia Source File with includet Source: https://github.com/timholy/revise.jl/blob/master/docs/src/cookbook.md This snippet shows how to use the `includet` function from Revise.jl to load and track changes in a single Julia source file. It covers defining a function in a file, including it, and then observing how modifications to the file are reflected in the active Julia session without restarting. ```julia mygreeting() = "Hello, world!" ``` ```julia julia> using Revise julia> includet("/tmp/mygreet.jl") julia> mygreeting() "Hello, world!" # Modify mygreeting() in the editor to: # mygreeting() = "Hello, revised world!" julia> mygreeting() "Hello, revised world!" ``` -------------------------------- ### Generate and Dev a Julia Package with Pkg Source: https://github.com/timholy/revise.jl/blob/master/docs/src/cookbook.md This snippet demonstrates how to generate a new Julia package named 'MyPkg' using the Pkg manager's 'generate' command and then add it to the development directory using the 'dev' command. This process sets up the basic structure for a new package. ```julia julia> using Revise, Pkg julia> cd(Pkg.devdir()) # take us to the standard "development directory" (v1.2) pkg> generate MyPkg Generating project MyPkg: MyPkg/Project.toml MyPkg/src/MyPkg.jl (v1.2) pkg> dev MyPkg [ Info: resolving package identifier `MyPkg` as a directory at `~/.julia/dev/MyPkg`. ... ``` -------------------------------- ### Debugging Code Revisions with Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/debugging.md This snippet demonstrates the core functionality of Revise.jl for debugging. It shows how to initialize a debug logger, include a test file, trigger code changes by replacing the file, and observe the resulting logs which detail method deletions and evaluations. It highlights how Revise tracks changes in code and line numbering. ```julia-repl julia> rlogger = Revise.debug_logger(); shell> cp revisetest.jl /tmp/ julia> includet("/tmp/revisetest.jl") julia> ReviseTest.cube(3) 81 shell> cp revisetest_revised.jl /tmp/revisetest.jl julia> ReviseTest.cube(3) 27 julia> rlogger.logs 9-element Vector{Revise.LogRecord}: Revise DeleteMethod: cube(::Any) Revise DeleteMethod: mult3(::Any) Revise DeleteMethod: mult4(::Any) Revise Eval: #= /tmp/revisetest.jl:7 =# Revise Eval: #= /tmp/revisetest.jl:9 =# Revise LineOffset Revise Eval: #= /tmp/revisetest.jl:14 =# Revise LineOffset Revise LineOffset ``` -------------------------------- ### Configure Default Revise Logging Source: https://github.com/timholy/revise.jl/blob/master/docs/src/debugging.md Enables Revise's debug logging by default by adding configuration lines to the Julia startup file (`~/.julia/config/startup.jl`). This ensures that Revise's actions are logged automatically during every Julia session, simplifying the process of capturing logs when issues arise. ```julia # Turn on logging Revise.debug_logger() ``` -------------------------------- ### View Method Signatures for Indent Function Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md Displays the detailed mapping of expressions to method signatures for the 'indent' function in 'indents.jl', as managed by Revise.jl. This shows the types of arguments the function expects. ```julia pkgdata.fileinfos[2].modexsigs[Items] ``` -------------------------------- ### Troubleshooting 'No space left on device' on Linux Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md Addresses the 'no space left on device (ENOSPC)' error in Revise.jl on Linux, which occurs when filesystem limits for watched files are reached. It suggests increasing `fs.inotify.max_user_watches` and other related parameters. ```shell # Check current inotify limits sysctl fs.inotify # Recommended minimum for Revise # fs.inotify.max_user_watches >= 65536 # Example of increasing a limit (requires sudo) sudo sysctl fs.inotify.max_user_instances=2048 # To make changes permanent, consult system documentation (e.g., SUSE KB) ``` -------------------------------- ### Revise.jl Callback Management Functions Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md Provides documentation for functions that manage user-defined callbacks for file revisions. These are used in conjunction with the `entr` implementation but can be utilized more broadly. ```julia Revise.add_callback Revise.remove_callback ``` -------------------------------- ### Open Package File with Julia's edit Function Source: https://github.com/timholy/revise.jl/blob/master/docs/src/cookbook.md This snippet demonstrates how to use Julia's built-in `edit` function to open the source file of a loaded package ('MyPkg') in a text editor. This is useful for making modifications to the package code. Note that this might require configuring the EDITOR environment variable in your system. ```julia julia> edit(pathof(MyPkg)) ``` -------------------------------- ### Tracking File Changes with Diff Source: https://github.com/timholy/revise.jl/blob/master/docs/src/debugging.md This snippet suggests a manual method for tracking code changes, particularly useful for bug reporting. It involves creating copies of a file at different stages of editing and then using the `diff` command to generate a compact summary of the differences between versions. This aids in clearly communicating code modifications. ```shell cp editedfile.jl /tmp/version1.jl cp editedfile.jl /tmp/version2.jl diff version1.jl version2.jl ``` -------------------------------- ### Explicit Method Definitions in Julia Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md This Julia code shows the explicit definition of methods that are equivalent to the code generated by the `@eval` loop. It explicitly defines `sizefloat` for `Float16`, `Float32`, and `Float64`, illustrating the outcome of the loop-based generation. ```julia sizefloat(x::Float16) = 2 sizefloat(x::Float32) = 4 sizefloat(x::Float64) = 8 ``` -------------------------------- ### Inspect Revise.jl Directory Paths Source: https://github.com/timholy/revise.jl/blob/master/docs/src/debugging.md This diagnostic step involves examining the paths Revise.jl uses to locate Julia's core directories. `Revise.basesrccache` should point to the `base.cache` file, and `Revise.juliadir` should point to the directory containing the `base/` module. ```julia println(Revise.basesrccache) println(Revise.juliadir) ``` -------------------------------- ### Inspect Package Data with Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md Demonstrates how to use Revise.jl in a Julia REPL to obtain and inspect the package data (PkgData) for a loaded module. This includes its package ID and file information. ```julia id = Base.PkgId(Items) pkgdata = Revise.pkgdatas[id] ``` -------------------------------- ### Examine Specific File Information in Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md Retrieves and displays detailed information about a specific source file (indents.jl) within the package data managed by Revise.jl, including parsed expressions and signatures. ```julia pkgdata.fileinfos[2] ``` -------------------------------- ### Include and Auto-Update Files with `includet()` in Julia Source: https://context7.com/timholy/revise.jl/llms.txt The `includet()` function loads a Julia source file and monitors it for changes, automatically reloading modified methods. Unlike `include`, it provides live updates. By default, it focuses on method definitions to prevent unintended side effects from data assignments. ```julia # Include and track a file julia> using Revise julia> includet("mycode.jl") # Now edit mycode.jl in your editor - changes will be automatically loaded # Track a file in a specific module context julia> module MyMod end julia> includet(MyMod, "code.jl") # Example file content (mycode.jl): # function greet(name) # println("Hello, $name!") # end # # data = [1, 2, 3] # This won't be re-evaluated on changes by default # After editing greet() in mycode.jl, it's immediately available: julia> greet("World") Hello, World! ``` -------------------------------- ### Automatic Tracking of Included Files with JULIA_REVISE_INCLUDE Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md Enable automatic tracking of files loaded via `include` by setting the JULIA_REVISE_INCLUDE environment variable to '1'. This is generally not recommended; prefer `includet`. ```shell export JULIA_REVISE_INCLUDE=1 ``` -------------------------------- ### Verbose Logging of Code Revisions in Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/debugging.md This snippet displays the verbose output from Revise.jl's debug logger. It provides detailed information about each logged event, including the type of action (DeleteMethod, Eval, LineOffset), the source file and line number, and specific details about the method or code being evaluated. This is useful for in-depth analysis of code revisions. ```julia-repl julia> show(IOContext(stdout, :verbose=>true), MIME("text/plain"), rlogger.logs) 9-element Vector{Revise.LogRecord}: Revise.LogRecord(Debug, DeleteMethod, Action, Revise_4ac0f476, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 296, (time=1.753703251773368e9, deltainfo=(Tuple{typeof(Main.ReviseTest.cube), Any}, cube(::Any)))) Revise.LogRecord(Debug, DeleteMethod, Action, Revise_4ac0f476, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 296, (time=1.753703251782686e9, deltainfo=(Tuple{typeof(Main.ReviseTest.Internal.mult3), Any}, mult3(::Any)))) Revise.LogRecord(Debug, DeleteMethod, Action, Revise_4ac0f476, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 296, (time=1.753703251782706e9, deltainfo=(Tuple{typeof(Main.ReviseTest.Internal.mult4), Any}, mult4(::Any)))) Revise.LogRecord(Debug, Eval, Action, Revise_9147188b, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 347, (time=1.753703251786138e9, deltainfo=(Main.ReviseTest, quote #= /tmp/revisetest.jl:7 =# cube(x) = begin #= /tmp/revisetest.jl:7 =# x ^ 3 end end))) Revise.LogRecord(Debug, Eval, Action, Revise_9147188b, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 347, (time=1.75370325178672e9, deltainfo=(Main.ReviseTest, quote #= /tmp/revisetest.jl:9 =# fourth(x) = begin #= /tmp/revisetest.jl:9 =# x ^ 4 end end))) Revise.LogRecord(Debug, LineOffset, Action, Revise_fcadbd44, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 369, (time=1.753703251787128e9, deltainfo=(Pair{Union{Nothing, Core.MethodTable}, Type}[nothing => Tuple{typeof(Main.ReviseTest.Internal.mult2), Any}], :(#= /tmp/revisetest.jl:11 =#) => :(#= /tmp/revisetest.jl:13 =#)))) Revise.LogRecord(Debug, Eval, Action, Revise_9147188b, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 347, (time=1.753703251793889e9, deltainfo=(Main.ReviseTest.Internal, quote #= /tmp/revisetest.jl:14 =# mult3(x) = begin #= /tmp/revisetest.jl:14 =# 3x end end))) Revise.LogRecord(Debug, LineOffset, Action, Revise_fcadbd44, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 369, (time=1.753703251795383e9, deltainfo=(Pair{Union{Nothing, Core.MethodTable}, Type}[nothing => Tuple{typeof(Main.ReviseTest.Internal.unchanged), Any}], :(#= /tmp/revisetest.jl:18 =#) => :(#= /tmp/revisetest.jl:19 =#)))) Revise.LogRecord(Debug, LineOffset, Action, Revise_fcadbd44, "/home/tim/.julia/dev/Revise/src/packagedef.jl", 369, (time=1.753703251795399e9, deltainfo=(Pair{Union{Nothing, Core.MethodTable}, Type}[nothing => Tuple{typeof(Main.ReviseTest.Internal.unchanged2), Any}], :(#= /tmp/revisetest.jl:20 =#) => :(#= /tmp/revisetest.jl:21 =#)))) ``` -------------------------------- ### Manual Function Redefinition in Julia Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md Demonstrates how to manually redefine a function in Julia using the `@eval` macro. This process is what Revise.jl automates. It shows how to change the behavior of `convert(Float64, π)` and the resulting output. ```julia julia> convert(Float64, π) 3.141592653589793 julia> # That's too hard, let's make life easier for students julia> @eval Base convert(::Type{Float64}, x::Irrational{:π}) = 3.0 convert (generic function with 714 methods) julia> convert(Float64, π) 3.0 ``` -------------------------------- ### User Callbacks Framework in Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/NEWS.md Revise 2.7 introduced a framework for user-defined callbacks. This allows users to hook into Revise's revision process to perform custom actions when specific events occur, enhancing the flexibility and extensibility of code revision. ```julia # Framework for user callbacks is available in Revise 2.7+ ``` -------------------------------- ### Lowered Code Representation of a Julia Method Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md This Julia code illustrates the approximate lowered code representation of a simple function definition `floatwins(x::AbstractFloat, y::Integer) = x`. It showcases the `CodeInfo` structure, including method expression, type computations, and the core logic of the function. ```julia CodeInfo( │ $(Expr(:method, :floatwins)) │ %2 = Core.Typeof(floatwins) │ %3 = Core.svec(%2, AbstractFloat, Integer) │ %4 = Core.svec() │ %5 = Core.svec(%3, %4) │ $(Expr(:method, :floatwins, :(%5), CodeInfo(quote return x end))) └── return floatwins ) ``` -------------------------------- ### Revise.jl Conceptual Diff and Patch Loop Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md Illustrates the core logic of Revise.jl's `revise()` function conceptually. It outlines the process of identifying deleted methods (in `oldexprs` but not `newexprs`) and new or modified methods (in `newexprs` but not `oldexprs`) for evaluation. ```julia for def in setdiff(oldexprs, newexprs) # `def` is an expression that defines a method. # It was in `oldexprs`, but is no longer present in `newexprs`--delete the method. delete_methods_corresponding_to_defexpr(mod, def) end for def in setdiff(newexprs, oldexprs) # `def` is an expression for a new or modified method. Instantiate it. Core.eval(mod, def) end ``` -------------------------------- ### Generate and Modify Julia Package with Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/limitations.md Demonstrates generating a Julia package, defining types and functions, and then updating the type definition and alias using Revise.jl without restarting the session. This workaround allows for modification of type definitions and constant reassignment. ```julia julia> using Pkg, Revise julia> Pkg.generate("MyPkg") Generating project MyPkg: MyPkg/Project.toml MyPkg/src/MyPkg.jl Dict{String, Base.UUID} with 1 entry: "MyPkg" => UUID("69940cda-0c72-4a1a-ae0b-fd3109336fe8") julia> cd("MyPkg") julia> write("src/MyPkg.jl",""" module MyPkg export FooStruct, processFoo abstract type AbstractFooStruct end struct FooStruct1 <: AbstractFooStruct bar::Int end FooStruct = FooStruct1 function processFoo(foo::AbstractFooStruct) @info foo.bar end end """) 230 julia> Pkg.activate(".") Activating project at `~/blah/MyPkg` julia> using MyPkg No Changes to `~/blah/MyPkg/Project.toml` No Changes to `~/blah/MyPkg/Manifest.toml` Precompiling MyPkg 1 dependency successfully precompiled in 2 seconds julia> processFoo(FooStruct(1)) [ Info: 1 julia> write("src/MyPkg.jl",""" module MyPkg export FooStruct, processFoo abstract type AbstractFooStruct end struct FooStruct2 <: AbstractFooStruct # change version nuumber bar::Float64 # change type of the field end FooStruct = FooStruct2 # update alias reference function processFoo(foo::AbstractFooStruct) @info foo.bar end end ") 234 julia> FooStruct # make sure FooStruct refers to FooStruct2 MyPkg.FooStruct2 julia> processFoo(FooStruct(3.5)) [ Info: 3.5 ``` -------------------------------- ### Revise.jl REPL Interruption Workaround Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md Describes Revise.jl's mechanism for handling REPL interruptions (Ctrl-C) that might stop background tasks. `throwto_repl` is a workaround to maintain Revise's file watching capabilities. ```julia Revise.throwto_repl ``` -------------------------------- ### Revise.jl Error Handling Functions Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md Documents functions for handling errors, specifically `trim_toplevel!`, which is part of Revise.jl's error management strategy. ```julia Revise.trim_toplevel! ``` -------------------------------- ### Verify Base Source Cache Path in Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/debugging.md This diagnostic step checks if Revise.jl can correctly locate the `base.cache` file, which is crucial for accessing Julia's `Base` module source code. It compares the expected path stored in `Revise.basesrccache` with the actual location of the file. ```julia isfile(Revise.basesrccache) ``` -------------------------------- ### Automate Workflows with Callbacks using `entr()` Source: https://context7.com/timholy/revise.jl/llms.txt The `entr()` function executes a specified callback function whenever tracked files or modules change. This is ideal for automating tasks like running tests, rebuilding documentation, or regenerating assets in response to code modifications. It supports watching multiple files and postponing initial execution. ```julia # Run tests whenever MyPackage changes julia> using Revise julia> using MyPackage, Test julia> entr(["myfile.txt"], [MyPackage]) do println("Files changed, running tests...") runtests() end # Watch multiple files and run a build process julia> entr(["config.json", "assets/style.css"]) do println("Rebuilding...") build_project() end # Watch all Revise-tracked files julia> entr(String[]; all=true) do println("Any tracked file changed!") run_validation() end # Start with postponed execution (don't run immediately) julia> entr(["data.csv"], postpone=true) do process_data() end ``` -------------------------------- ### Revise.jl Module and Path Functions Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md References functions related to managing modules and their associated file paths within Revise.jl. This is crucial for tracking code across different modules and directories. ```julia Revise.modulefiles ``` -------------------------------- ### Revise.jl Directory and File Monitoring Functions Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md Details functions responsible for monitoring directories and files for revisions. These functions are designed to be run asynchronously and recursively schedule revisions upon detecting changes. ```julia Revise.revise_dir_queued Revise.revise_file_queued ``` -------------------------------- ### Call Modified Function after Revise Source: https://github.com/timholy/revise.jl/blob/master/docs/src/cookbook.md This snippet shows how to call the `greet` function from the 'MyPkg' package after it has been defined and potentially modified. When using Revise.jl, changes made to the `MyPkg.jl` file should be reflected immediately upon calling the function, without needing to restart the Julia session. ```julia julia> MyPkg.greet() Hello World! ``` -------------------------------- ### Initialize Revise Debug Logger Source: https://github.com/timholy/revise.jl/blob/master/docs/src/debugging.md Initializes the Revise debug logger to capture log records. This logger object is used to retrieve detailed information about Revise's internal operations, which is helpful for debugging. It returns a `ReviseLogger` instance that stores log messages. ```jldoctest julia> rlogger = Revise.debug_logger() Revise.ReviseLogger(Revise.LogRecord[], Debug) ``` -------------------------------- ### Switching to Permanent Type Name in Julia with Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/limitations.md Illustrates the process of switching from a temporary alias to a permanent type name within a Julia session using Revise.jl. This final step, after development converges, requires a session restart to properly handle constant global variables. ```julia julia> isconst(MyPkg, :FooStruct) true julia> write("src/MyPkg.jl",""" module MyPkg export FooStruct, processFoo abstract type AbstractFooStruct end # this could be removed struct FooStruct <: AbstractFooStruct # change to just FooStruct bar::Float64 end function processFoo(foo::AbstractFooStruct) # consider changing to FooStruct @info foo.bar end end ") julia> run(Base.julia_cmd()) # start a new Julia session, alternatively exit() and restart julia julia> using Pkg, Revise # NEW Julia Session julia> Pkg.activate(".") Activating project at `~/blah/MyPkg` julia> using MyPkg Precompiling MyPkg 1 dependency successfully precompiled in 2 seconds julia> isconst(MyPkg, :FooStruct) true ``` -------------------------------- ### Revise.jl Distributed Computing Initialization Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md References the function used to initialize Revise.jl on worker processes in a distributed computing environment. This is essential for ensuring Revise functionality across multiple Julia processes. ```julia Revise.init_worker ``` -------------------------------- ### Manual Revision Control with JULIA_REVISE Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md Control when Revise.jl updates code by setting the JULIA_REVISE environment variable. When not set to 'auto', Revise requires manual calls to `revise()`. ```shell export JULIA_REVISE= ``` -------------------------------- ### Track Julia Libraries and Files with `Revise.track()` Source: https://context7.com/timholy/revise.jl/llms.txt Use `Revise.track()` to monitor changes in Julia's Base library, standard libraries, Core.Compiler, or specific modules and files. This is essential for code not automatically tracked through package loading, ensuring modifications are incorporated. ```julia # Track Julia's Base library julia> using Revise julia> Revise.track(Base) # Track a standard library julia> using Unicode julia> Revise.track(Unicode) # Track Core.Compiler julia> Revise.track(Core.Compiler) # Track a specific file with a module context julia> Revise.track(Main, "/path/to/myfile.jl") ``` -------------------------------- ### Revise.jl Git Integration Functions Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md Lists functions related to Revise.jl's integration with Git for source code management. These functions help in identifying Git-related sources and files within a repository. ```julia Revise.git_source Revise.git_files Revise.git_repo ``` -------------------------------- ### Configure Revise Mode for Method Tracking (Julia) Source: https://github.com/timholy/revise.jl/blob/master/docs/src/config.md This demonstrates how to configure Revise's tracking behavior within a Julia module by setting the `__revise_mode__` variable. The `:evalmeth` mode specifically tracks only method definitions, which is the default for `includet` and useful for fine-grained control. ```julia __revise_mode__ = :evalmeth ``` -------------------------------- ### Synchronous Processing of Packages and @require Blocks in Julia Source: https://github.com/timholy/revise.jl/blob/master/NEWS.md Revise 3.2 switches to synchronous processing for new packages and `@require` blocks. This ensures that Revise's work queue completes before new operations begin, providing greater guarantees of completion, albeit with a small increase in initial latency. ```julia # Synchronous processing is enabled by default in Revise 3.2+ ``` -------------------------------- ### Trigger code execution on file changes with Revise.jl Source: https://github.com/timholy/revise.jl/blob/master/docs/src/index.md This snippet demonstrates how to use Revise.jl's `entr` function to automatically execute a specified Julia function whenever changes are detected in a list of files or directories. It can also be configured to monitor all packages tracked by Revise by setting the `all` keyword argument to `true`. This is useful for workflows like regenerating web pages after code updates. ```julia entr(["file.js", "assets"], [MyWebCode]) do build_webpages(args...) end ``` ```julia entr(["file.js", "assets"], all=true) do build_webpages(args...) end ``` -------------------------------- ### Handling Revise.jl Errors and Retrying Source: https://context7.com/timholy/revise.jl/llms.txt This snippet demonstrates how to inspect the queue of errors reported by Revise.jl and how to retry the revision process after fixing issues. It's crucial for debugging and resuming development after encountering errors during code updates. ```julia # Check the queue of errors julia> Revise.queue_errors Dict{Tuple{PkgData, String}, Tuple{Exception, Any}}(...) # After fixing issues, retry julia> Revise.retry() ``` -------------------------------- ### Define Indentation Logic in Julia Source: https://github.com/timholy/revise.jl/blob/master/docs/src/internals.md Defines simple indentation logic for different integer types (UInt16 and UInt8) within the 'Items' module's scope. This file is included by Items.jl. ```julia indent(::UInt16) = 2 indent(::UInt8) = 4 ``` -------------------------------- ### Edit REPL Code with Sub-REPL in Julia Source: https://github.com/timholy/revise.jl/blob/master/docs/src/tricks.md This snippet demonstrates how to use Revise.jl and REPL to create a sub-REPL for editing REPL definitions. It allows for code reloading with Ctrl+D and quitting with 'exit()'. This method bypasses the need to exit the main REPL session to test code changes. ```julia using Revise using REPL Revise.track(REPL) term = REPL.Terminals.TTYTerminal("dumb", stdin, stdout, stderr) repl = REPL.LineEditREPL(term, true) Revise.retry() while true @info("Launching sub-REPL, use `^D` to reload, `exit()` to quit.") REPL.run_repl(repl) Revise.retry() end ``` -------------------------------- ### Julia Module with Named Function as remotecall Alternative Source: https://github.com/timholy/revise.jl/blob/master/docs/src/limitations.md This Julia code presents a workaround for distributed computing limitations with anonymous functions. It defines a named function `greetcaller` that encapsulates the operation, allowing `remotecall_fetch` to work reliably with Revise.jl even when the function's definition is modified. ```julia module ParReviseExample using Distributed greet(x) = println("Hello, ", x) greetcaller() = greet("Bar") foo() = for p in workers() remotecall_fetch(greetcaller, p) end end # module ``` -------------------------------- ### Revise.jl Lowered Code Analysis Functions Source: https://github.com/timholy/revise.jl/blob/master/docs/src/dev_reference.md Details functions for analyzing lowered code, which forms a significant part of Revise.jl's core logic. This includes minimal evaluation and identifying methods by execution. ```julia Revise.minimal_evaluation! Revise.methods_by_execution! Revise.CodeTrackingMethodInfo ```