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

Un-puget #49

Merged
merged 11 commits into from
Oct 7, 2019
8 changes: 6 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2.1
executors:
clojure:
docker:
- image: circleci/clojure:lein-2.9.1
- image: circleci/clojure:openjdk-11-lein-2.9.1
working_directory: ~/repo


Expand All @@ -16,7 +16,11 @@ jobs:
- checkout
- run:
name: Install cljfmt CLI
command: "wget https://github.com/greglook/cljfmt/releases/download/0.8.1/cljfmt_0.8.1_linux.tar.gz && tar -xzf cljfmt_0.8.1_linux.tar.gz"
environment:
CLJFMT_VERSION: 0.8.2
command: |
wget https://github.com/greglook/cljfmt/releases/download/${CLJFMT_VERSION}/cljfmt_${CLJFMT_VERSION}_linux.tar.gz
tar -xzf cljfmt_${CLJFMT_VERSION}_linux.tar.gz
- run:
name: Check source formatting
command: "./cljfmt check --stats style-stats.tsv"
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

...
### Changed
- Remove dependency on `puget` for colorized output and canonical printing. This
avoids pulling in `fipp` which is problematic on Java 9+.

## [1.2.2] - 2019-09-11

Expand Down
4 changes: 2 additions & 2 deletions example/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
:description "Overarching example project."

:plugins
[[lein-monolith "1.0.2-SNAPSHOT"]
[lein-cprint "1.2.0"]]
[[lein-monolith "1.2.3-SNAPSHOT"]
[lein-pprint "1.2.0"]]

:dependencies
[[org.clojure/clojure "1.8.0"]]
Expand Down
3 changes: 1 addition & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

:dependencies
[[manifold "0.1.8"]
[mvxcvi/puget "1.1.2"]
[rhizome "0.2.9"]]

:hiera
{:vertical false
:show-external true
:cluster-depth 1
:ignore-ns #{clojure puget manifold}}
:ignore-ns #{clojure manifold}}

:profiles
{:dev {:plugins [[lein-cloverage "1.0.9"]]
Expand Down
65 changes: 65 additions & 0 deletions src/lein_monolith/color.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
(ns lein-monolith.color
"Coloring functions which apply ANSI color codes to color terminal output."
(:require
[clojure.string :as str]))


(def ^:private sgr-code
"Map of symbols to numeric SGR (select graphic rendition) codes."
{:none 0
:bold 1
:underline 3
:blink 5
:reverse 7
:hidden 8
:strike 9
:black 30
:red 31
:green 32
:yellow 33
:blue 34
:magenta 35
:cyan 36
:white 37
:fg-256 38
:fg-reset 39
:bg-black 40
:bg-red 41
:bg-green 42
:bg-yellow 43
:bg-blue 44
:bg-magenta 45
:bg-cyan 46
:bg-white 47
:bg-256 48
:bg-reset 49})


(def enabled?
"Delay which yields true if text should be rendered with color."
(delay
(let [env (System/getenv "LEIN_MONOLITH_COLOR")
disabled? (and env (contains? #{"no" "false" "off"}
(str/lower-case env)))]
(not disabled?))))


(defn- sgr
"Returns an ANSI escope string which will apply the given collection of SGR
codes."
[codes]
(let [codes (map sgr-code codes codes)
codes (str/join \; codes)]
(str \u001b \[ codes \m)))


(defn colorize
"Wraps the given string with SGR escapes to apply the given codes, then reset
the graphics. If `*enabled*` is not truthy, returns the string unaltered."
[codes string]
(if @enabled?
(let [codes (if (keyword? codes)
[codes]
(vec codes))]
(str (sgr codes) string (sgr [:none])))
string))
21 changes: 10 additions & 11 deletions src/lein_monolith/dependency.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
(:require
[clojure.set :as set]
[clojure.string :as str]
[leiningen.core.main :as lein]
[puget.color.ansi :as ansi]
[puget.printer :as puget]))
[lein-monolith.color :refer [colorize]]
[leiningen.core.main :as lein]))


;; ## Coordinate Functions
Expand Down Expand Up @@ -196,16 +195,16 @@
default-choice
; Multiple versions or specs declared! Warn and use the default.
(do
(-> (str "WARN: Multiple dependency specs found for "
(condense-name dep-name) " in "
(count (distinct (map dep-source specs)))
" projects - using " (pr-str default-choice) " from "
(dep-source default-choice))
(ansi/sgr :red)
(lein/warn))
(->> (str "WARN: Multiple dependency specs found for "
(condense-name dep-name) " in "
(count (distinct (map dep-source specs)))
" projects - using " (pr-str default-choice) " from "
(dep-source default-choice))
(colorize :red)
(lein/warn))
(doseq [[spec projects] projects-for-specs]
(lein/warn (format "%-50s from %s"
(puget/cprint-str spec)
(pr-str spec)
(str/join " " (sort projects)))))
(lein/warn "")
default-choice))))
4 changes: 1 addition & 3 deletions src/lein_monolith/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
[lein-monolith.config :as config]
[lein-monolith.dependency :as dep]
[leiningen.core.main :as lein]
[leiningen.core.project :as project]
[puget.color.ansi :as ansi]
[puget.printer :as puget]))
[leiningen.core.project :as project]))


