I am trying to use lein.py, from above, on Windows (Vista).
It works nicely for some commands (e.g. lein.py compile),
after removing the extra space in two places e.g.
'leiningen-%s-standalone .jar' ->
'leiningen-%s-standalone.jar'
and
'1.1.0-alpha-SNAPSHOT/cloju re-1.1.0-alpha-SNAPSHOT.jar' ->
'1.1.0-alpha-SNAPSHOT/clojure-1.1.0-alpha-SNAPSHOT.jar'
But I still have the following error with the 'lein.py install' and
'lein.py jar' commands:
E:\temp\leiningen\myproject> E:\etc\clojure\Leiningen\lein.py install
Exception in thread "main" java.util.regex.PatternSyntaxException:
Illegal/unsupported escape sequence near index 9
^E:\temp\leiningen\myproject
^ (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:5274)
at clojure.lang.Compiler.eval(Compiler.java:5226)
...
E:\temp\leiningen\myproject> E:\etc\clojure\Leiningen\lein.py jar
Exception in thread "main" java.util.regex.PatternSyntaxException:
Illegal/unsupported escape sequence near index 9
^E:\temp\leiningen\myproject
^ (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:5274)
at clojure.lang.Compiler.eval(Compiler.java:5226)
...
I am guessing that this means that the backslash in 'temp\leiningen'
needs to be escaped
somewhere in the python script (lein.py) above.
(I am not clear why the first backslash (in E:\temp) is not reported
as the error (index 4).)
I have tried many guesses (I am not familiar with python (V2.6)).
Can anyone make some suggestions?
Regards,
John.
On Dec 12, 10:31 pm, Rob Wolfe <r...@smsnet.pl> wrote:
> LEIN_JAR = expanduser("~/.m2/repository/leiningen/leiningen/%s/leiningen-%s-standalone .jar" % (VERSION, VERSION))
>
> CLOJURE_JAR = expanduser("~/.m2/repository/org/clojure/clojure/1.1.0-alpha-SNAPSHOT/cloju re-1.1.0-alpha-SNAPSHOT.jar")
> Hi,
>
> I am trying to use lein.py, from above, on Windows (Vista).
>
> It works nicely for some commands (e.g. lein.py compile),
> after removing the extra space in two places e.g.
> 'leiningen-%s-standalone .jar' ->
> 'leiningen-%s-standalone.jar'
> and
> '1.1.0-alpha-SNAPSHOT/cloju re-1.1.0-alpha-SNAPSHOT.jar' ->
> '1.1.0-alpha-SNAPSHOT/clojure-1.1.0-alpha-SNAPSHOT.jar'
It's really strange. These additional spaces don't exist in my original script.
They were added by google groups or something.
I don't think it is `lein.py` problem anymore.
Leiningen uses regular expressions on paths and as usually
there is a problem with windows path separator.
I took a look in leiningen source and this small patch made
command "jar" working for me on Windows
(I haven't looked at "install" command, but probably it is the same
problem):
<patch>
diff --git a/src/leiningen/jar.clj b/src/leiningen/jar.clj
index 227bccd..d1dd766 100644
--- a/src/leiningen/jar.clj
+++ b/src/leiningen/jar.clj
@@ -22,13 +22,17 @@
(str "Main-Class: " main))])
"\n")))))
+(defn unix-path [path]
+ (.replaceAll path "\\\\" "/"))
+
(defmulti copy-to-jar (fn [project jar-os spec] (:type spec)))
(defmethod copy-to-jar :path [project jar-os spec]
(doseq [child (file-seq (file (:path spec)))]
(when-not (.isDirectory child)
- (let [path (str child)
- path (re-sub (re-pattern (str "^" (:root project))) "" path)
+ (let [path (unix-path (str child))
+ path (re-sub (re-pattern (str "^" (unix-path (:root project))))
+ "" path)
path (re-sub #"^/resources" "" path)
path (re-sub #"^/classes" "" path)
path (re-sub #"^/src" "" path)
</patch>
HTH,
Rob
> I am trying to use lein.py, from above, on Windows (Vista).
> But I still have the following error with the 'lein.py install' and
> 'lein.py jar' commands:
I don't know Python myself, so I will wait until I hear about these
being resolved before I check this in.
-Phil
I made the changes src/leiningen/jar.clj that you suggested.
Then issued the commands:
E:\etc\clojure\Leiningen\lein.py clean
E:\etc\clojure\Leiningen\lein.py deps
E:\etc\clojure\Leiningen\lein.py compile
E:\etc\clojure\Leiningen\lein.py jar
E:\etc\clojure\Leiningen\lein.py uberjar
and they all work to compile the new Leiningen.
(Fyi, I originally didn’t have the 'lein.py deps' step
and this seems to be essential, in my case.)
Then in the python script (lein.py), I set
LEIN_JAR = expanduser("E:/keep/eclipse/3.5/git-leiningen/src/
leiningen-standalone.jar")
CLOJURE_JAR = expanduser("E:/keep/eclipse/3.5/git-leiningen/src/lib/
clojure-1.1.0-master-20091218.160125-7.jar")
i.e. to point at the newly compiled leiningen and the version of
clojure
that it downloaded into its 'lib' folder.
I then tried the simple example at
http://zef.me/2470/building-clojure-projects-with-leiningen
using this project.clj
(defproject helloworld "0.1"
:dependencies [[org.clojure/clojure "1.1.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib "1.0-SNAPSHOT"]]
:main helloworld)
to correspond to the project.clj in E:/keep/eclipse/3.5/git-leiningen/
src
which contains
(defproject leiningen "1.1.0-SNAPSHOT"
:description "A build tool designed not to set your hair on fire."
:url "http://github.com/technomancy/leiningen"
:dependencies [[org.clojure/clojure "1.1.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib "1.0-SNAPSHOT"]
[ant/ant-launcher "1.6.2"]
[jline "0.9.94"]
[org.apache.maven/maven-ant-tasks "2.0.10"]]
:dev-dependencies [[leiningen/lein-swank "1.0.0-SNAPSHOT"]]
:main leiningen.core)
I am able to compile the helloworld example:
E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py compile
[copy] Copying 2 files to E:\keep\clojure\helloworld\lib
Compiling helloworld
But 'lein.py uberjar' or 'lein.py jar' both produce stange errors:
E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py uberjar
Wrong number of arguments to task uberjar.
E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py jar
Wrong number of arguments to task jar.
and so does 'lein.py new'
E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py new
Wrong number of arguments to task new.
E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py version
Leiningen nil on Java 1.6.0_18-ea Java HotSpot(TM) Client VM
This seems to be a different issue (possibly with the lein.py
script?).
Any pointers would be very welcome.
Regards,
John.
On Dec 19, 10:25 pm, Rob Wolfe <r...@smsnet.pl> wrote:
Are you really sure that function `copy-to-jar` looks exactly like this:
<code>
(defmethod copy-to-jar :path [project jar-os spec]
(doseq [child (file-seq (file (:path spec)))]
(when-not (.isDirectory child)
(let [path (unix-path (str child))
path (re-sub (re-pattern (str "^" (unix-path (:root project))))
"" path)
path (re-sub #"^/resources" "" path)
path (re-sub #"^/classes" "" path)
path (re-sub #"^/src" "" path)
path (re-sub #"^/" "" path)]
(.putNextEntry jar-os (JarEntry. path))
(copy child jar-os)))))
</codec>
I mean `unix-path` function is called twice not only once.
In order to see what is exactly the problem you need to comment out
`try-except` clause in core.clj in "-main" function.
>
> and so does 'lein.py new'
>
> E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py new
> Wrong number of arguments to task new.
And this message is totally OK. "new" command requires at least one
argument, e.g. project name:
lein.py new test_proj
But see below.
> E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py version
> Leiningen nil on Java 1.6.0_18-ea Java HotSpot(TM) Client VM
>
> This seems to be a different issue (possibly with the lein.py
> script?).
> Any pointers would be very welcome.
But there is still problem with passing arguments from windows
command line to leiningen. All arguments are considered as one
by Leiningen, so:
lein.py "new" "test_proj"
means for Leiningen:
lein.py "new test_proj"
I'm starting to think that it would be
nice to call leiningen as regular jar (I mean adding leiningen.clj
with "-main" function). Using "clojure.main" and "-e" is really
difficult on Windows.
@Phil what do you think about it?
Anyway I came up with this not very elegant soultion:
# part of lein.py
<code>
def run_leiningen(argv):
def escape_arg(s):
return s.replace("\\", "\\\\").replace("\"", "\\\"")
ARGS = ['"' + escape_arg(s) + '"' for s in argv]
CMD = ("java -Xbootclasspath/a:%s -client -cp %s clojure.main" \
+ " -e \"(use 'leiningen.core) (-main \\\"%s\\\")\"") \
% (quote_cp([CLOJURE_JAR]), quote_cp(CLASSPATH), ARGS[0])
if len(ARGS) == 2:
CMD = ("java -Xbootclasspath/a:%s -client -cp %s clojure.main" \
+ " -e \"(use 'leiningen.core) (-main \\\"%s\\\" \\\"%s\\\")\"") \
% (quote_cp([CLOJURE_JAR]), quote_cp(CLASSPATH), ARGS[0], ARGS[1])
elif len(ARGS) == 3:
CMD = ("java -Xbootclasspath/a:%s -client -cp %s clojure.main" \
+ " -e \"(use 'leiningen.core) (-main \\\"%s\\\" \\\"%s\\\" \\\"%s\\\")\"") \
% (quote_cp([CLOJURE_JAR]), quote_cp(CLASSPATH),
ARGS[0], ARGS[1], ARGS[2])
system(CMD)
</code>
I hope there is no command which requires more than 2 arguments. ;)
And now I managed to do what you were trying:
c:\src\clojure\test>c:\tools\bin\lein.py new test_proj
Created new project in: test_proj
c:\src\clojure\test>dir test_proj
2009-12-20 19:29 <DIR> .
2009-12-20 19:29 <DIR> ..
2009-12-20 19:29 56 .gitignore
2009-12-20 19:29 173 project.clj
2009-12-20 19:29 119 README
2009-12-20 19:29 <DIR> src
2009-12-20 19:29 <DIR> test
C:\src\clojure\test\helloworld>dir
2009-12-20 19:31 <DIR> .
2009-12-20 19:31 <DIR> ..
2009-12-20 19:05 187 project.clj
2009-12-20 19:06 <DIR> src
C:\src\clojure\test\helloworld>c:\tools\bin\lein.py compile
[copy] Copying 2 files to C:\src\clojure\test\helloworld\lib
Compiling helloworld
C:\src\clojure\test\helloworld>c:\tools\bin\lein.py jar
C:\src\clojure\test\helloworld>c:\tools\bin\lein.py uberjar
Including helloworld.jar
Including clojure-1.1.0-master-20091218.160125-7.jar
Including clojure-contrib-1.0-20091212.214557-33.jar
C:\src\clojure\test\helloworld>dir
2009-12-20 19:33 <DIR> .
2009-12-20 19:33 <DIR> ..
2009-12-20 19:32 <DIR> classes
2009-12-20 19:33 5 261 247 helloworld-standalone.jar
2009-12-20 19:33 5 498 helloworld.jar
2009-12-20 19:32 <DIR> lib
2009-12-20 19:05 187 project.clj
2009-12-20 19:06 <DIR> src
HTH,
Rob
Thanks for your helpful reply. I have finally had success.
On Dec 20, 7:10 pm, Rob Wolfe <r...@smsnet.pl> wrote:
> Are you really sure that function `copy-to-jar` looks exactly like this:
> ...
> I mean `unix-path` function is called twice not only once.
Evidently not.
So I started from fresh again, just to be certain.
> In order to see what is exactly the problem you need to comment out
> `try-except` clause in core.clj in "-main" function.
This wasn't necessary in the end, in my case.
>> E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py new
>> Wrong number of arguments to task new.
>
>And this message is totally OK. "new" command requires at least one
>argument, e.g. project name: lein.py new test_proj
My mistake, sorry.
(I should have remembered that new requires 2 args from before.)
>Anyway I came up with this not very elegant soultion:
># part of lein.py
><code>
>def run_leiningen(argv):
>...
I added your amended code to the python script to handle a second
argument.
Aside: if anyone cuts and pastes Rob's python code from a browser,
you may have to delete the whitespace after the 6 continuation
symbols (\) or else python (V2.6) complains.
So I have got past yesterday's issues and now have a standalone jar
file.
In case, it is helpful to others, the commands that I used
(virtually the same as in your last email) were:
E:\etc\clojure\Leiningen\lein.py clean
E:\etc\clojure\Leiningen\lein.py deps
E:\etc\clojure\Leiningen\lein.py compile
E:\etc\clojure\Leiningen\lein.py jar
E:\etc\clojure\Leiningen\lein.py uberjar
:: WARNING: Not 'java -jar helloworld.jar'. D'oh!
java -jar helloworld-standalone.jar
Thanks for your time with this.
Regards,
John.
On Dec 20, 7:10 pm, Rob Wolfe <r...@smsnet.pl> wrote: