Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow defdeps to be optionally prefixed with the #_ (ignore next form) reader macro #1

Merged
merged 1 commit into from Jan 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Expand Up @@ -23,9 +23,11 @@ you quickly want to analyse and plot some data using
## Usage

lein-oneoff scripts usually consist of a single file. Dependencies
should be stated at the top using the `defdeps` form. Here's an example:
should be stated at the top using the `defdeps` form. You may
optionally prefix the `defdeps` form with the reader macro #_ (ignore
next form). Here's an example:

(defdeps
#_(defdeps
[[org.clojure/clojure "1.2.0"]
[compojure "0.5.2"]
[ring/ring-jetty-adapter "0.3.3"]])
Expand Down Expand Up @@ -60,9 +62,10 @@ signature:
where dependencies should be specified as a vector using the same
syntax as inside regular leiningen `defproject` form under the
`:dependencies` key. The second argument is an optional map of
additional standard `defproject` entries. Please note that not
all of the available leinigen options make sense for a one-off script
and might not work correctly.
additional standard `defproject` entries. Please note that not all of
the available leinigen options make sense for a one-off script and
might not work correctly. Adding a `#_` prefix will make it possible
ignore the `defdeps` form when re-compiling the file in a repl.

One of the entries that can be useful is the `:repositories` entry. Here's
an example:
Expand Down
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject lein-oneoff "0.1.1"
(defproject lein-oneoff "0.1.2"
:description "Dependency management for one-off scripts."
:dev-dependencies [[lein-clojars "0.6.0"]]
:eval-in-leiningen true)
8 changes: 6 additions & 2 deletions src/leiningen/oneoff.clj
Expand Up @@ -82,8 +82,12 @@ of a one-off project."
(when swank-form-var
(add-hook swank-form-var oneoff-swank-form-hook))

(defn parse-defdeps [script]
(let [form (read-string (slurp script))]
(defn parse-defdeps
"Parse the defdeps form from the script, removing any leading #_
reader macro if needed."
[script]
(let [form (read-string
(.replaceFirst (re-matcher #"^ *#_" (slurp script)) ""))]
(if (= (first form) 'defdeps)
[(nth form 1) (nth form 2 {})]
[default-deps {}])))
Expand Down