API for clojure.tools.namespace - Extract namespace declarations 0.2.5 (in development)

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



clojure-source-file?

function
Usage: (clojure-source-file? file)
DEPRECATED; trivial to implement locally

Returns true if file is a normal file with a .clj extension.
Source


clojure-sources-in-jar

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


comment?

function
Usage: (comment? form)
DEPRECATED; moved to clojure.tools.namespace.parse

Returns true if form is a (comment ...)
Source


find-clojure-sources-in-dir

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


find-namespaces-in-dir

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


find-namespaces-in-jarfile

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


find-namespaces-on-classpath

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


find-ns-decls-in-dir

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


find-ns-decls-in-jarfile

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


find-ns-decls-on-classpath

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


ns-decl?

function
Usage: (ns-decl? form)
DEPRECATED; moved to clojure.tools.namespace.parse

Returns true if form is a (ns ...) declaration.
Source


read-file-ns-decl

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


read-ns-decl

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

clojure.tools.namespace.dependency

Bidirectional graphs of dependencies and dependent objects.

Protocols



DependencyGraph

Protocol

    Known implementations: MapDependencyGraph
    

immediate-dependencies

function
Usage: (immediate-dependencies graph node)
Returns the set of immediate dependencies of node.

immediate-dependents

function
Usage: (immediate-dependents graph node)
Returns the set of immediate dependents of node.

nodes

function
Usage: (nodes graph)
Returns the set of all nodes in graph.

transitive-dependencies

function
Usage: (transitive-dependencies graph node)
Returns the set of all things which node depends on, directly or
transitively.

transitive-dependents

function
Usage: (transitive-dependents graph node)
Returns the set of all things which depend upon node, directly or
transitively.
Source


DependencyGraphUpdate

Protocol

    Known implementations: MapDependencyGraph
    

depend

function
Usage: (depend graph node dep)
Returns a new graph with a dependency from node to dep ("node depends
on dep"). Forbids circular dependencies.

remove-all

function
Usage: (remove-all graph node)
Returns a new dependency graph with all references to node removed.

remove-edge

function
Usage: (remove-edge graph node dep)
Returns a new graph with the dependency from node to dep removed.

remove-node

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



MapDependencyGraph

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



->MapDependencyGraph

function
Usage: (->MapDependencyGraph dependencies dependents)
Positional factory function for class clojure.tools.namespace.dependency.MapDependencyGraph.
Source


dependent?

function
Usage: (dependent? graph x y)
True if y is a dependent of x.
Source


depends?

function
Usage: (depends? graph x y)
True if x is directly or transitively dependent on y.
Source


graph

function
Usage: (graph)
Returns a new, empty, dependency graph.
Source


map->MapDependencyGraph

function
Usage: (map->MapDependencyGraph m#)
Factory function for class clojure.tools.namespace.dependency.MapDependencyGraph, taking a map of keywords to field values.
Source


topo-comparator

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


topo-sort

function
Usage: (topo-sort graph)
Returns a topologically-sorted list of nodes in graph.
Source

clojure.tools.namespace.dir

Track namespace dependencies and changes by monitoring
file-modification timestamps

Public Variables and Functions



scan

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


scan-all

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

clojure.tools.namespace.file

Read and track namespace information from files

Public Variables and Functions



add-files

function
Usage: (add-files tracker files)
Reads ns declarations from files; returns an updated dependency
tracker with those files added.
Source


clojure-file?

function
Usage: (clojure-file? file)
Returns true if the java.io.File represents a normal Clojure source
file.
Source


read-file-ns-decl

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


remove-files

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

clojure.tools.namespace.find

Search for namespace declarations in directories and JAR files.

Public Variables and Functions



clojure-sources-in-jar

function
Usage: (clojure-sources-in-jar jar-file)
Returns a sequence of filenames ending in .clj found in the JAR file.
Source


find-clojure-sources-in-dir

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


find-namespaces

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


find-namespaces-in-dir

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


find-namespaces-in-jarfile

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


find-ns-decls

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


find-ns-decls-in-dir

function
Usage: (find-ns-decls-in-dir dir)
Searches dir recursively for (ns ...) declarations in Clojure
source files; returns the unevaluated ns declarations.
Source


find-ns-decls-in-jarfile

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

clojure.tools.namespace.move

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



move-ns

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.

This is a purely textual transformation. It does not work on
namespaces require'd or use'd from a prefix list.

WARNING: This function modifies and deletes your source files! Make
sure you have a backup or version control.
Source


move-ns-file

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


replace-ns-symbol

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

clojure.tools.namespace.parse

Parse Clojure namespace (ns) declarations and extract
dependencies.

Public Variables and Functions



comment?

function
Usage: (comment? form)
Returns true if form is a (comment ...)
Source


deps-from-ns-decl

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


ns-decl?

function
Usage: (ns-decl? form)
Returns true if form is a (ns ...) declaration.
Source


read-ns-decl

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

clojure.tools.namespace.reload

Force reloading namespaces on demand or through a
dependency tracker

Public Variables and Functions



remove-lib

function
Usage: (remove-lib lib)
Remove lib's namespace and remove lib from the set of loaded libs.
Source


track-reload

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


track-reload-one

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

clojure.tools.namespace.repl

REPL utilities for working with namespaces

Public Variables and Functions



disable-reload!

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


disable-unload!

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


refresh

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


refresh-all

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


set-refresh-dirs

function
Usage: (set-refresh-dirs & dirs)
Sets the directories which are scanned by 'refresh'. Supports the
same types as clojure.java.io/file.
Source

clojure.tools.namespace.track

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



add

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


remove

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


tracker

function
Usage: (tracker)
Returns a new, empty dependency tracker
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.