Skip to content

Commit

Permalink
Remove the requirement for :kmono/package
Browse files Browse the repository at this point in the history
It's currently required for all packages that want to participate in the
workspace to contain a `:kmono/package` key with at minimum an empty
map.

This is a lot of additional unnecessary boilerplate.

This commit makes the key optional and therefore all packages found will
be automatically participating. To exclude a package from the workspace
you can use the new `:excluded` key:

```clojure
{:kmono/package {:excluded true}}
```
  • Loading branch information
julienvincent committed Sep 26, 2024
1 parent da78997 commit 295ec1d
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 61 deletions.
3 changes: 2 additions & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
(defn- load-packages []
(let [project-root (core.fs/find-project-root!)
workspace-config (core.config/resolve-workspace-config project-root)
packages (core.packages/resolve-packages project-root workspace-config)
packages (->> (core.packages/resolve-packages project-root workspace-config)
(core.graph/filter-by #(not (get-in % [:deps-edn :kmono/private]))))

version (get-latest-version project-root)]

Expand Down
4 changes: 1 addition & 3 deletions examples/workspace/packages/a/deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{:kmono/package {}

:aliases {:test {:extra-paths ["test"]
{:aliases {:test {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
:main-opts ["-m" "kaocha.runner" "-c" "../../tests.edn"]}}}
4 changes: 1 addition & 3 deletions examples/workspace/packages/b/deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{:kmono/package {}

:deps {com.kepler16/a {:local/root "../a"}}
{:deps {com.kepler16/a {:local/root "../a"}}

:aliases {:test {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
Expand Down
4 changes: 1 addition & 3 deletions packages/kmono-build/deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{:kmono/package {}

:kmono/description "A suite of tools for use within tools.build"
{:kmono/description "A suite of tools for use within tools.build"

:deps {io.github.clojure/tools.build {:mvn/version "0.10.5"}
org.clojure/tools.deps {:mvn/version "0.20.1440"}
Expand Down
4 changes: 1 addition & 3 deletions packages/kmono-cli/deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{:kmono/package {:artifact kmono}

:kmono/description "The kmono CLI interface"
{:kmono/description "The kmono CLI interface"

:paths ["src" "resources"]

Expand Down
4 changes: 1 addition & 3 deletions packages/kmono-core/deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{:kmono/package {}

:kmono/description "The core kmono package and graph API's"
{:kmono/description "The core kmono package and graph API's"

:deps {babashka/fs {:mvn/version "0.5.22"}
babashka/process {:mvn/version "0.5.22"}
Expand Down
4 changes: 2 additions & 2 deletions packages/kmono-core/src/k16/kmono/core/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
(validate! core.schema/?PackageConfig
package-config
"Package config is invalid"
{:package-path (str package-path)})
{:package-path (str package-path)}))

package-config)))
package-config))
2 changes: 1 addition & 1 deletion packages/kmono-core/src/k16/kmono/core/fs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
(let [root (find-project-root dir)]
(when-not root
(throw (ex-info "Not a Clojure project" {:type :kmono/root-not-found
:dir (normalize-dir (or dir (fs/cwd)))})))
:dir (str (normalize-dir (or dir (fs/cwd))))})))
root)))

(defn read-edn-file! [file-path]
Expand Down
41 changes: 22 additions & 19 deletions packages/kmono-core/src/k16/kmono/core/packages.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@
(set! *warn-on-reflection* true)

(defn- create-package [project-root workspace-config package-path]
(when-let [config (core.config/resolve-package-config package-path)]
(let [package (merge {:name (symbol (fs/file-name package-path))}
(select-keys workspace-config [:group])
(select-keys config [:group :name :deps-edn])
{:absolute-path (str package-path)
:relative-path (str (fs/relativize project-root package-path))
:depends-on #{}})
fqn (symbol (str (:group package))
(str (:name package)))]

(when-not (:group package)
(ex-info (str "Missing package :group for " fqn ". "
"This either needs to be set in "
"the `:kmono/package` config or "
"in the `:kmono/workspace` config")
{:type :kmono/validation-error
:errors {:group ["required key"]}}))

(assoc package :fqn fqn))))
(let [config (core.config/resolve-package-config package-path)]
(when-not (or (:excluded config)
(fs/same-file? project-root package-path))
(let [relative-path (str (fs/relativize project-root package-path))
package (merge {:name (symbol (fs/file-name package-path))}
(select-keys workspace-config [:group])
(select-keys config [:group :name :deps-edn])
{:absolute-path (str package-path)
:relative-path relative-path
:depends-on #{}})
fqn (symbol (str (:group package))
(str (:name package)))]

(when-not (:group package)
(ex-info (str "Missing package :group for " fqn ". "
"This either needs to be set in "
"the `:kmono/package` config or "
"in the `:kmono/workspace` config")
{:type :kmono/validation-error
:errors {:group ["required key"]}}))

(assoc package :fqn fqn)))))

(defn- filter-dependencies [packages package]
(into #{}
Expand Down
3 changes: 2 additions & 1 deletion packages/kmono-core/src/k16/kmono/core/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
[:map
[:group {:optional true} :symbol]
[:name {:optional true}
[:maybe [:or :string :symbol]]]])
[:maybe [:or :string :symbol]]]
[:excluded {:optional true} :boolean]])

(def ?Coordinate
[:map
Expand Down
7 changes: 5 additions & 2 deletions packages/kmono-core/test/k16/kmono/core/packages_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
(use-fixtures :each with-test-repo)

(deftest load-packages-test
(let [config (core.config/resolve-workspace-config *repo*)]
(let [config (core.config/resolve-workspace-config *repo*)
packages (core.packages/resolve-packages *repo* config)]
(is (match? {'com.kepler16/a {:group 'com.kepler16
:name 'a
:fqn 'com.kepler16/a
Expand All @@ -33,4 +34,6 @@

:absolute-path (str (fs/file *repo* "packages/b"))
:relative-path "packages/b"}}
(core.packages/resolve-packages *repo* config)))))
packages))

(is (= 2 (count packages)))))
4 changes: 1 addition & 3 deletions packages/kmono-git/deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{:kmono/package {}

:kmono/description "Simple git interface"
{:kmono/description "Simple git interface"

:deps {babashka/process {:mvn/version "0.5.22"}
babashka/fs {:mvn/version "0.5.22"}}
Expand Down
4 changes: 1 addition & 3 deletions packages/kmono-log/deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{:kmono/package {}

:kmono/description "Terminal logging API's used by kmono"
{:kmono/description "Terminal logging API's used by kmono"

:deps {jansi-clj/jansi-clj {:mvn/version "1.0.3"}}}
4 changes: 3 additions & 1 deletion packages/kmono-test/deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{:paths ["src" "resources"]
{:kmono/private true

:paths ["src" "resources"]

:deps {babashka/fs {:mvn/version "0.5.22"}
babashka/process {:mvn/version "0.5.22"}}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
{:kmono/package {}

:aliases {:test {:extra-paths ["test"]
{:aliases {:test {:extra-paths ["test"]
:extra-deps {local/excluded {:local/root "../excluded"}}}}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{:kmono/package {}

:deps {org.clojure/clojure {:mvn/version "1.12.0"}
{:deps {org.clojure/clojure {:mvn/version "1.12.0"}
local/excluded {:local/root "../excluded"}
com.kepler16/a {:local/root "../a"}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{:kmono/package {:excluded true}}
4 changes: 1 addition & 3 deletions packages/kmono-version/deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{:kmono/package {}

:kmono/description "Tools for versioning kmono packages"
{:kmono/description "Tools for versioning kmono packages"

:deps {com.kepler16/kmono-core {:local/root "../kmono-core"}
com.kepler16/kmono-git {:local/root "../kmono-git"}}
Expand Down
4 changes: 1 addition & 3 deletions packages/kmono/deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{:kmono/package {}

:kmono/description "A tool for working in clojure (mono)repos"
{:kmono/description "A tool for working in clojure (mono)repos"

:deps {com.kepler16/kmono-core {:local/root "../kmono-core"}
com.kepler16/kmono-build {:local/root "../kmono-build"}
Expand Down

0 comments on commit 295ec1d

Please sign in to comment.