Skip to content

Commit

Permalink
patch: Ignore dependencies with no kmono config
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Jan 18, 2024
1 parent 3ac232d commit a007e5d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 76 deletions.
83 changes: 42 additions & 41 deletions packages/kmono/src/k16/kmono/adapters/clojure_deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,49 @@
(->adapter package-path 10000))
([package-path timeout-ms]
(let [deps-edn (read-deps-edn package-path)
{:keys [group artifact] :as config}
(-> (:kmono/config deps-edn)
(adapter/ensure-artifact package-path))
coord (str group "/" artifact)
managed-deps (get-local-deps config deps-edn)]
(reify Adapter
kmono-config (:kmono/config deps-edn)]
(when kmono-config
(let [{:keys [group artifact] :as config}
(-> kmono-config
(adapter/ensure-artifact package-path))
coord (str group "/" artifact)
managed-deps (get-local-deps config deps-edn)]
(reify Adapter

(prepare-deps-env [_ changes]
(binding [*print-namespace-maps* false]
(str "'"
{:deps
(into {} (map
(fn [dep]
[(symbol dep)
{:mvn/version
(get-in changes [dep :version])}]))
managed-deps)}
"'")))
(prepare-deps-env [_ changes]
(binding [*print-namespace-maps* false]
(str "'"
{:deps
(into {} (map
(fn [dep]
[(symbol dep)
{:mvn/version
(get-in changes [dep :version])}]))
managed-deps)}
"'")))

(get-managed-deps [_] managed-deps)
(get-managed-deps [_] managed-deps)

(get-kmono-config [_] config)

(release-published? [_ version]
(-> (p/vthread
(let [;; ignore user's local repository cache
local-repo (str package-path "/.kmono/" artifact "/.m2")]
(try (deps.util.session/with-session
(let [;; ignoring user's machine local m2 repo
versions (->> (deps.ext/find-versions
(symbol coord)
nil
:mvn {:mvn/local-repo local-repo
:mvn/repos
(merge deps.util.maven/standard-repos
(:mvn/repos deps-edn))})
(map :mvn/version)
(set))]
(contains? versions version)))
(finally
(try (fs/delete-tree local-repo)
(catch Throwable _))))))
(p/timeout timeout-ms (str "Timeout resolving mvn version for package " coord))
(deref)))))))
(get-kmono-config [_] config)

(release-published? [_ version]
(-> (p/vthread
(let [;; ignore user's local repository cache
local-repo (str package-path "/.kmono/" artifact "/.m2")]
(try (deps.util.session/with-session
(let [;; ignoring user's machine local m2 repo
versions (->> (deps.ext/find-versions
(symbol coord)
nil
:mvn {:mvn/local-repo local-repo
:mvn/repos
(merge deps.util.maven/standard-repos
(:mvn/repos deps-edn))})
(map :mvn/version)
(set))]
(contains? versions version)))
(finally
(try (fs/delete-tree local-repo)
(catch Throwable _))))))
(p/timeout timeout-ms (str "Timeout resolving mvn version for package " coord))
(deref)))))))))
46 changes: 24 additions & 22 deletions packages/kmono/src/k16/kmono/adapters/kmono_edn.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@
([package-path]
(->adapter package-path 10000))
([package-path _]
(let [kmono-config (-> (fs/file package-path "kmono.edn")
(slurp)
(edn/read-string))
config (adapter/ensure-artifact kmono-config package-path)
managed-deps (get config :local-deps [])]
(reify Adapter

(prepare-deps-env [_ changes]
(string/join
";"
(map
(fn [dep]
(str (symbol dep)
"@"
(get-in changes [dep :version])))
managed-deps)))

(get-managed-deps [_] managed-deps)

(get-kmono-config [_] config)

(release-published? [_ _] false)))))
(let [kmono-file (fs/file package-path "kmono.edn")]
(when (fs/exists? kmono-file)
(let [kmono-config (-> kmono-file
(slurp)
(edn/read-string))
config (adapter/ensure-artifact kmono-config package-path)
managed-deps (get config :local-deps [])]
(reify Adapter

(prepare-deps-env [_ changes]
(string/join
";"
(map
(fn [dep]
(str (symbol dep)
"@"
(get-in changes [dep :version])))
managed-deps)))

(get-managed-deps [_] managed-deps)

(get-kmono-config [_] config)

(release-published? [_ _] false)))))))
28 changes: 15 additions & 13 deletions packages/kmono/src/k16/kmono/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

(defn get-adapter
[pkg-dir]
(if (fs/exists? (fs/file pkg-dir "kmono.edn"))
(kmono.edn/->adapter (fs/file pkg-dir))
(clj.deps/->adapter (fs/file pkg-dir))))
(or (kmono.edn/->adapter (fs/file pkg-dir))
(clj.deps/->adapter (fs/file pkg-dir))))

(defn- assert-schema!
[?schema value]
Expand All @@ -30,28 +29,32 @@
(assert-schema! schema/?Config config))

(defn- create-package-config [package-dir]
(let [adapter (get-adapter package-dir)
kb-pkg-config (->> (adapter/get-kmono-config adapter)
(assert-schema! schema/?KmonoPackageConfig))
artifact (or (:artifact kb-pkg-config)
(symbol (fs/file-name package-dir)))
pkg-name (str (:group kb-pkg-config) "/" artifact)
pkg-commit-sha (git/subdir-commit-sha package-dir)]
(when-let [adapter (get-adapter package-dir)]
(let [kb-pkg-config (->> (adapter/get-kmono-config adapter)
(assert-schema! schema/?KmonoPackageConfig))
artifact (or (:artifact kb-pkg-config)
(symbol (fs/file-name package-dir)))
pkg-name (str (:group kb-pkg-config) "/" artifact)
pkg-commit-sha (git/subdir-commit-sha package-dir)

(let [pkg-config (merge kb-pkg-config
pkg-config (merge kb-pkg-config
{:artifact (or (:artifact kb-pkg-config)
(symbol (fs/file-name package-dir)))
:name pkg-name
:commit-sha pkg-commit-sha
:adapter adapter
:dir (str package-dir)})]

(->> (assoc pkg-config :depends-on (adapter/get-managed-deps adapter))
(assert-schema! schema/?Package)))))

(defn- create-config
[repo-root glob]
(let [package-dirs (fs/glob repo-root glob)]
{:packages (mapv create-package-config package-dirs)}))
{:packages (->> package-dirs
(map create-package-config)
(remove nil?)
vec)}))

(defn create-graph
{:malli/schema [:=> [:cat schema/?Packages] schema/?Graph]}
Expand Down Expand Up @@ -149,4 +152,3 @@
:package-map (->pkg-map packages)
:graph graph
:build-order (parallel-topo-sort graph)})))))

0 comments on commit a007e5d

Please sign in to comment.