API for clojure.tools.namespace
-
by Stuart Sierra
Full namespace name:
clojure.tools.namespace
Overview
This namespace is DEPRECATED; most functions have been moved to
other namespaces
Public Variables and Functions
function
Usage: (clojure-source-file? file)
DEPRECATED; trivial to implement locally
Returns true if file is a normal file with a .clj extension.
Source
function
Usage: (clojure-sources-in-jar jar-file)
DEPRECATED; moved to clojure.tools.namespace.find
Returns a sequence of filenames ending in .clj found in the JAR file.
Source
function
Usage: (comment? form)
DEPRECATED; moved to clojure.tools.namespace.parse
Returns true if form is a (comment ...)
Source
function
Usage: (find-clojure-sources-in-dir dir)
DEPRECATED; moved to clojure.tools.namespace.find
Searches recursively under dir for Clojure source files (.clj).
Returns a sequence of File objects, in breadth-first sort order.
Source
function
Usage: (find-namespaces-in-dir dir)
DEPRECATED; moved to clojure.tools.namespace.find
Searches dir recursively for (ns ...) declarations in Clojure
source files; returns the symbol names of the declared namespaces.
Source
function
Usage: (find-namespaces-in-jarfile jarfile)
DEPRECATED; moved to clojure.tools.namespace.find
Searches the JAR file for Clojure source files containing (ns ...)
declarations. Returns a sequence of the symbol names of the
declared namespaces.
Source
function
Usage: (find-namespaces-on-classpath)
DEPRECATED; use clojure.tools.namespace.find/find-namespaces
and clojure.java.classpath/classpath from
http://github.com/clojure/java.classpath
Searches CLASSPATH (both directories and JAR files) for Clojure
source files containing (ns ...) declarations. Returns a sequence
of the symbol names of the declared namespaces.
Source
function
Usage: (find-ns-decls-in-dir dir)
DEPRECATED; moved to clojure.tools.namespace.find
Searches dir recursively for (ns ...) declarations in Clojure
source files; returns the unevaluated ns declarations.
Source
function
Usage: (find-ns-decls-in-jarfile jarfile)
DEPRECATED; moved to clojure.tools.namespace.find
Searches the JAR file for Clojure source files containing (ns ...)
declarations; returns the unevaluated ns declarations.
Source
function
Usage: (find-ns-decls-on-classpath)
DEPRECATED; use clojure.tools.namespace.find/find-ns-decls
and clojure.java.classpath/classpath from
http://github.com/clojure/java.classpath
Searches CLASSPATH (both directories and JAR files) for Clojure
source files containing (ns ...) declarations. Returns a sequence of
the unevaluated ns declaration forms.
Source
function
Usage: (ns-decl? form)
DEPRECATED; moved to clojure.tools.namespace.parse
Returns true if form is a (ns ...) declaration.
Source
function
Usage: (read-file-ns-decl file)
DEPRECATED; moved to clojure.tools.namespace.file
Attempts to read a (ns ...) declaration from file, and returns the
unevaluated form. Returns nil if read fails, or if the first form
is not a ns declaration.
Source
function
Usage: (read-ns-decl rdr)
DEPRECATED; moved to clojure.tools.namespace.parse
Attempts to read a (ns ...) declaration from rdr, and returns the
unevaluated form. Returns nil if read fails or if a ns declaration
cannot be found. The ns declaration must be the first Clojure form
in the file, except for (comment ...) forms.
Source
read-ns-decl-from-jarfile-entry
function
Usage: (read-ns-decl-from-jarfile-entry jarfile entry-name)
DEPRECATED; moved to clojure.tools.namespace.find
Attempts to read a (ns ...) declaration from the named entry in the
JAR file, and returns the unevaluated form. Returns nil if the read
fails, or if the first form is not a ns declaration.
Source
Bidirectional graphs of dependencies and dependent objects.
Protocols
Protocol
Known implementations:
MapDependencyGraph
function
Usage: (immediate-dependencies graph node)
Returns the set of immediate dependencies of node.
function
Usage: (immediate-dependents graph node)
Returns the set of immediate dependents of node.
function
Usage: (nodes graph)
Returns the set of all nodes in graph.
function
Usage: (transitive-dependencies graph node)
Returns the set of all things which node depends on, directly or
transitively.
function
Usage: (transitive-dependents graph node)
Returns the set of all things which depend upon node, directly or
transitively.
Source
Protocol
Known implementations:
MapDependencyGraph
function
Usage: (depend graph node dep)
Returns a new graph with a dependency from node to dep ("node depends
on dep"). Forbids circular dependencies.
function
Usage: (remove-all graph node)
Returns a new dependency graph with all references to node removed.
function
Usage: (remove-edge graph node dep)
Returns a new graph with the dependency from node to dep removed.
function
Usage: (remove-node graph node)
Removes the node from the dependency graph without removing it as a
dependency of other nodes. That is, removes all outgoing edges from
node.
Source
Types
record
Fields:
[dependencies dependents]
Protocols:
DependencyGraph, DependencyGraphUpdate
Interfaces:
clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map
Public Variables and Functions
function
Usage: (->MapDependencyGraph dependencies dependents)
Positional factory function for class clojure.tools.namespace.dependency.MapDependencyGraph.
Source
function
Usage: (dependent? graph x y)
True if y is a dependent of x.
Source
function
Usage: (depends? graph x y)
True if x is directly or transitively dependent on y.
Source
function
Usage: (graph)
Returns a new, empty, dependency graph.
Source
function
Usage: (map->MapDependencyGraph m#)
Factory function for class clojure.tools.namespace.dependency.MapDependencyGraph, taking a map of keywords to field values.
Source
function
Usage: (topo-comparator graph)
Returns a comparator fn which produces a topological sort based on
the dependencies in graph. Nodes not present in the graph will sort
after nodes in the graph.
Source
function
Usage: (topo-sort graph)
Returns a topologically-sorted list of nodes in graph.
Source
Track namespace dependencies and changes by monitoring
file-modification timestamps
Public Variables and Functions
function
Usage: (scan tracker & dirs)
Scans directories for files which have changed since the last time
'scan' was run; update the dependency tracker with
new/changed/deleted files.
If no dirs given, defaults to all directories on the classpath.
Source
function
Usage: (scan-all tracker & dirs)
Scans directories for all Clojure source files and updates the
dependency tracker to reload files. If no dirs given, defaults to
all directories on the classpath.
Source
Read and track namespace information from files
Public Variables and Functions
function
Usage: (add-files tracker files)
Reads ns declarations from files; returns an updated dependency
tracker with those files added.
Source
function
Usage: (clojure-file? file)
Returns true if the java.io.File represents a normal Clojure source
file.
Source
function
Usage: (read-file-ns-decl file)
Attempts to read a (ns ...) declaration from file, and returns the
unevaluated form. Returns nil if read fails, or if the first form
is not a ns declaration.
Source
function
Usage: (remove-files tracker files)
Returns an updated dependency tracker with files removed. The files
must have been previously added with add-files.
Source
Search for namespace declarations in directories and JAR files.
Public Variables and Functions
function
Usage: (clojure-sources-in-jar jar-file)
Returns a sequence of filenames ending in .clj found in the JAR file.
Source
function
Usage: (find-clojure-sources-in-dir dir)
Searches recursively under dir for Clojure source files (.clj).
Returns a sequence of File objects, in breadth-first sort order.
Source
function
Usage: (find-namespaces files)
Searches a sequence of java.io.File objects (both directories and
JAR files) for .clj source files containing (ns...) declarations.
Returns a sequence of the symbol names of the declared
namespaces. Use with clojure.java.classpath to search Clojure's
classpath.
Source
function
Usage: (find-namespaces-in-dir dir)
Searches dir recursively for (ns ...) declarations in Clojure
source files; returns the symbol names of the declared namespaces.
Source
function
Usage: (find-namespaces-in-jarfile jarfile)
Searches the JAR file for Clojure source files containing (ns ...)
declarations. Returns a sequence of the symbol names of the
declared namespaces.
Source
function
Usage: (find-ns-decls files)
Searches a sequence of java.io.File objects (both directories and
JAR files) for .clj source files containing (ns...) declarations.
Returns a sequence of the unevaluated ns declaration forms. Use with
clojure.java.classpath to search Clojure's classpath.
Source
function
Usage: (find-ns-decls-in-dir dir)
Searches dir recursively for (ns ...) declarations in Clojure
source files; returns the unevaluated ns declarations.
Source
function
Usage: (find-ns-decls-in-jarfile jarfile)
Searches the JAR file for Clojure source files containing (ns ...)
declarations; returns the unevaluated ns declarations.
Source
read-ns-decl-from-jarfile-entry
function
Usage: (read-ns-decl-from-jarfile-entry jarfile entry-name)
Attempts to read a (ns ...) declaration from the named entry in the
JAR file, and returns the unevaluated form. Returns nil if the read
fails, or if the first form is not a ns declaration.
Source
Refactoring tool to move a Clojure namespace from one name/file to
another, and update all references to that namespace in your other
Clojure source files.
WARNING: This code is ALPHA and subject to change. It also modifies
and deletes your source files! Make sure you have a backup or
version control.
Public Variables and Functions
function
Usage: (move-ns old-sym new-sym source-path dirs)
ALPHA: subject to change. Moves the .clj source file (found relative
to source-path) for the namespace named old-sym to new-sym and
replace all occurances of the old name with the new name in all
Clojure source files found in dirs.
WARNING: This function modifies and deletes your source files! Make
sure you have a backup or version control.
Source
function
Usage: (move-ns-file old-sym new-sym source-path)
ALPHA: subject to change. Moves the .clj source file (found relative
to source-path) for the namespace named old-sym to a file for a
namespace named new-sym.
WARNING: This function moves and deletes your source files! Make
sure you have a backup or version control.
Source
function
Usage: (replace-ns-symbol source old-sym new-sym)
ALPHA: subject to change. Given Clojure source as a string, replaces
all occurances of the namespace name old-sym with new-sym and
returns modified source as a string.
Source
Parse Clojure namespace (ns) declarations and extract
dependencies.
Public Variables and Functions
function
Usage: (comment? form)
Returns true if form is a (comment ...)
Source
function
Usage: (deps-from-ns-decl decl)
Given an (ns...) declaration form (unevaluated), returns a set of
symbols naming the dependencies of that namespace. Handles :use and
:require clauses but not :load.
Source
function
Usage: (ns-decl? form)
Returns true if form is a (ns ...) declaration.
Source
function
Usage: (read-ns-decl rdr)
Attempts to read a (ns ...) declaration from a
java.io.PushbackReader, and returns the unevaluated form. Returns
nil if read fails or if a ns declaration cannot be found. The ns
declaration must be the first Clojure form in the file, except for
(comment ...) forms.
Source
Force reloading namespaces on demand or through a
dependency tracker
Public Variables and Functions
function
Usage: (remove-lib lib)
Remove lib's namespace and remove lib from the set of loaded libs.
Source
function
Usage: (track-reload tracker)
Executes all pending unload/reload operations on dependency tracker
until either an error is encountered or there are no more pending
operations.
Source
function
Usage: (track-reload-one tracker)
Executes the next pending unload/reload operation in the dependency
tracker. Returns the updated dependency tracker. If reloading caused
an error, it is captured as ::error and the namespace which caused
the error is ::error-ns.
Source
REPL utilities for working with namespaces
Public Variables and Functions
function
Usage: (disable-reload!)
(disable-reload! namespace)
Adds metadata to namespace (or *ns* if unspecified) telling
'refresh' not to load it. Implies disable-unload! also.
Warning: Aliases to reloaded namespaces will break.
Source
function
Usage: (disable-unload!)
(disable-unload! namespace)
Adds metadata to namespace (or *ns* if unspecified) telling
'refresh' not to unload it. The namespace may still be reloaded, it
just won't be removed first.
Warning: Aliases to reloaded namespaces will break.
Source
function
Usage: (refresh & options)
Scans source code directories for files which have changed (since
the last time this function was run) and reloads them in dependency
order. Returns :ok or an error; sets the latest exception to
clojure.core/*e (if *e is thread-bound).
The directories to be scanned are controlled by 'set-refresh-dirs';
defaults to all directories on the Java classpath.
Options are key-value pairs. Valid options are:
:after Namespace-qualified symbol naming a zero-argument
function to be invoked after a successful refresh. This
symbol will be resolved *after* all namespaces have
been reloaded.
Source
function
Usage: (refresh-all & options)
Scans source code directories for all Clojure source files and
reloads them in dependency order.
The directories to be scanned are controlled by 'set-refresh-dirs';
defaults to all directories on the Java classpath.
Options are key-value pairs. Valid options are:
:after Namespace-qualified symbol naming a zero-argument
function to be invoked after a successful refresh. This
symbol will be resolved *after* all namespaces have
been reloaded.
Source
function
Usage: (set-refresh-dirs & dirs)
Sets the directories which are scanned by 'refresh'. Supports the
same types as clojure.java.io/file.
Source
Dependency tracker which can compute which namespaces need to be
reloaded after files have changed. This is the low-level
implementation that requires you to find the namespace dependencies
yourself: most uses will interact with the wrappers in
clojure.tools.namespace.file and clojure.tools.namespace.dir or the
public API in clojure.tools.namespace.repl.
Public Variables and Functions
function
Usage: (add tracker depmap)
Returns an updated dependency tracker with new/updated namespaces.
Depmap is a map describing the new or modified namespaces. Keys in
the map are namespace names (symbols). Values in the map are sets of
symbols naming the birect dependencies of each namespace. For
example, assuming these ns declarations:
(ns alpha (:require beta))
(ns beta (:require gamma delta))
the depmap would look like this:
{alpha #{beta}
beta #{gamma delta}}
After adding new/updated namespaces, the dependency tracker will
have two lists associated with the following keys:
:clojure.tools.namespace.track/unload
is the list of namespaces that need to be removed
:clojure.tools.namespace.track/load
is the list of namespaces that need to be reloaded
To reload namespaces in the correct order, first remove/unload all
namespaces in the 'unload' list, then (re)load all namespaces in the
'load' list. The clojure.tools.namespace.reload namespace has
functions to do this.
Source
function
Usage: (remove tracker names)
Returns an updated dependency tracker from which the namespaces
(symbols) have been removed. The ::unload and ::load lists are
populated as with 'add'.
Source
function
Usage: (tracker)
Returns a new, empty dependency tracker
Source