;; ## Profile Generation
Expand Down
46 changes: 23 additions & 23 deletions src/lein_monolith/task/each.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require
[clojure.java.io :as io]
[clojure.string :as str]
[lein-monolith.color :refer [colorize]]
[lein-monolith.config :as config]
[lein-monolith.dependency :as dep]
[lein-monolith.plugin :as plugin]
Expand All @@ -13,8 +14,7 @@
[leiningen.core.project :as project]
[leiningen.core.utils :refer [rebind-io!]]
[manifold.deferred :as d]
[manifold.executor :as executor]
[puget.color.ansi :as ansi])
[manifold.executor :as executor])
(:import
(com.hypirion.io
ClosingPipe
Expand Down Expand Up @@ -78,25 +78,25 @@
(let [task-time (reduce + (keep :elapsed results))
speedup (/ task-time elapsed)]
(lein/info (format "\n%s %11s"
(ansi/sgr "Run time:" :bold :cyan)
(colorize [:bold :cyan] "Run time:")
(u/human-duration elapsed)))
(lein/info (format "%s %11s"
(ansi/sgr "Task time:" :bold :cyan)
(colorize [:bold :cyan] "Task time:")
(u/human-duration task-time)))
(lein/info (format "%s %11.1f"
(ansi/sgr "Speedup:" :bold :cyan)
(colorize [:bold :cyan] "Speedup:")
speedup))
(lein/info (->> results
(sort-by :elapsed)
(reverse)
(take 8)
(map #(format "%-45s %s %11s"
(ansi/sgr (:name %) :bold :yellow)
(colorize [:bold :yellow] (:name %))
(if (:success %) " " "!")
(u/human-duration (:elapsed %))))
(str/join "\n")
(str \newline
(ansi/sgr "Slowest projects:" :bold :cyan)
(colorize [:bold :cyan] "Slowest projects:")
\newline)))))


Expand Down Expand Up @@ -257,7 +257,7 @@
fprints (:fingerprints ctx)]
(try
(lein/info (format "\nApplying to %s%s"
(ansi/sgr target :bold :yellow)
(colorize [:bold :yellow] target)
(if marker
(str " (" (fingerprint/explain-str fprints marker target) ")")
"")))
Expand All @@ -269,8 +269,8 @@
(when (:refresh opts)
(fingerprint/save! fprints marker target)
(lein/info (format "Saved %s fingerprint for %s"
(ansi/sgr marker :bold)
(ansi/sgr target :bold :yellow))))
(colorize :bold marker)
(colorize [:bold :yellow] target))))
(assoc @results :success true)
(catch Exception ex
(when-not (or (:parallel opts) (:endure opts))
Expand All @@ -280,17 +280,17 @@
[:start target]
(:task ctx))]
(lein/warn (format "\n%s %s\n"
(ansi/sgr "Resume with:" :bold :red)
(colorize [:bold :red] "Resume with:")
(str/join " " resume-args)))))
(when-not (:endure opts)
(throw ex))
(assoc @results :success false, :error ex))
(finally
(lein/info (format "Completed %s (%s/%s) in %s"
(ansi/sgr target :bold :yellow)
(ansi/sgr (swap! (:completions ctx) inc) :cyan)
(ansi/sgr (:num-targets ctx) :cyan)
(ansi/sgr (u/human-duration (:elapsed @results)) :bold :cyan)))))))
(colorize [:bold :yellow] target)
(colorize :cyan (swap! (:completions ctx) inc))
(colorize :cyan (:num-targets ctx))
(colorize [:bold :cyan] (u/human-duration (:elapsed @results)))))))))


(defn- run-linear!
Expand Down Expand Up @@ -348,8 +348,8 @@
(lein/info "Target selection matched zero subprojects; nothing to do")
(do
(lein/info "Applying"
(ansi/sgr (str/join " " task) :bold :cyan)
"to" (ansi/sgr (count targets) :cyan)
(colorize [:bold :cyan] (str/join " " task))
"to" (colorize :cyan (count targets))
"subprojects...")
(let [ctx {:monolith monolith
:subprojects subprojects
Expand All @@ -366,14 +366,14 @@
(print-report results elapsed))
(if-let [failures (seq (map :name (remove :success results)))]
(lein/abort (format "\n%s: Applied %s to %s projects in %s with %d failures: %s"
(ansi/sgr "FAILURE" :bold :red)
(ansi/sgr (str/join " " task) :bold :cyan)
(ansi/sgr (count targets) :cyan)
(colorize [:bold :red] "FAILURE")
(colorize [:bold :cyan] (str/join " " task))
(colorize :cyan (count targets))
(u/human-duration elapsed)
(count failures)
(str/join " " failures)))
(lein/info (format "\n%s: Applied %s to %s projects in %s"
(ansi/sgr "SUCCESS" :bold :green)
(ansi/sgr (str/join " " task) :bold :cyan)
(ansi/sgr (count targets) :cyan)
(colorize [:bold :green] "SUCCESS")
(colorize [:bold :cyan] (str/join " " task))
(colorize :cyan (count targets))
(u/human-duration elapsed)))))))))
Loading