Skip to content

Commit

Permalink
Move to clojure.spec.alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
kkinnear committed May 6, 2017
1 parent cadf10b commit b226ac5
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 46 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.4.0 - 2017-5-5

### Changed

* Changed to use `clojure.spec.alpha` instead of `clojure.spec`.
Now, the 0.4.0 version runs in 1.9-alpha16, but not 1.9-alpha15.
It still runs in 1.8 as well, but requires a different supporing
library -- see the readme.

### Fixed

* Issue #26 -- now it runs in 1.9-alpha16.

## 0.3.3 - 2017-5-4

### Changed
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ and has __deprecated__ several little used configuration approachs in
order to drastically reduce its other dependencies. This may require
some slight extra work when using zprint as a library.

__NOTE:__ As of version 0.4.0, zprint now uses `clojure.spec.alpha` for
Clojure, and still used `cljs.spec` for Clojurescript.

### Clojure 1.8:

__Leiningen ([via Clojars](http://clojars.org/zprint))__
Expand All @@ -120,16 +123,22 @@ In addition to the zprint dependency, you also need to
include the library:

```
[clojure-future-spec "1.9.0-alpha15"]
[clojure-future-spec "1.9.0-alpha16-1"]
```

Probably later versions would work as well, but this is what I've
tested with.

### Clojure 1.9-alpha15:

__NOTE:__ The changes in clojure.spec for Clojure 1.9-alpha16 make this
the last release of zprint which will work with Clojure 1.9-alpha15.
__NOTE:__ Use `zprint 0.3.3` for 1.9-alpha15. `zprint 0.4.0` will not work
with 1.9-alpha15!

In addition to the zprint dependency, you also need to
include the library:

```
[clojure-future-spec "1.9.0-alpha15"]
```

### Clojure 1.9-alpha16:

__Leiningen ([via Clojars](http://clojars.org/zprint))__

Expand Down Expand Up @@ -163,7 +172,7 @@ away, but can still be used if you load the library:

If you use either of these __deprecated__ capabilities, please raise
an issue on Github and let me know. Otherwise they will go away
completely before too much longer.
very soon!

## Features

Expand Down
2 changes: 1 addition & 1 deletion appcds
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ helptext="Usage: ./setup.sh zprint-filter output-command-name"

if [[ -z "$1" ]]
then
echo "Missing first required argument: zprint filter file (e.g. zprint-filter-0.3.3)"
echo "Missing first required argument: zprint filter file (e.g. zprint-filter-0.4.0)"
echo "$helptext"
exit 1
fi
Expand Down
18 changes: 9 additions & 9 deletions doc/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ You can use a script released along with the zprint-filter uberjar
to create another script which will run the zprint-filter in a way
that it will startup in less than a second.

1. Download `zprint-filter-0.3.3` from [releases](https://github.com/kkinnear/zprint/releases/latest)
1. Download `zprint-filter-0.4.0` from [releases](https://github.com/kkinnear/zprint/releases/latest)

2. Download the install script `appcds` from [releases](https://github.com/kkinnear/zprint/releases/latest)

Expand All @@ -222,7 +222,7 @@ that it will startup in less than a second.
6. Run the install script:

```
./appcds zprint-filter-0.3.3 za
./appcds zprint-filter-0.4.0 za
```
It will run pretty quickly when it works, and will spit out
less than a page of status and statistics. When it completes,
Expand Down Expand Up @@ -256,13 +256,13 @@ Here are the steps to set this version up manually:
```
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:off \
-XX:DumpLoadedClassList=zprint.filter.classlist \
-cp zprint-filter-0.3.3 \
-cp zprint-filter-0.4.0 \
zprint.main < helloworld.clj > /dev/null
```
or, for easier copying and pasting:

```
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:off -XX:DumpLoadedClassList=zprint.filter.classlist -cp zprint-filter-0.3.3 zprint.main < helloworld.clj > /dev/null
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:off -XX:DumpLoadedClassList=zprint.filter.classlist -cp zprint-filter-0.4.0 zprint.main < helloworld.clj > /dev/null
```

5. Build the cache now that you have the list of classes used -- type this
Expand All @@ -273,14 +273,14 @@ Here are the steps to set this version up manually:
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:dump \
-XX:SharedClassListFile=zprint.filter.classlist \
-XX:SharedArchiveFile=`pwd`/zprint.filter.cache \
-cp `pwd`/zprint-filter-0.3.3 \
-cp `pwd`/zprint-filter-0.4.0 \
zprint.main < helloworld.clj
```

or, for easier copying and pasting:

```
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:dump -XX:SharedClassListFile=zprint.filter.classlist -XX:SharedArchiveFile=`pwd`/zprint.filter.cache -cp `pwd`/zprint-filter-0.3.3 zprint.main < helloworld.clj
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:dump -XX:SharedClassListFile=zprint.filter.classlist -XX:SharedArchiveFile=`pwd`/zprint.filter.cache -cp `pwd`/zprint-filter-0.4.0 zprint.main < helloworld.clj
```

This will output a bunch of statistics about building the cache.
Expand All @@ -291,12 +291,12 @@ Here are the steps to set this version up manually:
```
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:on \
-XX:SharedArchiveFile=`pwd`/zprint.filter.cache \
-cp `pwd`/zprint-filter-0.3.3 zprint.main
-cp `pwd`/zprint-filter-0.4.0 zprint.main
```
or, for easier copying and pasting:

```
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:on -XX:SharedArchiveFile=`pwd`/zprint.filter.cache -cp `pwd`/zprint-filter-0.3.3 zprint.main
java -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -Xshare:on -XX:SharedArchiveFile=`pwd`/zprint.filter.cache -cp `pwd`/zprint-filter-0.4.0 zprint.main
```

7. Make that file executable:
Expand Down Expand Up @@ -358,7 +358,7 @@ and about 10% faster than the bootclasspath approach, described above.
containing the following single line:

```
java -Xbootclasspath/a:`pwd`/zprint-filter-0.3.3 zprint.main
java -Xbootclasspath/a:`pwd`/zprint-filter-0.4.0 zprint.main
```

Note that the switch you are using is: `-Xbootclasspath/a:`, and
Expand Down
23 changes: 11 additions & 12 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
;!zprint {:vector {:wrap? false}}
(defproject zprint "0.3.3"
(defproject zprint "0.4.0"
:description "Pretty print zippers and s-expressions"
:url "https://github.com/kkinnear/zprint"
:license {:name "MIT License",
:url "https://opensource.org/licenses/MIT",
:key "mit",
:year 2015}
:plugins [[lein-expectations "0.0.8"] [lein-zprint "0.2.3"]]
:plugins [[lein-expectations "0.0.8"] [lein-zprint "0.3.0"]]
:profiles {:dev {:dependencies [[expectations "2.0.16"]
[com.taoensso/tufte "1.1.1"]
[clojure-future-spec "1.9.0-alpha15"]]},
[clojure-future-spec "1.9.0-alpha16-1"]]},
:uberjar {:aot [zprint.core zprint.main],
:main zprint.main,
:dependencies [[clojure-future-spec "1.9.0-alpha15"]],
:omit-source true,
:uberjar-name "zprint-filter-0.3.3"}}
:dependencies [[clojure-future-spec "1.9.0-alpha16-1"]]
:omit-source true
:uberjar-name "zprint-filter-0.4.0"}}
; Clojure 1.8 you can exclude all sources
:uberjar-exclusions [#"\.(clj|java|cljs)"]
; Clojure 1.9 requires the .clj files
; :uberjar-exclusions [#"\.(java|cljs)"]
:zprint {:old? false}
:dependencies
[#_[org.clojure/clojure "1.9.0-alpha15"]
[org.clojure/clojure "1.8.0"]
#_[clojure-future-spec "1.9.0-alpha15"]
[rewrite-cljs "0.4.3" :exclusions [[org.clojure/clojurescript]]]
[rewrite-clj "0.4.13" :exclusions [[com.cemerick/austin]]]
#_[table "0.4.0" :exclusions [[org.clojure/clojure]]]
[#_[org.clojure/clojure "1.9.0-alpha16"]
[org.clojure/clojure "1.8.0"]
[rewrite-cljs "0.4.3" :exclusions [[org.clojure/clojurescript]]]
[rewrite-clj "0.4.13" :exclusions [[com.cemerick/austin]]]
#_[table "0.4.0" :exclusions [[org.clojure/clojure]]]
#_[cprop "0.1.6"]])
2 changes: 1 addition & 1 deletion src/zprint/config.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
;; # Program Version
;;

(defn about "Return version of this program." [] (str "zprint-0.3.3"))
(defn about "Return version of this program." [] (str "zprint-0.4.0"))

;;
;; # External Configuration
Expand Down
7 changes: 4 additions & 3 deletions src/zprint/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
[zprint.zutil :refer [zmap-all zcomment? edn* whitespace? string]]
[zprint.sutil]
[rewrite-clj.parser :as p]
#_[clojure.spec :as spec :refer [get-spec describe]]))
#_[clojure.spec.alpha :as s]))


;;
;; zprint
Expand Down Expand Up @@ -747,8 +748,8 @@
in the doc string."
[{:keys [width rightcnt], {:keys [indent]} :list, :as options} fn-name]
(let [{n :ns, nm :name, :as m} (meta (resolve fn-name))
get-spec-fn (resolve 'clojure.spec/get-spec)
describe-fn (resolve 'clojure.spec/describe)]
get-spec-fn (resolve 's/get-spec)
describe-fn (resolve 's/describe)]
(when (and get-spec-fn describe-fn)
(when-let [fn-spec (get-spec-fn (symbol (str (ns-name n))
(name nm)))]
Expand Down
22 changes: 16 additions & 6 deletions src/zprint/spec.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns zprint.spec
#?@(:cljs [[:require-macros [zprint.smacros :refer [only-keys]]]])
(:require #?@(:clj [[zprint.smacros :refer [only-keys]] [clojure.spec :as s]]
(:require #?@(:clj [[zprint.smacros :refer [only-keys]]
[clojure.spec.alpha :as s]]
:cljs [[cljs.spec :as s]])))

;;
Expand Down Expand Up @@ -256,7 +257,7 @@
(if (and (number? last-ks)
(or (= last-ks last-num)
(= last-path
#?(:clj :clojure.spec/pred
#?(:clj :clojure.spec.alpha/pred
:cljs :cljs.spec/pred))))
(into [] (butlast ks))
ks)))
Expand All @@ -282,7 +283,7 @@
"Try to do a better job of explaining spec problems."
[explain-data-return]
(when explain-data-return
(let [problem-list (#?(:clj :clojure.spec/problems
(let [problem-list (#?(:clj :clojure.spec.alpha/problems
:cljs :cljs.spec/problems)
explain-data-return)
problem-list (remove #(= "nil?" (str (:pred %))) problem-list)
Expand All @@ -302,6 +303,7 @@
"Using spec defined above, validate the given options map. Return
nil if no errors, or a string containing errors if any."
([options source-str]
#_(println "Options:" options)
(try (if (s/valid? ::options options)
nil
(if source-str
Expand All @@ -310,10 +312,18 @@
(explain-more (s/explain-data ::options options))))
(catch #?(:clj Exception
:cljs :default) e
#_(println "Exception:" (str e))
#_(println "type of exception:" (type e))
#_(println ":cause" (:cause e))
(if source-str
(str "In " source-str
", validation failed completely because: " (.-message e))
(str "Validation failed completely because: " (.-message e))))))
(str "In "
source-str
", validation failed completely because: "
(str e)
#_(.-message e))
(str "Validation failed completely because: "
(str e)
#_(.-message e))))))
([options] (validate-basic options nil)))

#_(defn explain
Expand Down
2 changes: 1 addition & 1 deletion test/zprint/spec_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[zprint.spec :refer :all]
[zprint.finish :refer :all]
[clojure.repl :refer :all]
[clojure.spec :as s]
[clojure.spec.alpha :as s]
[clojure.string :as str]
[rewrite-clj.parser :as p :only [parse-string parse-string-all]]
[rewrite-clj.node :as n]
Expand Down
5 changes: 0 additions & 5 deletions test/zprint/zprint_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,3 @@
(read-string (zprint-str (trim-gensym-regex
(read-string (source-fn
'zprint.zprint/fzprint-list*))))))





2 changes: 1 addition & 1 deletion test_uberjar
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
java -jar target/zprint-filter-0.3.3 <src/zprint/zprint.cljc >z.cljc
java -jar target/zprint-filter-0.4.0 <src/zprint/zprint.cljc >z.cljc
diff z.cljc src/zprint/zprint.cljc
rm z.cljc

0 comments on commit b226ac5

Please sign in to comment.