From 55e2b18a889c0d3c1e0dc86d8a781dcb1a6c93b1 Mon Sep 17 00:00:00 2001 From: Daniel Matysiak Date: Thu, 26 Aug 2021 16:55:57 -0400 Subject: [PATCH 01/58] Print warnings to stderr to avoid polluting stderr --- environ/src/environ/core.cljc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/environ/src/environ/core.cljc b/environ/src/environ/core.cljc index 09073b8..9f98bd9 100644 --- a/environ/src/environ/core.cljc +++ b/environ/src/environ/core.cljc @@ -13,6 +13,10 @@ #?(:cljs (def ^:private process (when nodejs? (js/require "process")))) +(defn- printerr [& more] + (binding [*out* *err*] + (apply println more))) + (defn- keywordize [s] (-> (str/lower-case s) (str/replace "_" "-") @@ -21,13 +25,13 @@ (defn- sanitize-key [k] (let [s (keywordize (name k))] - (if-not (= k s) (println "Warning: environ key" k "has been corrected to" s)) + (if-not (= k s) (printerr "Warning: environ key" k "has been corrected to" s)) s)) (defn- sanitize-val [k v] (if (string? v) v - (do (println "Warning: environ value" (pr-str v) "for key" k "has been cast to string") + (do (printerr "Warning: environ value" (pr-str v) "for key" k "has been cast to string") (str v)))) (defn- read-system-env [] @@ -58,8 +62,8 @@ (doseq [[k kvs] (group-by key (apply concat ms)) :let [vs (map val kvs)] :when (and (next kvs) (not= (first vs) (last vs)))] - (println "Warning: environ value" (first vs) "for key" k - "has been overwritten with" (last vs)))) + (printerr "Warning: environ value" (first vs) "for key" k + "has been overwritten with" (last vs)))) (defn- merge-env [& ms] (warn-on-overwrite ms) From b72429217d4fb17dbda4d43079fdf3780d84cc7f Mon Sep 17 00:00:00 2001 From: Daniel Matysiak Date: Thu, 26 Aug 2021 16:55:57 -0400 Subject: [PATCH 02/58] Print warnings to STDERR to avoid polluting STDOUT --- environ/src/environ/core.cljc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/environ/src/environ/core.cljc b/environ/src/environ/core.cljc index 09073b8..9f98bd9 100644 --- a/environ/src/environ/core.cljc +++ b/environ/src/environ/core.cljc @@ -13,6 +13,10 @@ #?(:cljs (def ^:private process (when nodejs? (js/require "process")))) +(defn- printerr [& more] + (binding [*out* *err*] + (apply println more))) + (defn- keywordize [s] (-> (str/lower-case s) (str/replace "_" "-") @@ -21,13 +25,13 @@ (defn- sanitize-key [k] (let [s (keywordize (name k))] - (if-not (= k s) (println "Warning: environ key" k "has been corrected to" s)) + (if-not (= k s) (printerr "Warning: environ key" k "has been corrected to" s)) s)) (defn- sanitize-val [k v] (if (string? v) v - (do (println "Warning: environ value" (pr-str v) "for key" k "has been cast to string") + (do (printerr "Warning: environ value" (pr-str v) "for key" k "has been cast to string") (str v)))) (defn- read-system-env [] @@ -58,8 +62,8 @@ (doseq [[k kvs] (group-by key (apply concat ms)) :let [vs (map val kvs)] :when (and (next kvs) (not= (first vs) (last vs)))] - (println "Warning: environ value" (first vs) "for key" k - "has been overwritten with" (last vs)))) + (printerr "Warning: environ value" (first vs) "for key" k + "has been overwritten with" (last vs)))) (defn- merge-env [& ms] (warn-on-overwrite ms) From 5f272ffe4074c284090d77513da2fbe17af208a9 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 6 Jan 2013 20:08:15 +0000 Subject: [PATCH 03/58] Released 0.3.1 --- README.md | 4 ++-- environ.core/project.clj | 2 +- environ.lein/project.clj | 2 +- project.clj | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 62de793..41ecc01 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ the Leiningen project map. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "0.3.0"]] +:dependencies [[environ "0.3.1"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll need the following plugin and hook: ```clojure -:plugins [[environ/environ.lein "0.3.0"]] +:plugins [[environ/environ.lein "0.3.1"]] :hooks [environ.leiningen.hooks] ``` diff --git a/environ.core/project.clj b/environ.core/project.clj index ca389e2..198f7f7 100644 --- a/environ.core/project.clj +++ b/environ.core/project.clj @@ -1,4 +1,4 @@ -(defproject environ/environ.core "0.3.0" +(defproject environ/environ.core "0.3.1" :description "Core environ library for use in applications" :url "https://github.com/weavejester/environ" :dependencies [[org.clojure/clojure "1.2.1"]]) diff --git a/environ.lein/project.clj b/environ.lein/project.clj index 8b48047..80801ba 100644 --- a/environ.lein/project.clj +++ b/environ.lein/project.clj @@ -1,4 +1,4 @@ -(defproject environ/environ.lein "0.3.0" +(defproject environ/environ.lein "0.3.1" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :eval-in-leiningen true) diff --git a/project.clj b/project.clj index 530dea4..d98f12f 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,6 @@ -(defproject environ "0.3.0" +(defproject environ "0.3.1" :description "Library for managing environment settings" :url "https://github.com/weavejester/environ" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[environ/environ.core "0.3.0"]]) + :dependencies [[environ/environ.core "0.3.1"]]) From 30227f519aa613c78cccf9c78fe5d1976666f6b0 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Mon, 11 Mar 2013 20:22:49 +0000 Subject: [PATCH 04/58] Changed hook function to apply-task --- environ.lein/src/environ/leiningen/hooks.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environ.lein/src/environ/leiningen/hooks.clj b/environ.lein/src/environ/leiningen/hooks.clj index 696bc44..17d7c92 100644 --- a/environ.lein/src/environ/leiningen/hooks.clj +++ b/environ.lein/src/environ/leiningen/hooks.clj @@ -1,7 +1,7 @@ (ns environ.leiningen.hooks (:use [robert.hooke :only (add-hook)]) (:require [clojure.java.io :as io] - leiningen.core.classpath)) + leiningen.core.main)) (defn env-file [project] (io/file (:root project) ".lein-env")) @@ -12,5 +12,5 @@ (apply func dep-key project args)) (defn activate [] - (add-hook #'leiningen.core.classpath/resolve-dependencies + (add-hook #'leiningen.core.main/apply-task write-env-to-file)) From 44e4d95e383b7ff3faa1e8ab38b8c3e01ce013a1 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Tue, 12 Mar 2013 13:53:31 +0000 Subject: [PATCH 05/58] Renamed projects to integrate better with Lein 2.0.0 --- environ.lein/src/environ/leiningen/hooks.clj | 16 ---------------- {environ.core => environ}/project.clj | 2 +- {environ.core => environ}/src/environ/core.clj | 0 .../test/environ/test/core.clj | 0 {environ.lein => lein-environ}/project.clj | 2 +- lein-environ/src/lein_environ/plugin.clj | 14 ++++++++++++++ project.clj | 6 ------ 7 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 environ.lein/src/environ/leiningen/hooks.clj rename {environ.core => environ}/project.clj (79%) rename {environ.core => environ}/src/environ/core.clj (100%) rename {environ.core => environ}/test/environ/test/core.clj (100%) rename {environ.lein => lein-environ}/project.clj (74%) create mode 100644 lein-environ/src/lein_environ/plugin.clj delete mode 100644 project.clj diff --git a/environ.lein/src/environ/leiningen/hooks.clj b/environ.lein/src/environ/leiningen/hooks.clj deleted file mode 100644 index 17d7c92..0000000 --- a/environ.lein/src/environ/leiningen/hooks.clj +++ /dev/null @@ -1,16 +0,0 @@ -(ns environ.leiningen.hooks - (:use [robert.hooke :only (add-hook)]) - (:require [clojure.java.io :as io] - leiningen.core.main)) - -(defn env-file [project] - (io/file (:root project) ".lein-env")) - -(defn- write-env-to-file [func dep-key project & args] - (spit (env-file project) - (prn-str (:env project {}))) - (apply func dep-key project args)) - -(defn activate [] - (add-hook #'leiningen.core.main/apply-task - write-env-to-file)) diff --git a/environ.core/project.clj b/environ/project.clj similarity index 79% rename from environ.core/project.clj rename to environ/project.clj index 198f7f7..d47f70d 100644 --- a/environ.core/project.clj +++ b/environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ/environ.core "0.3.1" +(defproject environ "0.4.0-SNAPSHOT" :description "Core environ library for use in applications" :url "https://github.com/weavejester/environ" :dependencies [[org.clojure/clojure "1.2.1"]]) diff --git a/environ.core/src/environ/core.clj b/environ/src/environ/core.clj similarity index 100% rename from environ.core/src/environ/core.clj rename to environ/src/environ/core.clj diff --git a/environ.core/test/environ/test/core.clj b/environ/test/environ/test/core.clj similarity index 100% rename from environ.core/test/environ/test/core.clj rename to environ/test/environ/test/core.clj diff --git a/environ.lein/project.clj b/lein-environ/project.clj similarity index 74% rename from environ.lein/project.clj rename to lein-environ/project.clj index 80801ba..d435ebe 100644 --- a/environ.lein/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ/environ.lein "0.3.1" +(defproject lein-environ "0.4.0-SNAPSHOT" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :eval-in-leiningen true) diff --git a/lein-environ/src/lein_environ/plugin.clj b/lein-environ/src/lein_environ/plugin.clj new file mode 100644 index 0000000..da18965 --- /dev/null +++ b/lein-environ/src/lein_environ/plugin.clj @@ -0,0 +1,14 @@ +(ns lein-environ.plugin + (:use [robert.hooke :only (add-hook)]) + (:require [clojure.java.io :as io] + leiningen.core.main)) + +(defn env-file [project] + (io/file (:root project) ".lein-env")) + +(defn- write-env-to-file [func task-name project args] + (spit (env-file project) (prn-str (:env project {}))) + (func task-name project args)) + +(defn hooks [] + (add-hook #'leiningen.core.main/apply-task #'write-env-to-file)) \ No newline at end of file diff --git a/project.clj b/project.clj deleted file mode 100644 index d98f12f..0000000 --- a/project.clj +++ /dev/null @@ -1,6 +0,0 @@ -(defproject environ "0.3.1" - :description "Library for managing environment settings" - :url "https://github.com/weavejester/environ" - :license {:name "Eclipse Public License" - :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[environ/environ.core "0.3.1"]]) From b035deb901ec9e0e2ee7e665bfacb1aecde58622 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Tue, 12 Mar 2013 14:00:13 +0000 Subject: [PATCH 06/58] Added licenses --- environ/project.clj | 2 ++ lein-environ/project.clj | 2 ++ 2 files changed, 4 insertions(+) diff --git a/environ/project.clj b/environ/project.clj index d47f70d..119c986 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,4 +1,6 @@ (defproject environ "0.4.0-SNAPSHOT" :description "Core environ library for use in applications" :url "https://github.com/weavejester/environ" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.2.1"]]) diff --git a/lein-environ/project.clj b/lein-environ/project.clj index d435ebe..b32b0ab 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,6 @@ (defproject lein-environ "0.4.0-SNAPSHOT" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} :eval-in-leiningen true) From 5788aa3238b537a7d97cf2fc21b0c3ac9a3193aa Mon Sep 17 00:00:00 2001 From: James Reeves Date: Tue, 12 Mar 2013 14:05:00 +0000 Subject: [PATCH 07/58] Updated README with new functionality --- README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 41ecc01..a548de3 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ Environ is a Clojure library for managing environment settings from a number of different sources. -Currently, Environ supports two sources; environment variables, and -the Leiningen project map. +Currently, Environ supports three sources; environment variables, Java +system properties and the Leiningen project map using the lein-environ +plugin. ## Installation @@ -12,18 +13,17 @@ the Leiningen project map. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "0.3.1"]] +:dependencies [[environ "0.4.0-SNAPSHOT"]] ``` If you want to be able to draw settings from the Leiningen project -map, you'll need the following plugin and hook: +map, you'll also need the following plugin: ```clojure -:plugins [[environ/environ.lein "0.3.1"]] -:hooks [environ.leiningen.hooks] +:plugins [[lein-environ "0.4.0-SNAPSHOT"]] ``` -A good place to put this is in your `~/.lein/profiles.clj` file. +A good place to put this is in your `profiles.clj` file. ## Usage @@ -65,9 +65,18 @@ AWS_SECRET_KEY=YYYYYYYYYYYYYYYYYYYYYY Notice that the equivalent environment variables are uppercase, and the "-" character has been replaced with "_". +You can also use Java system properties: + +``` +java -jar app-standalone.jar -Daws.access.key=XX -Daws.secret.key=YY +``` + +Note in this case that the "-" character has been replace with ".", +since this is the standard separator for system properties. + ## License -Copyright © 2012 James Reeves +Copyright © 2013 James Reeves Distributed under the Eclipse Public License, the same as Clojure. From fffa12aa140583754c4c00cb8c55c3e573e37d52 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Tue, 12 Mar 2013 14:16:59 +0000 Subject: [PATCH 08/58] Released 0.4.0 --- README.md | 4 ++-- environ/project.clj | 2 +- lein-environ/project.clj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a548de3..6c71b77 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,14 @@ plugin. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "0.4.0-SNAPSHOT"]] +:dependencies [[environ "0.4.0"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll also need the following plugin: ```clojure -:plugins [[lein-environ "0.4.0-SNAPSHOT"]] +:plugins [[lein-environ "0.4.0"]] ``` A good place to put this is in your `profiles.clj` file. diff --git a/environ/project.clj b/environ/project.clj index 119c986..c5be3a3 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ "0.4.0-SNAPSHOT" +(defproject environ "0.4.0" :description "Core environ library for use in applications" :url "https://github.com/weavejester/environ" :license {:name "Eclipse Public License" diff --git a/lein-environ/project.clj b/lein-environ/project.clj index b32b0ab..9c15f10 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject lein-environ "0.4.0-SNAPSHOT" +(defproject lein-environ "0.4.0" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :license {:name "Eclipse Public License" From dd9a29d49173755b0d644879c50b4bb4516d0f04 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 20 Apr 2014 20:44:39 +0100 Subject: [PATCH 09/58] System props now prioritized over environment vars Fixes #7 and introduces small backward incompatibility. Shouldn't affect the vast majority of users. --- environ/src/environ/core.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index 1c3414c..9a0124e 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -33,5 +33,5 @@ env (merge (read-env-file) - (read-system-props) - (read-system-env))) + (read-system-env) + (read-system-props))) From f2c0f0198f3965225e91cb887498af1f3d362604 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 20 Apr 2014 21:16:37 +0100 Subject: [PATCH 10/58] Changed 'def env' to 'defonce env' Should prevent issues with :reload-all and changing .lein-env files. Partially fixes #5. --- environ/src/environ/core.clj | 2 +- environ/test/environ/test/core.clj | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index 9a0124e..c866782 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -29,7 +29,7 @@ (into {} (for [[k v] (read-string (slurp env-file))] [(sanitize k) v]))))) -(def ^{:doc "A map of environment variables."} +(defonce ^{:doc "A map of environment variables."} env (merge (read-env-file) diff --git a/environ/test/environ/test/core.clj b/environ/test/environ/test/core.clj index d90c80e..34ad2c6 100644 --- a/environ/test/environ/test/core.clj +++ b/environ/test/environ/test/core.clj @@ -1,19 +1,28 @@ (ns environ.test.core - (:use clojure.test - environ.core)) + (:use clojure.test) + (:require [environ.core :as e])) + +(defn refresh-ns [] + (ns-unalias *ns* 'e) + (remove-ns 'environ.core) + (dosync (alter @#'clojure.core/*loaded-libs* disj 'environ.core)) + (require '[environ.core :as e])) + +(defn refresh-env [] + (eval `(do (refresh-ns) e/env))) (deftest test-env (testing "env variables" - (is (= (:user env) (System/getenv "USER"))) - (is (= (:java-arch env) (System/getenv "JAVA_ARCH")))) + (is (= (:user e/env) (System/getenv "USER"))) + (is (= (:java-arch e/env) (System/getenv "JAVA_ARCH")))) (testing "system properties" - (is (= (:user-name env) (System/getProperty "user.name"))) - (is (= (:user-country env) (System/getProperty "user.country")))) + (is (= (:user-name e/env) (System/getProperty "user.name"))) + (is (= (:user-country e/env) (System/getProperty "user.country")))) (testing "env file" (spit ".lein-env" (prn-str {:foo "bar"})) - (use 'environ.core :reload) - (is (= (:foo env) "bar"))) + (let [env (refresh-env)] + (is (= (:foo env) "bar")))) (testing "env file with irregular keys" (spit ".lein-env" (prn-str {:foo.bar "baz"})) - (use 'environ.core :reload) - (is (= (:foo-bar env) "baz")))) + (let [env (refresh-env)] + (is (= (:foo-bar env) "baz"))))) From a03b881f7bf58e0467f990bd52f9ac29cdfce073 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 20 Apr 2014 21:18:49 +0100 Subject: [PATCH 11/58] Updated copyright year --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c71b77..7fc89f5 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,6 @@ since this is the standard separator for system properties. ## License -Copyright © 2013 James Reeves +Copyright © 2014 James Reeves Distributed under the Eclipse Public License, the same as Clojure. From 543c87644d09a6c2f6f9c8e1a274cf2ccf405496 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 20 Apr 2014 21:19:54 +0100 Subject: [PATCH 12/58] Added :scm keys to subprojects --- environ/project.clj | 1 + lein-environ/project.clj | 1 + 2 files changed, 2 insertions(+) diff --git a/environ/project.clj b/environ/project.clj index c5be3a3..4bd449d 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,6 +1,7 @@ (defproject environ "0.4.0" :description "Core environ library for use in applications" :url "https://github.com/weavejester/environ" + :scm {:dir ".."} :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.2.1"]]) diff --git a/lein-environ/project.clj b/lein-environ/project.clj index 9c15f10..971d86a 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,6 +1,7 @@ (defproject lein-environ "0.4.0" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" + :scm {:dir ".."} :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :eval-in-leiningen true) From 6ac84109849136c78c9092b55a3dd0dbeaa131e5 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 20 Apr 2014 21:26:48 +0100 Subject: [PATCH 13/58] Updated README documentation --- README.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7fc89f5..077122d 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ # Environ Environ is a Clojure library for managing environment settings from a -number of different sources. +number of different sources. It works well for applications following +the [12 Factor App](http://12factor.net/) pattern. -Currently, Environ supports three sources; environment variables, Java -system properties and the Leiningen project map using the lein-environ -plugin. +Currently, Environ supports three sources, resolved in the following +order: + +1. A `.lein-env` file in the project directory +2. Environment variables +3. Java system properties + +The first source can be set via the "lein-environ" Leiningen plugin, +which dumps the contents of the `:env` key in the project map into +that files. ## Installation @@ -23,8 +31,6 @@ map, you'll also need the following plugin: :plugins [[lein-environ "0.4.0"]] ``` -A good place to put this is in your `profiles.clj` file. - ## Usage @@ -52,7 +58,8 @@ In your application, you can access these values through the ``` You'll likely also want to add `.lein-env` to your `.gitignore` file -(or the equivalent for your version control system). +(or the equivalent for your version control system), if it isn't +covered by an existing rule. When you deploy to a production environment, you can use standard environment variables to configure the same settings. @@ -74,6 +81,8 @@ java -jar app-standalone.jar -Daws.access.key=XX -Daws.secret.key=YY Note in this case that the "-" character has been replace with ".", since this is the standard separator for system properties. +These system properties will override any environment variables. + ## License From fa45d3c07fe8fc28a7b6b0dc38922049925508d0 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 20 Apr 2014 21:54:05 +0100 Subject: [PATCH 14/58] Released 0.5.0 --- README.md | 4 ++-- environ/project.clj | 2 +- lein-environ/project.clj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 077122d..3fdd5a5 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,14 @@ that files. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "0.4.0"]] +:dependencies [[environ "0.5.0"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll also need the following plugin: ```clojure -:plugins [[lein-environ "0.4.0"]] +:plugins [[lein-environ "0.5.0"]] ``` diff --git a/environ/project.clj b/environ/project.clj index 4bd449d..7df361e 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ "0.4.0" +(defproject environ "0.5.0" :description "Core environ library for use in applications" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/lein-environ/project.clj b/lein-environ/project.clj index 971d86a..9a85555 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject lein-environ "0.4.0" +(defproject lein-environ "0.5.0" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From 397a560e9249d946dc989f7840a5ef9d30aa7d1f Mon Sep 17 00:00:00 2001 From: Joe Littlejohn Date: Thu, 24 Apr 2014 16:08:16 +0100 Subject: [PATCH 15/58] Fix message when correcting invalid keys --- environ/src/environ/core.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index c866782..2c01192 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -10,7 +10,7 @@ (defn- sanitize [k] (let [s (keywordize (name k))] - (if-not (= k s) (println "Warning: environ key " k " was has been corrected to " s)) + (if-not (= k s) (println "Warning: environ key " k " has been corrected to " s)) s)) (defn- read-system-env [] From aa08e2c384eb337541736fd7458205a5af1eb1b6 Mon Sep 17 00:00:00 2001 From: "Antoine R. Dumont" Date: Sat, 31 May 2014 10:52:14 +0200 Subject: [PATCH 16/58] Fix order in jvm options in `java -jar` sample - https://github.com/weavejester/environ/issues/12 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fdd5a5..def9339 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ the "-" character has been replaced with "_". You can also use Java system properties: ``` -java -jar app-standalone.jar -Daws.access.key=XX -Daws.secret.key=YY +java -Daws.access.key=XX -Daws.secret.key=YY -jar app-standalone.jar ``` Note in this case that the "-" character has been replace with ".", From c8e9efbf2be8484e49e2a2c3580ebda710d26d1d Mon Sep 17 00:00:00 2001 From: James Reeves Date: Fri, 15 Aug 2014 19:19:18 +0100 Subject: [PATCH 17/58] Update README with better explanation --- README.md | 65 ++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index def9339..44a80e8 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ order: 2. Environment variables 3. Java system properties -The first source can be set via the "lein-environ" Leiningen plugin, +The first source is set via the "lein-environ" Leiningen plugin, which dumps the contents of the `:env` key in the project map into -that files. +that file. ## Installation @@ -32,56 +32,53 @@ map, you'll also need the following plugin: ``` -## Usage +## Example Usage -Let's say you have an application that requires an AWS access key and -secret key. +Let's say you have an application that requires a database connection. +Often you'll need three different databases, one for development, one +for testing, and one for production. -You can use Leiningen's profiles to add this information to your -development environment in your `~/.lein/profiles.clj` file, as it's -likely you'll be using the same AWS account for all development: +Lets pull the database connection details from the key `:database-url` +on the `environ.core/env` map. ```clojure -{:user {:env {:aws-access-key "XXXXXXXXXXXXXXX" - :aws-secret-key "YYYYYYYYYYYYYYYYYYYYYY"}}} +(require '[environ.core :refer [env]]) + +(def database-url + (env :database-url)) ``` -In your application, you can access these values through the -`environ.core/env` map: +The value of this key can be set in several different ways. The most +common way during development is to use a local `profiles.clj` file in +your project directory. This file contained a map that is merged with +the standard `project.clj` file, but can be kept out of version +control and reserved for local development options. ```clojure -(use 'environ.core) - -(def aws-creds - {:access-key (env :aws-access-key) - :secret-key (env :aws-secret-key)}) +{:dev {:env {:database-url "jdbc:postgres://localhost/dev"}} + :test {:env {:database-url "jdbc:postgres://localhost/test"}}} ``` -You'll likely also want to add `.lein-env` to your `.gitignore` file -(or the equivalent for your version control system), if it isn't -covered by an existing rule. +In this case we add a database URL for the dev and test environments. +This means that if you run `lein repl`, the dev database will be used, +and if you run `lein test`, the test database will be used. -When you deploy to a production environment, you can use standard -environment variables to configure the same settings. +When you deploy to a production environment, you can make use of +environment variables, like so: ```bash -AWS_ACCESS_KEY=XXXXXXXXXXXXXXX -AWS_SECRET_KEY=YYYYYYYYYYYYYYYYYYYYYY +DATABASE_URL=jdbc:postgres://localhost/prod java -jar standalone.jar ``` -Notice that the equivalent environment variables are uppercase, and -the "-" character has been replaced with "_". - -You can also use Java system properties: +Or use Java system properties: +```bash +java -Ddatabase.url=jdbc:postgres://localhost/prod -jar standalone.jar ``` -java -Daws.access.key=XX -Daws.secret.key=YY -jar app-standalone.jar -``` - -Note in this case that the "-" character has been replace with ".", -since this is the standard separator for system properties. -These system properties will override any environment variables. +Note that with environment variables, the "-" character is replaced +with the more idiomatic "_" character. Similarly, with system +properties, "-" is replaced with ".". ## License From 9396089da7fd9954f20d66eeeed7162b2b89605f Mon Sep 17 00:00:00 2001 From: James Reeves Date: Fri, 15 Aug 2014 20:15:56 +0100 Subject: [PATCH 18/58] Improve wording of key conversion info in README --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 44a80e8..a8d4924 100644 --- a/README.md +++ b/README.md @@ -76,9 +76,10 @@ Or use Java system properties: java -Ddatabase.url=jdbc:postgres://localhost/prod -jar standalone.jar ``` -Note that with environment variables, the "-" character is replaced -with the more idiomatic "_" character. Similarly, with system -properties, "-" is replaced with ".". +Note that Environ automatically lowercases keys, and replaces the +characters "_" and "." with "-". The environment variable +`DATABASE_URL` and the system property `database.url` are therefore +both converted to the same keyword `:database-url`. ## License From 5ddd7c557eeb1e4040ca28370e3a9d796a36a2a6 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sat, 16 Aug 2014 19:12:37 +0100 Subject: [PATCH 19/58] Release 1.0.0 --- README.md | 4 ++-- environ/project.clj | 4 ++-- lein-environ/project.clj | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a8d4924..df4931d 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,14 @@ that file. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "0.5.0"]] +:dependencies [[environ "1.0.0"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll also need the following plugin: ```clojure -:plugins [[lein-environ "0.5.0"]] +:plugins [[lein-environ "1.0.0"]] ``` diff --git a/environ/project.clj b/environ/project.clj index 7df361e..be70e68 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,5 +1,5 @@ -(defproject environ "0.5.0" - :description "Core environ library for use in applications" +(defproject environ "1.0.0" + :description "Library for accessing environment variables" :url "https://github.com/weavejester/environ" :scm {:dir ".."} :license {:name "Eclipse Public License" diff --git a/lein-environ/project.clj b/lein-environ/project.clj index 9a85555..d120900 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject lein-environ "0.5.0" +(defproject lein-environ "1.0.0" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From 0ce89e44cad94d331f6ff66346c38a7109f9d504 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sat, 3 Jan 2015 16:53:55 +0000 Subject: [PATCH 20/58] Update base Clojure version to 1.5.1 --- environ/project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environ/project.clj b/environ/project.clj index be70e68..889635a 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -4,4 +4,4 @@ :scm {:dir ".."} :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.2.1"]]) + :dependencies [[org.clojure/clojure "1.5.1"]]) From fef7f9e4eed6cdfb24d55a09895aa5c204c2061b Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sat, 3 Jan 2015 23:44:26 +0000 Subject: [PATCH 21/58] Update .gitignore --- .gitignore | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index f15bb5c..4596bb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,9 @@ target -/lib -/classes -/checkouts +classes +checkouts pom.xml pom.xml.asc *.jar *.class -.lein-deps-sum -.lein-failures -.lein-plugins -.lein-env +.lein-* +.nrepl-port From 4796da4787de2dbc35d7121f6a5a92072fd924f6 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 4 Jan 2015 13:47:05 +0000 Subject: [PATCH 22/58] Replace :use with :refer --- environ/test/environ/test/core.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environ/test/environ/test/core.clj b/environ/test/environ/test/core.clj index 34ad2c6..4633f43 100644 --- a/environ/test/environ/test/core.clj +++ b/environ/test/environ/test/core.clj @@ -1,6 +1,6 @@ (ns environ.test.core - (:use clojure.test) - (:require [environ.core :as e])) + (:require [clojure.test :refer :all] + [environ.core :as e])) (defn refresh-ns [] (ns-unalias *ns* 'e) From bd3b894d0b5116c0ab954bac115e19bd3bb7d4d5 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Sun, 4 Jan 2015 13:49:07 +0000 Subject: [PATCH 23/58] Move environ.test.core to environ.core-test --- environ/test/environ/{test/core.clj => core_test.clj} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename environ/test/environ/{test/core.clj => core_test.clj} (97%) diff --git a/environ/test/environ/test/core.clj b/environ/test/environ/core_test.clj similarity index 97% rename from environ/test/environ/test/core.clj rename to environ/test/environ/core_test.clj index 4633f43..369323e 100644 --- a/environ/test/environ/test/core.clj +++ b/environ/test/environ/core_test.clj @@ -1,4 +1,4 @@ -(ns environ.test.core +(ns environ.core-test (:require [clojure.test :refer :all] [environ.core :as e])) From 9775dd7054b1b03cd3eb473710d7838891024669 Mon Sep 17 00:00:00 2001 From: Daniel Szmulewicz Date: Tue, 7 Apr 2015 14:53:24 +0300 Subject: [PATCH 24/58] Add support for Boot --- README.md | 25 +++++++++++++++++++++++++ boot-environ/project.clj | 6 ++++++ boot-environ/src/environ/boot.clj | 10 ++++++++++ 3 files changed, 41 insertions(+) create mode 100644 boot-environ/project.clj create mode 100644 boot-environ/src/environ/boot.clj diff --git a/README.md b/README.md index df4931d..f92e625 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,18 @@ map, you'll also need the following plugin: :plugins [[lein-environ "1.0.0"]] ``` +If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, require the dependency: + +```clojure +:dependencies '[[boot-environ "1.0.0"]] +``` + +Then require the environ boot task. + +```clojure +(require + '[environ.boot :refer [environ]]) +``` ## Example Usage @@ -63,6 +75,19 @@ In this case we add a database URL for the dev and test environments. This means that if you run `lein repl`, the dev database will be used, and if you run `lein test`, the test database will be used. +In the case of Boot, you have the full flexibility of tasks and build pipelines, +meaning that all the following are valid: + +```clojure +$ boot environ -e database-url=jdbc:postgres://localhost/dev repl +``` + +```clojure +(environ :env {:database-url "jdbc:postgres://localhost/dev") +``` + +The latter form can be included in custom pipelines and `task-options!'. + When you deploy to a production environment, you can make use of environment variables, like so: diff --git a/boot-environ/project.clj b/boot-environ/project.clj new file mode 100644 index 0000000..cf7f846 --- /dev/null +++ b/boot-environ/project.clj @@ -0,0 +1,6 @@ +(defproject boot-environ "1.0.0" + :description "Boot task for Environ" + :url "https://github.com/weavejester/environ" + :scm {:dir ".."} + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"}) diff --git a/boot-environ/src/environ/boot.clj b/boot-environ/src/environ/boot.clj new file mode 100644 index 0000000..c9ea7bc --- /dev/null +++ b/boot-environ/src/environ/boot.clj @@ -0,0 +1,10 @@ +(ns environ.boot + {:boot/export-tasks true} + (:require [boot.core :as core] + [environ.core :as environ])) + +(core/deftask environ [e env FOO=BAR {kw edn} "The environment map"] + (fn [next-task] + (fn [fileset] + (with-redefs [environ/env (merge environ/env env)] + (next-task fileset))))) From f606930f05f7c57aea8d048572aa90dc96ca9fc8 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Mon, 13 Jul 2015 17:44:18 +0100 Subject: [PATCH 25/58] Remove unnecessary newline in README example --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index f92e625..be7c5fb 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,7 @@ If you are using the Boot toolchain, you may want to read and write settings fro Then require the environ boot task. ```clojure -(require - '[environ.boot :refer [environ]]) +(require '[environ.boot :refer [environ]]) ``` ## Example Usage From 126b194d1e393cb9ea5d448eaba4ce88b6c66546 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Mon, 13 Jul 2015 18:09:34 +0100 Subject: [PATCH 26/58] Fix environ task value type in boot-environ --- boot-environ/src/environ/boot.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot-environ/src/environ/boot.clj b/boot-environ/src/environ/boot.clj index c9ea7bc..49faeb7 100644 --- a/boot-environ/src/environ/boot.clj +++ b/boot-environ/src/environ/boot.clj @@ -3,7 +3,7 @@ (:require [boot.core :as core] [environ.core :as environ])) -(core/deftask environ [e env FOO=BAR {kw edn} "The environment map"] +(core/deftask environ [e env FOO=BAR {kw str} "The environment map"] (fn [next-task] (fn [fileset] (with-redefs [environ/env (merge environ/env env)] From 8ab8495346f5168f73c997dbf1cfbf2343fbbf64 Mon Sep 17 00:00:00 2001 From: Earl St Sauver Date: Mon, 13 Jul 2015 19:48:37 +0700 Subject: [PATCH 27/58] Fix Typo in Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be7c5fb..69a4d84 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ $ boot environ -e database-url=jdbc:postgres://localhost/dev repl ``` ```clojure -(environ :env {:database-url "jdbc:postgres://localhost/dev") +(environ :env {:database-url "jdbc:postgres://localhost/dev"}) ``` The latter form can be included in custom pipelines and `task-options!'. From ca0d33d2fb74dc432ad1e0aa474229650c854e2b Mon Sep 17 00:00:00 2001 From: James Reeves Date: Mon, 13 Jul 2015 18:20:52 +0100 Subject: [PATCH 28/58] Change boot-environ version to 1.0.0-RC1 --- README.md | 2 +- boot-environ/project.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 69a4d84..3d3add7 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ map, you'll also need the following plugin: If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, require the dependency: ```clojure -:dependencies '[[boot-environ "1.0.0"]] +:dependencies '[[boot-environ "1.0.0-RC1"]] ``` Then require the environ boot task. diff --git a/boot-environ/project.clj b/boot-environ/project.clj index cf7f846..6147a6d 100644 --- a/boot-environ/project.clj +++ b/boot-environ/project.clj @@ -1,4 +1,4 @@ -(defproject boot-environ "1.0.0" +(defproject boot-environ "1.0.0-RC1" :description "Boot task for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From b62f07134f595b8bec8f5e670cc10478a040cb88 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Wed, 9 Sep 2015 09:06:03 +0200 Subject: [PATCH 29/58] Improve test reliability --- environ/test/environ/core_test.clj | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/environ/test/environ/core_test.clj b/environ/test/environ/core_test.clj index 369323e..694d01e 100644 --- a/environ/test/environ/core_test.clj +++ b/environ/test/environ/core_test.clj @@ -1,23 +1,26 @@ (ns environ.core-test (:require [clojure.test :refer :all] - [environ.core :as e])) + [clojure.java.io :as io])) (defn refresh-ns [] - (ns-unalias *ns* 'e) (remove-ns 'environ.core) (dosync (alter @#'clojure.core/*loaded-libs* disj 'environ.core)) - (require '[environ.core :as e])) + (require 'environ.core)) (defn refresh-env [] - (eval `(do (refresh-ns) e/env))) + (refresh-ns) + (var-get (find-var 'environ.core/env))) (deftest test-env + (.delete (io/file ".lein-env")) (testing "env variables" - (is (= (:user e/env) (System/getenv "USER"))) - (is (= (:java-arch e/env) (System/getenv "JAVA_ARCH")))) + (let [env (refresh-env)] + (is (= (:user env) (System/getenv "USER"))) + (is (= (:java-arch env) (System/getenv "JAVA_ARCH"))))) (testing "system properties" - (is (= (:user-name e/env) (System/getProperty "user.name"))) - (is (= (:user-country e/env) (System/getProperty "user.country")))) + (let [env (refresh-env)] + (is (= (:user-name env) (System/getProperty "user.name"))) + (is (= (:user-country env) (System/getProperty "user.country"))))) (testing "env file" (spit ".lein-env" (prn-str {:foo "bar"})) (let [env (refresh-env)] From ba14098752a55677e05186e7047fb8e5cd43800b Mon Sep 17 00:00:00 2001 From: Tim Visher Date: Tue, 8 Sep 2015 11:36:40 -0400 Subject: [PATCH 30/58] Use edn/read-string to read .lein-env Removes a potential arbitrary code evaluation vector. --- environ/src/environ/core.clj | 5 +++-- environ/test/environ/core_test.clj | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index 2c01192..7a0adb8 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -1,5 +1,6 @@ (ns environ.core - (:require [clojure.string :as str] + (:require [clojure.edn :as edn] + [clojure.string :as str] [clojure.java.io :as io])) (defn- keywordize [s] @@ -26,7 +27,7 @@ (defn- read-env-file [] (let [env-file (io/file ".lein-env")] (if (.exists env-file) - (into {} (for [[k v] (read-string (slurp env-file))] + (into {} (for [[k v] (edn/read-string (slurp env-file))] [(sanitize k) v]))))) (defonce ^{:doc "A map of environment variables."} diff --git a/environ/test/environ/core_test.clj b/environ/test/environ/core_test.clj index 694d01e..e950545 100644 --- a/environ/test/environ/core_test.clj +++ b/environ/test/environ/core_test.clj @@ -28,4 +28,7 @@ (testing "env file with irregular keys" (spit ".lein-env" (prn-str {:foo.bar "baz"})) (let [env (refresh-env)] - (is (= (:foo-bar env) "baz"))))) + (is (= (:foo-bar env) "baz")))) + (testing "env file with irregular keys" + (spit ".lein-env" "{:foo #=(str \"bar\" \"baz\")}") + (is (thrown? RuntimeException (refresh-env))))) From b026d218b3aee2da11f62ae24aaf557ee7162548 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Fri, 11 Sep 2015 10:28:39 +0200 Subject: [PATCH 31/58] Release boot-environ 1.0.0 --- README.md | 2 +- boot-environ/project.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3d3add7..69a4d84 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ map, you'll also need the following plugin: If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, require the dependency: ```clojure -:dependencies '[[boot-environ "1.0.0-RC1"]] +:dependencies '[[boot-environ "1.0.0"]] ``` Then require the environ boot task. diff --git a/boot-environ/project.clj b/boot-environ/project.clj index 6147a6d..cf7f846 100644 --- a/boot-environ/project.clj +++ b/boot-environ/project.clj @@ -1,4 +1,4 @@ -(defproject boot-environ "1.0.0-RC1" +(defproject boot-environ "1.0.0" :description "Boot task for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From 692c5874791d75a454772a53014bb2584d3ee04e Mon Sep 17 00:00:00 2001 From: James Reeves Date: Fri, 11 Sep 2015 10:33:04 +0200 Subject: [PATCH 32/58] Release 1.0.1 --- README.md | 6 +++--- boot-environ/project.clj | 2 +- environ/project.clj | 2 +- lein-environ/project.clj | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 69a4d84..8325e16 100644 --- a/README.md +++ b/README.md @@ -21,20 +21,20 @@ that file. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "1.0.0"]] +:dependencies [[environ "1.0.1"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll also need the following plugin: ```clojure -:plugins [[lein-environ "1.0.0"]] +:plugins [[lein-environ "1.0.1"]] ``` If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, require the dependency: ```clojure -:dependencies '[[boot-environ "1.0.0"]] +:dependencies '[[boot-environ "1.0.1"]] ``` Then require the environ boot task. diff --git a/boot-environ/project.clj b/boot-environ/project.clj index cf7f846..155d14c 100644 --- a/boot-environ/project.clj +++ b/boot-environ/project.clj @@ -1,4 +1,4 @@ -(defproject boot-environ "1.0.0" +(defproject boot-environ "1.0.1" :description "Boot task for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/environ/project.clj b/environ/project.clj index 889635a..9be0b07 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ "1.0.0" +(defproject environ "1.0.1" :description "Library for accessing environment variables" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/lein-environ/project.clj b/lein-environ/project.clj index d120900..35d576d 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject lein-environ "1.0.0" +(defproject lein-environ "1.0.1" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From 04fe336f6488c1bc891c5d32353cd587934bbb22 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Fri, 11 Sep 2015 10:46:50 +0200 Subject: [PATCH 33/58] Update README copyright year --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8325e16..02d6950 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,6 @@ both converted to the same keyword `:database-url`. ## License -Copyright © 2014 James Reeves +Copyright © 2015 James Reeves Distributed under the Eclipse Public License, the same as Clojure. From 7790e46b7abfa0e45091afb26a85c1253c291130 Mon Sep 17 00:00:00 2001 From: Charles Loomis Date: Wed, 20 Jan 2016 11:35:28 +0100 Subject: [PATCH 34/58] Make Environ work in Boot pods (fixes #46) --- README.md | 5 +++++ boot-environ/src/environ/boot.clj | 34 +++++++++++++++++++++++++------ environ/src/environ/core.clj | 7 ++++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 02d6950..c0185d2 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,11 @@ $ boot environ -e database-url=jdbc:postgres://localhost/dev repl The latter form can be included in custom pipelines and `task-options!'. +The task also creates or updates a `.boot-env` file in the fileset. +This is useful for tasks that create their own pods like +[boot-test](https://github.com/adzerk-oss/boot-test), which won't +see changes in the environ vars. + When you deploy to a production environment, you can make use of environment variables, like so: diff --git a/boot-environ/src/environ/boot.clj b/boot-environ/src/environ/boot.clj index 49faeb7..d643c8f 100644 --- a/boot-environ/src/environ/boot.clj +++ b/boot-environ/src/environ/boot.clj @@ -1,10 +1,32 @@ (ns environ.boot {:boot/export-tasks true} (:require [boot.core :as core] - [environ.core :as environ])) + [environ.core :as environ] + [clojure.edn :as edn] + [clojure.java.io :as io])) -(core/deftask environ [e env FOO=BAR {kw str} "The environment map"] - (fn [next-task] - (fn [fileset] - (with-redefs [environ/env (merge environ/env env)] - (next-task fileset))))) +(def ^:const env-file ".boot-env") + +(defn- read-boot-env [fileset] + (if-let [t (core/tmp-get fileset env-file)] + (-> t core/tmp-file slurp edn/read-string) + {})) + +(defn- write-boot-env [env tmp] + (spit (io/file tmp env-file) (prn-str env))) + +(defn- update-boot-env + [fileset tmp-dir env] + (doto fileset + (-> (read-boot-env) (merge env) (write-boot-env tmp-dir)) + (-> (core/add-source tmp-dir) (core/commit!)))) + +(core/deftask environ + "Adds key-value pairs to the environment picked up by environ." + [e env FOO=BAR {kw str} "The environment map"] + (let [tmp (core/tmp-dir!)] + (fn environ-middleware [next-task] + (fn environ-handler [fileset] + (core/empty-dir! tmp) + (with-redefs [environ/env (merge environ/env env)] + (next-task (update-boot-env fileset tmp env))))))) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index 7a0adb8..2c39e7a 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -24,8 +24,8 @@ (map (fn [[k v]] [(keywordize k) v])) (into {}))) -(defn- read-env-file [] - (let [env-file (io/file ".lein-env")] +(defn- read-env-file [f] + (if-let [env-file (io/file f)] (if (.exists env-file) (into {} (for [[k v] (edn/read-string (slurp env-file))] [(sanitize k) v]))))) @@ -33,6 +33,7 @@ (defonce ^{:doc "A map of environment variables."} env (merge - (read-env-file) + (read-env-file ".lein-env") + (read-env-file (io/resource ".boot-env")) (read-system-env) (read-system-props))) From 02c55daa82987406ee37965ac6fcf7819c00fb71 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Wed, 27 Jan 2016 18:51:42 +0000 Subject: [PATCH 35/58] Update README with new .boot-env source --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c0185d2..889a48c 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,22 @@ Environ is a Clojure library for managing environment settings from a number of different sources. It works well for applications following the [12 Factor App](http://12factor.net/) pattern. -Currently, Environ supports three sources, resolved in the following +Currently, Environ supports four sources, resolved in the following order: 1. A `.lein-env` file in the project directory -2. Environment variables -3. Java system properties +2. A `.boot-env` file on the classpath +3. Environment variables +4. Java system properties -The first source is set via the "lein-environ" Leiningen plugin, -which dumps the contents of the `:env` key in the project map into -that file. +The first two sources are set by the lein-environ and boot-environ +plugins respectively, and should not be edited manually. + +The `.lein-env` file is populated with the content of the `:env` key +in the Leiningen project map. + +The `.boot-env` file is populated by the `environ.boot/environ` Boot +task. ## Installation From f0f244cf566688ffad799d1859e5455a927566f8 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Wed, 27 Jan 2016 18:53:18 +0000 Subject: [PATCH 36/58] Tweak README formatting and wording --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 889a48c..bfc7d80 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,8 @@ map, you'll also need the following plugin: :plugins [[lein-environ "1.0.1"]] ``` -If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, require the dependency: +If you are using the Boot toolchain, you may want to read and write +settings from build pipelines. In *build.boot*, add the dependency: ```clojure :dependencies '[[boot-environ "1.0.1"]] @@ -49,7 +50,8 @@ Then require the environ boot task. (require '[environ.boot :refer [environ]]) ``` -## Example Usage + +## Usage Let's say you have an application that requires a database connection. Often you'll need three different databases, one for development, one @@ -80,8 +82,8 @@ In this case we add a database URL for the dev and test environments. This means that if you run `lein repl`, the dev database will be used, and if you run `lein test`, the test database will be used. -In the case of Boot, you have the full flexibility of tasks and build pipelines, -meaning that all the following are valid: +In the case of Boot, you have the full flexibility of tasks and build +pipelines, meaning that all the following are valid: ```clojure $ boot environ -e database-url=jdbc:postgres://localhost/dev repl From ed0e074ab4c01675e0fb5699ae0f87648fd2d258 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Wed, 27 Jan 2016 18:55:04 +0000 Subject: [PATCH 37/58] Update copyright year in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bfc7d80..991865f 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,6 @@ both converted to the same keyword `:database-url`. ## License -Copyright © 2015 James Reeves +Copyright © 2016 James Reeves Distributed under the Eclipse Public License, the same as Clojure. From b455dd35bab159a059311c782a9324e99de939e6 Mon Sep 17 00:00:00 2001 From: Tap Date: Tue, 22 Dec 2015 21:52:03 +0700 Subject: [PATCH 38/58] Cast non-string values from env file to string --- environ/src/environ/core.clj | 10 ++++++++-- environ/test/environ/core_test.clj | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index 2c39e7a..6112fe0 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -9,11 +9,17 @@ (str/replace "." "-") (keyword))) -(defn- sanitize [k] +(defn- sanitize-key [k] (let [s (keywordize (name k))] (if-not (= k s) (println "Warning: environ key " k " has been corrected to " s)) s)) +(defn- sanitize-val [v] + (if (string? v) + v + (do (println "Warning: environ value" (pr-str v) "has been cast to string") + (str v)))) + (defn- read-system-env [] (->> (System/getenv) (map (fn [[k v]] [(keywordize k) v])) @@ -28,7 +34,7 @@ (if-let [env-file (io/file f)] (if (.exists env-file) (into {} (for [[k v] (edn/read-string (slurp env-file))] - [(sanitize k) v]))))) + [(sanitize-key k) (sanitize-val v)]))))) (defonce ^{:doc "A map of environment variables."} env diff --git a/environ/test/environ/core_test.clj b/environ/test/environ/core_test.clj index e950545..b9af808 100644 --- a/environ/test/environ/core_test.clj +++ b/environ/test/environ/core_test.clj @@ -31,4 +31,9 @@ (is (= (:foo-bar env) "baz")))) (testing "env file with irregular keys" (spit ".lein-env" "{:foo #=(str \"bar\" \"baz\")}") - (is (thrown? RuntimeException (refresh-env))))) + (is (thrown? RuntimeException (refresh-env)))) + (testing "env file with non-string values" + (spit ".lein-env" (prn-str {:foo 1 :bar :baz})) + (let [env (refresh-env)] + (is (= (:foo env) "1")) + (is (= (:bar env) ":baz"))))) From 39b735db6b0c747ae5804ae15696edb2436bd31e Mon Sep 17 00:00:00 2001 From: James Reeves Date: Wed, 27 Jan 2016 18:59:57 +0000 Subject: [PATCH 39/58] Fix spacing in environ key warning message --- environ/src/environ/core.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index 6112fe0..cffd4c3 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -11,7 +11,7 @@ (defn- sanitize-key [k] (let [s (keywordize (name k))] - (if-not (= k s) (println "Warning: environ key " k " has been corrected to " s)) + (if-not (= k s) (println "Warning: environ key" k "has been corrected to" s)) s)) (defn- sanitize-val [v] From 4ce07ce2044585de2f46573ee362434c1d73543d Mon Sep 17 00:00:00 2001 From: James Reeves Date: Wed, 27 Jan 2016 23:02:03 +0000 Subject: [PATCH 40/58] Release 1.0.2 --- README.md | 6 +++--- boot-environ/project.clj | 2 +- environ/project.clj | 2 +- lein-environ/project.clj | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 991865f..7c36291 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,21 @@ task. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "1.0.1"]] +:dependencies [[environ "1.0.2"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll also need the following plugin: ```clojure -:plugins [[lein-environ "1.0.1"]] +:plugins [[lein-environ "1.0.2"]] ``` If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, add the dependency: ```clojure -:dependencies '[[boot-environ "1.0.1"]] +:dependencies '[[boot-environ "1.0.2"]] ``` Then require the environ boot task. diff --git a/boot-environ/project.clj b/boot-environ/project.clj index 155d14c..67552bc 100644 --- a/boot-environ/project.clj +++ b/boot-environ/project.clj @@ -1,4 +1,4 @@ -(defproject boot-environ "1.0.1" +(defproject boot-environ "1.0.2" :description "Boot task for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/environ/project.clj b/environ/project.clj index 9be0b07..8ff74cf 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ "1.0.1" +(defproject environ "1.0.2" :description "Library for accessing environment variables" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/lein-environ/project.clj b/lein-environ/project.clj index 35d576d..2bcaee2 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject lein-environ "1.0.1" +(defproject lein-environ "1.0.2" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From 6998eda7c0087d24fa7130c758bb32bdfc09190a Mon Sep 17 00:00:00 2001 From: James Reeves Date: Mon, 8 Feb 2016 04:09:46 +0000 Subject: [PATCH 41/58] Add HISTORY.md file (fixes #38) --- HISTORY.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 HISTORY.md diff --git a/HISTORY.md b/HISTORY.md new file mode 100644 index 0000000..6950bb6 --- /dev/null +++ b/HISTORY.md @@ -0,0 +1,12 @@ +## 1.0.2 (2016-01-27) + +* Cast non-string values to strings and output warning +* Fix boot-environ to work with pods + +## 1.0.1 (2014-08-16) + +* Use safer `clojure.edn/read-string` function to read environment files + +## 1.0.0 (2014-08-16) + +* First stable release From cc7029e46479cb8af38d4a2fba86625e0b5efc79 Mon Sep 17 00:00:00 2001 From: Jean Niklas L'orange Date: Fri, 19 Feb 2016 22:21:21 +0100 Subject: [PATCH 42/58] Set *print-xxx* to false when writing env-file --- boot-environ/src/environ/boot.clj | 9 ++++++++- lein-environ/src/lein_environ/plugin.clj | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/boot-environ/src/environ/boot.clj b/boot-environ/src/environ/boot.clj index d643c8f..0b41445 100644 --- a/boot-environ/src/environ/boot.clj +++ b/boot-environ/src/environ/boot.clj @@ -7,13 +7,20 @@ (def ^:const env-file ".boot-env") +(defn- as-edn [& args] + (binding [*print-dup* false + *print-meta* false + *print-length* false + *print-level* false] + (apply prn-str args))) + (defn- read-boot-env [fileset] (if-let [t (core/tmp-get fileset env-file)] (-> t core/tmp-file slurp edn/read-string) {})) (defn- write-boot-env [env tmp] - (spit (io/file tmp env-file) (prn-str env))) + (spit (io/file tmp env-file) (as-edn env))) (defn- update-boot-env [fileset tmp-dir env] diff --git a/lein-environ/src/lein_environ/plugin.clj b/lein-environ/src/lein_environ/plugin.clj index da18965..ac38c5b 100644 --- a/lein-environ/src/lein_environ/plugin.clj +++ b/lein-environ/src/lein_environ/plugin.clj @@ -3,12 +3,19 @@ (:require [clojure.java.io :as io] leiningen.core.main)) +(defn- as-edn [& args] + (binding [*print-dup* false + *print-meta* false + *print-length* false + *print-level* false] + (apply prn-str args))) + (defn env-file [project] (io/file (:root project) ".lein-env")) (defn- write-env-to-file [func task-name project args] - (spit (env-file project) (prn-str (:env project {}))) + (spit (env-file project) (as-edn (:env project {}))) (func task-name project args)) (defn hooks [] - (add-hook #'leiningen.core.main/apply-task #'write-env-to-file)) \ No newline at end of file + (add-hook #'leiningen.core.main/apply-task #'write-env-to-file)) From 1c2a6458df239bc8c8f152d69317bc0ca76a636b Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Fri, 4 Mar 2016 15:29:51 +1300 Subject: [PATCH 43/58] Print key when sanitizing value --- environ/src/environ/core.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index cffd4c3..c28d324 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -14,10 +14,10 @@ (if-not (= k s) (println "Warning: environ key" k "has been corrected to" s)) s)) -(defn- sanitize-val [v] +(defn- sanitize-val [k v] (if (string? v) v - (do (println "Warning: environ value" (pr-str v) "has been cast to string") + (do (println "Warning: environ value" (pr-str v) "for key" k "has been cast to string") (str v)))) (defn- read-system-env [] @@ -34,7 +34,7 @@ (if-let [env-file (io/file f)] (if (.exists env-file) (into {} (for [[k v] (edn/read-string (slurp env-file))] - [(sanitize-key k) (sanitize-val v)]))))) + [(sanitize-key k) (sanitize-val k v)]))))) (defonce ^{:doc "A map of environment variables."} env From 0797e4e55dd4837b2a55a5e35acc521fb9b48d83 Mon Sep 17 00:00:00 2001 From: David Haslem Date: Wed, 27 Apr 2016 23:19:58 -0700 Subject: [PATCH 44/58] Ensure updated fileset is returned (fixes #56) --- boot-environ/src/environ/boot.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boot-environ/src/environ/boot.clj b/boot-environ/src/environ/boot.clj index 0b41445..322e8e9 100644 --- a/boot-environ/src/environ/boot.clj +++ b/boot-environ/src/environ/boot.clj @@ -24,9 +24,9 @@ (defn- update-boot-env [fileset tmp-dir env] - (doto fileset - (-> (read-boot-env) (merge env) (write-boot-env tmp-dir)) - (-> (core/add-source tmp-dir) (core/commit!)))) + (do + (-> fileset (read-boot-env) (merge env) (write-boot-env tmp-dir)) + (-> fileset (core/add-source tmp-dir) (core/commit!)))) (core/deftask environ "Adds key-value pairs to the environment picked up by environ." From 072ef5e391a52f6c94b93f5e04f86f5ab818c3c7 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Fri, 6 May 2016 15:34:04 +0100 Subject: [PATCH 45/58] Release 1.0.3 --- HISTORY.md | 6 ++++++ README.md | 6 +++--- boot-environ/project.clj | 2 +- environ/project.clj | 2 +- lein-environ/project.clj | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 6950bb6..502e907 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,9 @@ +## 1.0.3 (2016-05--06) + +* Fix boot-environ to return updated fileset +* Print key when santizing value for easier debugging +* Set `*print-xxx*` vars to false when writing env-file + ## 1.0.2 (2016-01-27) * Cast non-string values to strings and output warning diff --git a/README.md b/README.md index 7c36291..d02651e 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,21 @@ task. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "1.0.2"]] +:dependencies [[environ "1.0.3"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll also need the following plugin: ```clojure -:plugins [[lein-environ "1.0.2"]] +:plugins [[lein-environ "1.0.3"]] ``` If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, add the dependency: ```clojure -:dependencies '[[boot-environ "1.0.2"]] +:dependencies '[[boot-environ "1.0.3"]] ``` Then require the environ boot task. diff --git a/boot-environ/project.clj b/boot-environ/project.clj index 67552bc..9dc150f 100644 --- a/boot-environ/project.clj +++ b/boot-environ/project.clj @@ -1,4 +1,4 @@ -(defproject boot-environ "1.0.2" +(defproject boot-environ "1.0.3" :description "Boot task for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/environ/project.clj b/environ/project.clj index 8ff74cf..ee97bf8 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ "1.0.2" +(defproject environ "1.0.3" :description "Library for accessing environment variables" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/lein-environ/project.clj b/lein-environ/project.clj index 2bcaee2..b28f98b 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject lein-environ "1.0.2" +(defproject lein-environ "1.0.3" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From f6a302975d6b79d600e7daef0422736f83188a38 Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Mon, 25 Jul 2016 14:29:10 +1200 Subject: [PATCH 46/58] Replace :project namespaced keywords with value from project.clj This replicates the equivalent functionality in Leiningen, where keywords like :project/version are replaced with the value of the key :version from the project map. --- README.md | 12 ++++++++++-- lein-environ/src/lein_environ/plugin.clj | 13 ++++++++++++- lein-environ/test/lein_environ/plugin_test.clj | 11 +++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 lein-environ/test/lein_environ/plugin_test.clj diff --git a/README.md b/README.md index d02651e..e451a4e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,15 @@ The first two sources are set by the lein-environ and boot-environ plugins respectively, and should not be edited manually. The `.lein-env` file is populated with the content of the `:env` key -in the Leiningen project map. +in the Leiningen project map. Keywords with a `project` namespace are +looked up in the project map. For example: + +```clojure +{:env {:app-version :project/version}} +``` + +This looks up the `:version` key in the Leiningen project map. You can view +the full project map by using [lein-pprint](https://github.com/technomancy/leiningen/tree/master/lein-pprint). The `.boot-env` file is populated by the `environ.boot/environ` Boot task. @@ -96,7 +104,7 @@ $ boot environ -e database-url=jdbc:postgres://localhost/dev repl The latter form can be included in custom pipelines and `task-options!'. The task also creates or updates a `.boot-env` file in the fileset. -This is useful for tasks that create their own pods like +This is useful for tasks that create their own pods like [boot-test](https://github.com/adzerk-oss/boot-test), which won't see changes in the environ vars. diff --git a/lein-environ/src/lein_environ/plugin.clj b/lein-environ/src/lein_environ/plugin.clj index ac38c5b..65b2176 100644 --- a/lein-environ/src/lein_environ/plugin.clj +++ b/lein-environ/src/lein_environ/plugin.clj @@ -10,11 +10,22 @@ *print-level* false] (apply prn-str args))) +(defn- map-vals [f m] + (reduce-kv #(assoc %1 %2 (f %3)) {} m)) + +(defn- replace-project-keyword [value project] + (if (and (keyword? value) (= (namespace value) "project")) + (project (keyword (name value))) + value)) + +(defn read-env [project] + (map-vals #(replace-project-keyword % project) (:env project {}))) + (defn env-file [project] (io/file (:root project) ".lein-env")) (defn- write-env-to-file [func task-name project args] - (spit (env-file project) (as-edn (:env project {}))) + (spit (env-file project) (as-edn (read-env project))) (func task-name project args)) (defn hooks [] diff --git a/lein-environ/test/lein_environ/plugin_test.clj b/lein-environ/test/lein_environ/plugin_test.clj new file mode 100644 index 0000000..a72e938 --- /dev/null +++ b/lein-environ/test/lein_environ/plugin_test.clj @@ -0,0 +1,11 @@ +(ns lein-environ.plugin-test + (:require [clojure.test :refer :all] + [lein-environ.plugin :as l])) + +(deftest replace-project-keyword-test + (are [expected project] (= expected (l/read-env project)) + {:app-version "1.0.0", :test-version :version} + {:version "1.0.0", :env {:app-version :project/version :test-version :version}} + + {:foo "bar"} + {:env {:foo "bar"}})) From e97912294d0f21d31af7767f46fba5963d83d761 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Thu, 4 Aug 2016 14:30:36 +0100 Subject: [PATCH 47/58] Release 1.1.0 --- HISTORY.md | 6 +++++- README.md | 6 +++--- boot-environ/project.clj | 2 +- environ/project.clj | 2 +- lein-environ/project.clj | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 502e907..eb325c1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,4 +1,8 @@ -## 1.0.3 (2016-05--06) +## 1.1.0 (2016-08-04) + +* Replace `:project/foo` keywords with the value of `:foo` key in project map + +## 1.0.3 (2016-05-06) * Fix boot-environ to return updated fileset * Print key when santizing value for easier debugging diff --git a/README.md b/README.md index e451a4e..b91096b 100644 --- a/README.md +++ b/README.md @@ -35,21 +35,21 @@ task. Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "1.0.3"]] +:dependencies [[environ "1.1.0"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll also need the following plugin: ```clojure -:plugins [[lein-environ "1.0.3"]] +:plugins [[lein-environ "1.1.0"]] ``` If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, add the dependency: ```clojure -:dependencies '[[boot-environ "1.0.3"]] +:dependencies '[[boot-environ "1.1.0"]] ``` Then require the environ boot task. diff --git a/boot-environ/project.clj b/boot-environ/project.clj index 9dc150f..8a27e8d 100644 --- a/boot-environ/project.clj +++ b/boot-environ/project.clj @@ -1,4 +1,4 @@ -(defproject boot-environ "1.0.3" +(defproject boot-environ "1.1.0" :description "Boot task for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/environ/project.clj b/environ/project.clj index ee97bf8..7f251cf 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ "1.0.3" +(defproject environ "1.1.0" :description "Library for accessing environment variables" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/lein-environ/project.clj b/lein-environ/project.clj index b28f98b..85b602f 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject lein-environ "1.0.3" +(defproject lein-environ "1.1.0" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From 275de0651411871e1da739ed1bdda90b55a2e4a0 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Thu, 4 Aug 2016 15:30:05 +0100 Subject: [PATCH 48/58] Rearrange information in README a little --- README.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b91096b..7bf3164 100644 --- a/README.md +++ b/README.md @@ -16,18 +16,8 @@ The first two sources are set by the lein-environ and boot-environ plugins respectively, and should not be edited manually. The `.lein-env` file is populated with the content of the `:env` key -in the Leiningen project map. Keywords with a `project` namespace are -looked up in the project map. For example: - -```clojure -{:env {:app-version :project/version}} -``` - -This looks up the `:version` key in the Leiningen project map. You can view -the full project map by using [lein-pprint](https://github.com/technomancy/leiningen/tree/master/lein-pprint). - -The `.boot-env` file is populated by the `environ.boot/environ` Boot -task. +in the Leiningen project map. The `.boot-env` file is populated by the +`environ.boot/environ` Boot task. ## Installation @@ -90,6 +80,16 @@ In this case we add a database URL for the dev and test environments. This means that if you run `lein repl`, the dev database will be used, and if you run `lein test`, the test database will be used. +Keywords with a `project` namespace are looked up in the project +map. For example: + +```clojure +{:env {:app-version :project/version}} +``` + +This looks up the `:version` key in the Leiningen project map. You can +view the full project map by using [lein-pprint][]. + In the case of Boot, you have the full flexibility of tasks and build pipelines, meaning that all the following are valid: @@ -105,8 +105,7 @@ The latter form can be included in custom pipelines and `task-options!'. The task also creates or updates a `.boot-env` file in the fileset. This is useful for tasks that create their own pods like -[boot-test](https://github.com/adzerk-oss/boot-test), which won't -see changes in the environ vars. +[boot-test][], which won't see changes in the environ vars. When you deploy to a production environment, you can make use of environment variables, like so: @@ -126,6 +125,9 @@ characters "_" and "." with "-". The environment variable `DATABASE_URL` and the system property `database.url` are therefore both converted to the same keyword `:database-url`. +[lein-pprint]: https://github.com/technomancy/leiningen/tree/master/lein-pprint +[boot-test]: https://github.com/adzerk-oss/boot-test + ## License From 153817436783e12f68a7dd8ff694bcc4142b0ff4 Mon Sep 17 00:00:00 2001 From: Andre Helberg Date: Sat, 15 Oct 2016 09:32:58 +0200 Subject: [PATCH 49/58] Fix PostgreSQL URLs in README --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7bf3164..2457086 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,8 @@ the standard `project.clj` file, but can be kept out of version control and reserved for local development options. ```clojure -{:dev {:env {:database-url "jdbc:postgres://localhost/dev"}} - :test {:env {:database-url "jdbc:postgres://localhost/test"}}} +{:dev {:env {:database-url "jdbc:postgresql://localhost/dev"}} + :test {:env {:database-url "jdbc:postgresql://localhost/test"}}} ``` In this case we add a database URL for the dev and test environments. @@ -94,11 +94,11 @@ In the case of Boot, you have the full flexibility of tasks and build pipelines, meaning that all the following are valid: ```clojure -$ boot environ -e database-url=jdbc:postgres://localhost/dev repl +$ boot environ -e database-url=jdbc:postgresql://localhost/dev repl ``` ```clojure -(environ :env {:database-url "jdbc:postgres://localhost/dev"}) +(environ :env {:database-url "jdbc:postgresql://localhost/dev"}) ``` The latter form can be included in custom pipelines and `task-options!'. @@ -111,13 +111,13 @@ When you deploy to a production environment, you can make use of environment variables, like so: ```bash -DATABASE_URL=jdbc:postgres://localhost/prod java -jar standalone.jar +DATABASE_URL=jdbc:postgresql://localhost/prod java -jar standalone.jar ``` Or use Java system properties: ```bash -java -Ddatabase.url=jdbc:postgres://localhost/prod -jar standalone.jar +java -Ddatabase.url=jdbc:postgresql://localhost/prod -jar standalone.jar ``` Note that Environ automatically lowercases keys, and replaces the From 75c4584e2954a041835a3cb97de4a09883a80041 Mon Sep 17 00:00:00 2001 From: Marcus Spiegel Date: Tue, 16 Jan 2018 19:34:07 +0100 Subject: [PATCH 50/58] Print warning if environ values are overwritten --- environ/src/environ/core.clj | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj index c28d324..e5de6b3 100644 --- a/environ/src/environ/core.clj +++ b/environ/src/environ/core.clj @@ -36,9 +36,20 @@ (into {} (for [[k v] (edn/read-string (slurp env-file))] [(sanitize-key k) (sanitize-val k v)]))))) +(defn- warn-on-overwrite [ms] + (doseq [[k kvs] (group-by key (apply concat ms)) + :let [vs (map val kvs)] + :when (and (next kvs) (not= (first vs) (last vs)))] + (println "Warning: environ value" (first vs) "for key" k + "has been overwritten with" (last vs)))) + +(defn- merge-env [& ms] + (warn-on-overwrite ms) + (apply merge ms)) + (defonce ^{:doc "A map of environment variables."} env - (merge + (merge-env (read-env-file ".lein-env") (read-env-file (io/resource ".boot-env")) (read-system-env) From a215249630a4802e42cebbabf98249aa88b121a5 Mon Sep 17 00:00:00 2001 From: Ken Kantzer Date: Tue, 8 May 2018 16:41:41 -0700 Subject: [PATCH 51/58] Update README for creating composite profiles --- README.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2457086..83e24fe 100644 --- a/README.md +++ b/README.md @@ -67,9 +67,9 @@ on the `environ.core/env` map. The value of this key can be set in several different ways. The most common way during development is to use a local `profiles.clj` file in -your project directory. This file contained a map that is merged with -the standard `project.clj` file, but can be kept out of version -control and reserved for local development options. +your project directory. This file contains a map with profiles that will +be merged with the profiles specified in the standard `project.clj`, but +can be kept out of version control and reserved for local development options. ```clojure {:dev {:env {:database-url "jdbc:postgresql://localhost/dev"}} @@ -80,6 +80,24 @@ In this case we add a database URL for the dev and test environments. This means that if you run `lein repl`, the dev database will be used, and if you run `lein test`, the test database will be used. +So that profiles you define in `profiles.clj` are merged into, rather than +replacing profiles defined in `project.clj`, a composite profile can be +created in `project.clj`: + +```clojure +:profiles {:dev [:project/dev :profiles/dev] + :test [:project/test :profiles/test] + ;; only edit :profiles/* in profiles.clj + :profiles/dev {} + :profiles/test {} + :project/dev {:source-paths ["src" "tool-src"] + :dependencies [[midje "1.6.3"]] + :plugins [[lein-auto "0.1.3"]]} + :project/test {}} +``` + +And then use the `:profiles/dev` key in your `profiles.clj`. + Keywords with a `project` namespace are looked up in the project map. For example: From e268fcaf2c4a910a360cae556bd5d0504a18ab51 Mon Sep 17 00:00:00 2001 From: micah Date: Sun, 26 Aug 2018 08:42:29 -0400 Subject: [PATCH 52/58] Update README with uberjar and project.clj info --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 83e24fe..0008cb3 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,10 @@ both converted to the same keyword `:database-url`. [lein-pprint]: https://github.com/technomancy/leiningen/tree/master/lein-pprint [boot-test]: https://github.com/adzerk-oss/boot-test +*Important* -- environ will not pick up configuration settings from the +`project.clj` when called from a compiled uberjar. So for any compiled +code you produce with `lein uberjar`, you will want to set your +configuration values via shell environment and/or system properties. ## License From ddfc75e3f800805d7a57e2bafd16afd119d962e8 Mon Sep 17 00:00:00 2001 From: r0man Date: Mon, 10 Dec 2018 18:23:52 +0100 Subject: [PATCH 53/58] Add support for Node.js --- .gitignore | 2 + environ/project.clj | 27 ++++++++- environ/src/environ/core.clj | 56 ------------------ environ/src/environ/core.cljc | 81 +++++++++++++++++++++++++++ environ/test/environ/core_test.clj | 39 ------------- environ/test/environ/core_test.cljc | 64 +++++++++++++++++++++ environ/test/environ/test/runner.cljs | 5 ++ 7 files changed, 178 insertions(+), 96 deletions(-) delete mode 100644 environ/src/environ/core.clj create mode 100644 environ/src/environ/core.cljc delete mode 100644 environ/test/environ/core_test.clj create mode 100644 environ/test/environ/core_test.cljc create mode 100644 environ/test/environ/test/runner.cljs diff --git a/.gitignore b/.gitignore index 4596bb4..02f7d37 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ pom.xml.asc *.class .lein-* .nrepl-port +environ/.cljs_node_repl +environ/out/ diff --git a/environ/project.clj b/environ/project.clj index 7f251cf..528110d 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -4,4 +4,29 @@ :scm {:dir ".."} :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.5.1"]]) + :dependencies [[org.clojure/clojure "1.8.0"]] + :profiles {:provided {:dependencies [[org.clojure/clojurescript "1.10.439"]]}} + :plugins [[lein-cljsbuild "1.1.7"] + [lein-doo "0.1.10"]] + :aliases + {"ci" ["do" + ["clean"] + ["test"] + ["doo" "node" "test-nodejs" "once"] + ["doo" "nashorn" "test-nashorn" "once"]]} + :cljsbuild + {:builds + [{:id "test-nashorn" + :compiler + {:main environ.test.runner + :optimizations :simple + :output-dir "target/test-nashorn" + :output-to "target/environ.test.nashorn.js"} + :source-paths ["src" "test"]} + {:id "test-nodejs" + :compiler + {:main environ.test.runner + :output-dir "target/test-nodejs" + :output-to "target/environ.test.nodejs.js" + :target :nodejs} + :source-paths ["src" "test"]}]}) diff --git a/environ/src/environ/core.clj b/environ/src/environ/core.clj deleted file mode 100644 index e5de6b3..0000000 --- a/environ/src/environ/core.clj +++ /dev/null @@ -1,56 +0,0 @@ -(ns environ.core - (:require [clojure.edn :as edn] - [clojure.string :as str] - [clojure.java.io :as io])) - -(defn- keywordize [s] - (-> (str/lower-case s) - (str/replace "_" "-") - (str/replace "." "-") - (keyword))) - -(defn- sanitize-key [k] - (let [s (keywordize (name k))] - (if-not (= k s) (println "Warning: environ key" k "has been corrected to" s)) - s)) - -(defn- sanitize-val [k v] - (if (string? v) - v - (do (println "Warning: environ value" (pr-str v) "for key" k "has been cast to string") - (str v)))) - -(defn- read-system-env [] - (->> (System/getenv) - (map (fn [[k v]] [(keywordize k) v])) - (into {}))) - -(defn- read-system-props [] - (->> (System/getProperties) - (map (fn [[k v]] [(keywordize k) v])) - (into {}))) - -(defn- read-env-file [f] - (if-let [env-file (io/file f)] - (if (.exists env-file) - (into {} (for [[k v] (edn/read-string (slurp env-file))] - [(sanitize-key k) (sanitize-val k v)]))))) - -(defn- warn-on-overwrite [ms] - (doseq [[k kvs] (group-by key (apply concat ms)) - :let [vs (map val kvs)] - :when (and (next kvs) (not= (first vs) (last vs)))] - (println "Warning: environ value" (first vs) "for key" k - "has been overwritten with" (last vs)))) - -(defn- merge-env [& ms] - (warn-on-overwrite ms) - (apply merge ms)) - -(defonce ^{:doc "A map of environment variables."} - env - (merge-env - (read-env-file ".lein-env") - (read-env-file (io/resource ".boot-env")) - (read-system-env) - (read-system-props))) diff --git a/environ/src/environ/core.cljc b/environ/src/environ/core.cljc new file mode 100644 index 0000000..7692b51 --- /dev/null +++ b/environ/src/environ/core.cljc @@ -0,0 +1,81 @@ +(ns environ.core + (:require #?(:clj [clojure.edn :as edn] :cljs [cljs.reader :as edn]) + #?(:clj [clojure.java.io :as io]) + #?(:cljs [goog.object :as obj]) + [clojure.string :as str])) + +#?(:cljs (def ^:private nodejs? + (exists? js/require))) + +#?(:cljs (def ^:private fs + (when nodejs? (js/require "fs")))) + +#?(:cljs (def ^:private process + (when nodejs? (js/require "process")))) + +(defn- keywordize [s] + (-> (str/lower-case s) + (str/replace "_" "-") + (str/replace "." "-") + (keyword))) + +(defn- sanitize-key [k] + (let [s (keywordize (name k))] + (if-not (= k s) (println "Warning: environ key" k "has been corrected to" s)) + s)) + +(defn- sanitize-val [k v] + (if (string? v) + v + (do (println "Warning: environ value" (pr-str v) "for key" k "has been cast to string") + (str v)))) + +(defn- read-system-env [] + (->> #?(:clj (System/getenv) + :cljs (zipmap (obj/getKeys (.-env process)) + (obj/getValues (.-env process)))) + (map (fn [[k v]] [(keywordize k) v])) + (into {}))) + +#?(:clj (defn- read-system-props [] + (->> (System/getProperties) + (map (fn [[k v]] [(keywordize k) v])) + (into {})))) + +(defn- slurp-file [f] + #?(:clj (when-let [f (io/file f)] + (when (.exists f) + (slurp f))) + :cljs (when (.existsSync fs f) + (str (.readFileSync fs f))))) + +(defn- read-env-file [f] + (when-let [content (slurp-file f)] + (into {} (for [[k v] (edn/read-string content)] + [(sanitize-key k) (sanitize-val k v)])))) + +(defn- warn-on-overwrite [ms] + (doseq [[k kvs] (group-by key (apply concat ms)) + :let [vs (map val kvs)] + :when (and (next kvs) (not= (first vs) (last vs)))] + (println "Warning: environ value" (first vs) "for key" k + "has been overwritten with" (last vs)))) + +(defn- merge-env [& ms] + (warn-on-overwrite ms) + (apply merge ms)) + +(defn- read-env [] + #?(:clj (merge-env + (read-env-file ".lein-env") + (read-env-file (io/resource ".boot-env")) + (read-system-env) + (read-system-props)) + :cljs (if nodejs? + (merge-env + (read-env-file ".lein-env") + (read-system-env)) + {}))) + +(defonce ^{:doc "A map of environment variables."} + env (read-env)) diff --git a/environ/test/environ/core_test.clj b/environ/test/environ/core_test.clj deleted file mode 100644 index b9af808..0000000 --- a/environ/test/environ/core_test.clj +++ /dev/null @@ -1,39 +0,0 @@ -(ns environ.core-test - (:require [clojure.test :refer :all] - [clojure.java.io :as io])) - -(defn refresh-ns [] - (remove-ns 'environ.core) - (dosync (alter @#'clojure.core/*loaded-libs* disj 'environ.core)) - (require 'environ.core)) - -(defn refresh-env [] - (refresh-ns) - (var-get (find-var 'environ.core/env))) - -(deftest test-env - (.delete (io/file ".lein-env")) - (testing "env variables" - (let [env (refresh-env)] - (is (= (:user env) (System/getenv "USER"))) - (is (= (:java-arch env) (System/getenv "JAVA_ARCH"))))) - (testing "system properties" - (let [env (refresh-env)] - (is (= (:user-name env) (System/getProperty "user.name"))) - (is (= (:user-country env) (System/getProperty "user.country"))))) - (testing "env file" - (spit ".lein-env" (prn-str {:foo "bar"})) - (let [env (refresh-env)] - (is (= (:foo env) "bar")))) - (testing "env file with irregular keys" - (spit ".lein-env" (prn-str {:foo.bar "baz"})) - (let [env (refresh-env)] - (is (= (:foo-bar env) "baz")))) - (testing "env file with irregular keys" - (spit ".lein-env" "{:foo #=(str \"bar\" \"baz\")}") - (is (thrown? RuntimeException (refresh-env)))) - (testing "env file with non-string values" - (spit ".lein-env" (prn-str {:foo 1 :bar :baz})) - (let [env (refresh-env)] - (is (= (:foo env) "1")) - (is (= (:bar env) ":baz"))))) diff --git a/environ/test/environ/core_test.cljc b/environ/test/environ/core_test.cljc new file mode 100644 index 0000000..9ce376a --- /dev/null +++ b/environ/test/environ/core_test.cljc @@ -0,0 +1,64 @@ +(ns environ.core-test + (:require #?(:clj [clojure.java.io :as io]) + #?(:cljs [goog.object :as obj]) + [clojure.test :refer [deftest is testing]] + [environ.core :as environ])) + +#?(:cljs (def nodejs? (exists? js/require))) +#?(:cljs (def fs (when nodejs? (js/require "fs")))) +#?(:cljs (def process (when nodejs? (js/require "process")))) + +(defn- delete-file [f] + #?(:clj (.delete (io/file f)) + :cljs (when (.existsSync fs f) + (.unlinkSync fs f)))) + +(defn- get-env [x] + #?(:clj (System/getenv x) + :cljs (obj/get (.-env process) x))) + +#?(:clj (defn refresh-ns [] + (remove-ns 'environ.core) + (dosync (alter @#'clojure.core/*loaded-libs* disj 'environ.core)) + (require 'environ.core))) + +#?(:clj (defn refresh-env [] + (refresh-ns) + (var-get (find-var 'environ.core/env)))) + +#?(:cljs (defn refresh-env [] + (set! environ/env (environ/read-env)) + environ/env)) + +#?(:cljs (defn- spit [f data] + (.writeFileSync fs f data))) + +(deftest test-env + (if #?(:clj true :cljs nodejs?) + (testing "JVM and Node.js environment" + (testing "env variables" + (let [env (refresh-env)] + (is (= (:user env) (get-env "USER"))) + (is (= (:java-arch env) (get-env "JAVA_ARCH"))))) + #?(:clj (testing "system properties" + (let [env (refresh-env)] + (is (= (:user-name env) (System/getProperty "user.name"))) + (is (= (:user-country env) (System/getProperty "user.country")))))) + (testing "env file" + (spit ".lein-env" (prn-str {:foo "bar"})) + (let [env (refresh-env)] + (is (= (:foo env) "bar")))) + (testing "env file with irregular keys" + (spit ".lein-env" (prn-str {:foo.bar "baz"})) + (let [env (refresh-env)] + (is (= (:foo-bar env) "baz")))) + (testing "env file with irregular keys" + (spit ".lein-env" "{:foo #=(str \"bar\" \"baz\")}") + (is (thrown? #?(:clj RuntimeException :cljs js/Error) (refresh-env)))) + (testing "env file with non-string values" + (spit ".lein-env" (prn-str {:foo 1 :bar :baz})) + (let [env (refresh-env)] + (is (= (:foo env) "1")) + (is (= (:bar env) ":baz"))))) + (testing "non Node.js environment" + (is (= environ/env {}))))) diff --git a/environ/test/environ/test/runner.cljs b/environ/test/environ/test/runner.cljs new file mode 100644 index 0000000..ca08446 --- /dev/null +++ b/environ/test/environ/test/runner.cljs @@ -0,0 +1,5 @@ +(ns environ.test.runner + (:require [doo.runner :refer-macros [doo-tests]] + [environ.core-test])) + +(doo-tests 'environ.core-test) From 729951c3a1ffcd0c99f209425295dd0b171ddf46 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Tue, 5 May 2020 22:14:22 +0100 Subject: [PATCH 54/58] Rename HISTORY.md to CHANGELOG.md --- HISTORY.md => CHANGELOG.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename HISTORY.md => CHANGELOG.md (100%) diff --git a/HISTORY.md b/CHANGELOG.md similarity index 100% rename from HISTORY.md rename to CHANGELOG.md From 99fdf0dced72f7a01326cc9a0937f6f40172ab41 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Tue, 5 May 2020 22:14:54 +0100 Subject: [PATCH 55/58] Update copyright year in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0008cb3..22f738d 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,6 @@ configuration values via shell environment and/or system properties. ## License -Copyright © 2016 James Reeves +Copyright © 2020 James Reeves Distributed under the Eclipse Public License, the same as Clojure. From 715eb5483fd6d50d7cad8f7532020c32ffe442d1 Mon Sep 17 00:00:00 2001 From: James Reeves Date: Tue, 5 May 2020 22:30:05 +0100 Subject: [PATCH 56/58] Release 1.2.0 --- CHANGELOG.md | 4 ++++ README.md | 6 +++--- boot-environ/project.clj | 2 +- environ/project.clj | 2 +- lein-environ/project.clj | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb325c1..ee4a6da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.0 (2020-05-05) + +* Add support for ClojureScript on node.js (#87) + ## 1.1.0 (2016-08-04) * Replace `:project/foo` keywords with the value of `:foo` key in project map diff --git a/README.md b/README.md index 22f738d..42486a9 100644 --- a/README.md +++ b/README.md @@ -25,21 +25,21 @@ in the Leiningen project map. The `.boot-env` file is populated by the Include the following dependency in your `project.clj` file: ```clojure -:dependencies [[environ "1.1.0"]] +:dependencies [[environ "1.2.0"]] ``` If you want to be able to draw settings from the Leiningen project map, you'll also need the following plugin: ```clojure -:plugins [[lein-environ "1.1.0"]] +:plugins [[lein-environ "1.2.0"]] ``` If you are using the Boot toolchain, you may want to read and write settings from build pipelines. In *build.boot*, add the dependency: ```clojure -:dependencies '[[boot-environ "1.1.0"]] +:dependencies '[[boot-environ "1.2.0"]] ``` Then require the environ boot task. diff --git a/boot-environ/project.clj b/boot-environ/project.clj index 8a27e8d..12a068d 100644 --- a/boot-environ/project.clj +++ b/boot-environ/project.clj @@ -1,4 +1,4 @@ -(defproject boot-environ "1.1.0" +(defproject boot-environ "1.2.0" :description "Boot task for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/environ/project.clj b/environ/project.clj index 528110d..80782f0 100644 --- a/environ/project.clj +++ b/environ/project.clj @@ -1,4 +1,4 @@ -(defproject environ "1.1.0" +(defproject environ "1.2.0" :description "Library for accessing environment variables" :url "https://github.com/weavejester/environ" :scm {:dir ".."} diff --git a/lein-environ/project.clj b/lein-environ/project.clj index 85b602f..b017a86 100644 --- a/lein-environ/project.clj +++ b/lein-environ/project.clj @@ -1,4 +1,4 @@ -(defproject lein-environ "1.1.0" +(defproject lein-environ "1.2.0" :description "Leiningen plugin for Environ" :url "https://github.com/weavejester/environ" :scm {:dir ".."} From b30c1418e7f22ceca0ed71c16bed4e5922a3d9ad Mon Sep 17 00:00:00 2001 From: Sergey Kozachenko Date: Mon, 12 Jul 2021 14:43:16 +0300 Subject: [PATCH 57/58] Fix advanced compilation issue Signed-off-by: SergeyKozachenko --- environ/src/environ/core.cljc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environ/src/environ/core.cljc b/environ/src/environ/core.cljc index 7692b51..09073b8 100644 --- a/environ/src/environ/core.cljc +++ b/environ/src/environ/core.cljc @@ -46,8 +46,8 @@ #?(:clj (when-let [f (io/file f)] (when (.exists f) (slurp f))) - :cljs (when (.existsSync fs f) - (str (.readFileSync fs f))))) + :cljs (when ^js (.existsSync fs f) + (str ^js (.readFileSync fs f))))) (defn- read-env-file [f] (when-let [content (slurp-file f)] From cc935685b101839fa49324a0e509d1e06b4c3c74 Mon Sep 17 00:00:00 2001 From: Daniel Matysiak Date: Thu, 26 Aug 2021 16:55:57 -0400 Subject: [PATCH 58/58] Print warnings to STDERR to avoid polluting STDOUT --- environ/src/environ/core.cljc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/environ/src/environ/core.cljc b/environ/src/environ/core.cljc index 09073b8..9f98bd9 100644 --- a/environ/src/environ/core.cljc +++ b/environ/src/environ/core.cljc @@ -13,6 +13,10 @@ #?(:cljs (def ^:private process (when nodejs? (js/require "process")))) +(defn- printerr [& more] + (binding [*out* *err*] + (apply println more))) + (defn- keywordize [s] (-> (str/lower-case s) (str/replace "_" "-") @@ -21,13 +25,13 @@ (defn- sanitize-key [k] (let [s (keywordize (name k))] - (if-not (= k s) (println "Warning: environ key" k "has been corrected to" s)) + (if-not (= k s) (printerr "Warning: environ key" k "has been corrected to" s)) s)) (defn- sanitize-val [k v] (if (string? v) v - (do (println "Warning: environ value" (pr-str v) "for key" k "has been cast to string") + (do (printerr "Warning: environ value" (pr-str v) "for key" k "has been cast to string") (str v)))) (defn- read-system-env [] @@ -58,8 +62,8 @@ (doseq [[k kvs] (group-by key (apply concat ms)) :let [vs (map val kvs)] :when (and (next kvs) (not= (first vs) (last vs)))] - (println "Warning: environ value" (first vs) "for key" k - "has been overwritten with" (last vs)))) + (printerr "Warning: environ value" (first vs) "for key" k + "has been overwritten with" (last vs)))) (defn- merge-env [& ms] (warn-on-overwrite ms)