Skip to content

Commit

Permalink
metabase.xrays API namespace (#42491)
Browse files Browse the repository at this point in the history
* Remove unused `metabase.api.transform`

* Copy the deps graph improvements from my other PR

* New combined X-Rays API namespace

* Fix kondo error
  • Loading branch information
camsaul committed May 10, 2024
1 parent c68b889 commit 59e7b3d
Show file tree
Hide file tree
Showing 57 changed files with 490 additions and 519 deletions.
83 changes: 32 additions & 51 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@
metabase.async #{metabase.async.streaming-response
metabase.async.streaming-response.thread-pool
metabase.async.util} ; TODO -- consolidate these into a real API namespace.
metabase.automagic-dashboards #{metabase.automagic-dashboards.comparison
metabase.automagic-dashboards.core
metabase.automagic-dashboards.dashboard-templates
metabase.automagic-dashboards.populate} ; TODO -- consolidate these into a real API namespace.
metabase.bootstrap #{metabase.bootstrap}
metabase.cmd #{} ; there are no namespaces here since you shouldn't be using this in any other module.
metabase.config #{metabase.config}
Expand All @@ -174,8 +170,6 @@
metabase.db.metadata-queries ; TODO this should probably be separate from metabase.db
metabase.db.query ; TODO this is mostly util stuff like `metabase.db.query/query` that we don't even need anymore.
metabase.db.setup} ; TODO these are only calling `metabase.db.setup/setup-db!` and there's a slightly different version in `metabase.db`
metabase.domain-entities #{metabase.domain-entities.core
metabase.domain-entities.specs} ; TODO -- these should probably be combined into the `metabase.transforms` module, that's the only place that uses them.
metabase.driver :any ; TODO -- 19 namespaces!!!! CRY
metabase.email #{metabase.email
metabase.email.messages} ; TODO -- consolidate these into a real API namespace.
Expand Down Expand Up @@ -251,14 +245,11 @@
metabase.task #{metabase.task
metabase.task.index-values
metabase.task.persist-refresh} ; TODO -- consolidate these into a real API namespace.
metabase.transforms #{metabase.transforms.core
metabase.transforms.dashboard
metabase.transforms.materialize
metabase.transforms.specs} ; TODO -- consolidate these into a real API namespace.
metabase.troubleshooting #{metabase.troubleshooting}
metabase.types #{metabase.types}
metabase.upload #{metabase.upload}
metabase.util :any} ; I think util being `:any` is actually something I am ok with. But this has 32 namespaces.
metabase.util :any ; I think util being `:any` is actually something I am ok with. But this has 32 namespaces.
metabase.xrays #{metabase.xrays}}

;; Map of module => other modules you're allowed to use there. You have two options here:
;;
Expand All @@ -275,13 +266,11 @@
metabase.analyze :any
metabase.api :any
metabase.async :any
metabase.automagic-dashboards :any
metabase.bootstrap #{}
metabase.cmd :any
metabase.config #{metabase.plugins}
metabase.core :any
metabase.db :any
metabase.domain-entities :any
metabase.driver :any
metabase.email :any
metabase.embed :any
Expand Down Expand Up @@ -309,11 +298,11 @@
metabase.shared :any
metabase.sync :any
metabase.task :any
metabase.transforms :any
metabase.troubleshooting :any
metabase.types #{metabase.util}
metabase.upload :any
metabase.util :any}
metabase.util :any
metabase.xrays :any}

;; namespaces matching these patterns (with `re-find`) are excluded from the module linter. Since regex literals
;; aren't allowed in EDN just used the `(str <regex>)` version i.e. two slashes instead of one.
Expand Down Expand Up @@ -423,13 +412,9 @@
metabase.api.tiles api.tiles
metabase.api.timeline api.timeline
metabase.api.timeline-event api.timeline-event
metabase.api.transform api.transform
metabase.api.user api.user
metabase.api.util api.util
metabase.async.streaming-response.thread-pool thread-pool
metabase.automagic-dashboards.core magic
metabase.automagic-dashboards.dashboard-templates dashboard-templates
metabase.automagic-dashboards.populate populate
metabase.cmd.copy.h2 copy.h2
metabase.config config
metabase.config.file config.file
Expand All @@ -439,7 +424,6 @@
metabase.db.metadata-queries metadata-queries
metabase.db.spec mdb.spec
metabase.db.query mdb.query
metabase.domain-entities.specs de.specs
metabase.driver.common.parameters params
metabase.driver.common.parameters.dates params.dates
metabase.driver.common.parameters.operators params.ops
Expand Down Expand Up @@ -584,9 +568,6 @@
metabase.test.util.js test.js
metabase.test.util.timezone test.tz
metabase.timeseries-query-processor-test.util tqpt
metabase.transforms.core tf
metabase.transforms.materialize tf.materialize
metabase.transforms.specs tf.specs
metabase.util.cron u.cron
metabase.util.date-2 u.date
metabase.util.date-2.common u.date.common
Expand All @@ -607,6 +588,7 @@
metabase.util.schema su
metabase.util.ui-logic ui-logic
metabase.util.urls urls
metabase.xrays xrays
metabuild-common.core u
metabuild-common.output out
metabuild-common.shell shell
Expand Down Expand Up @@ -638,7 +620,6 @@
metabase.db.data-migrations/defmigration clojure.core/def
metabase.db.liquibase/with-liquibase clojure.core/let
metabase.db.schema-migrations-test.impl/with-temp-empty-app-db clojure.core/let
metabase.domain-entities.malli/defn schema.core/defn
metabase.driver.mongo.query-processor/mongo-let clojure.core/let
metabase.driver.mongo.connection/with-mongo-client clojure.core/let
metabase.driver.mongo.connection/with-mongo-database clojure.core/let
Expand Down Expand Up @@ -669,28 +650,28 @@
metabase.test/with-actions clojure.core/let
metabase.test/with-open-channels clojure.core/let
metabase.test/with-single-admin-user clojure.core/fn

metabase.test/with-temp-dir clojure.core/let
metabase.test/with-temp-empty-app-db clojure.core/let
metabase.test/with-temp-file clojure.core/let
metabase.test/with-user-in-groups clojure.core/let
metabase.upload-test/with-upload-table! clojure.core/let
metabase.util.files/with-open-path-to-resource clojure.core/let
metabase.util.malli.defn/defn schema.core/defn
metabase.util.malli.fn/fn schema.core/fn
metabase.util.malli/defmethod schema.core/defmethod
metabase.util.malli/defn schema.core/defn
metabase.util.malli/fn schema.core/fn
metabase.util.ssh/with-ssh-tunnel clojure.core/let
monger.operators/defoperator clojure.core/def
potemkin.types/defprotocol+ clojure.core/defprotocol
potemkin.types/defrecord+ clojure.core/defrecord
potemkin.types/deftype+ clojure.core/deftype
potemkin/defprotocol+ clojure.core/defprotocol
potemkin/defrecord+ clojure.core/defrecord
potemkin/deftype+ clojure.core/deftype
toucan.db/with-call-counting clojure.core/fn
toucan2.core/with-call-count clojure.core/fn}
metabase.test/with-temp-dir clojure.core/let
metabase.test/with-temp-empty-app-db clojure.core/let
metabase.test/with-temp-file clojure.core/let
metabase.test/with-user-in-groups clojure.core/let
metabase.upload-test/with-upload-table! clojure.core/let
metabase.util.files/with-open-path-to-resource clojure.core/let
metabase.util.malli.defn/defn schema.core/defn
metabase.util.malli.fn/fn schema.core/fn
metabase.util.malli/defmethod schema.core/defmethod
metabase.util.malli/defn schema.core/defn
metabase.util.malli/fn schema.core/fn
metabase.util.ssh/with-ssh-tunnel clojure.core/let
metabase.xrays.domain-entities.malli/defn schema.core/defn
monger.operators/defoperator clojure.core/def
potemkin.types/defprotocol+ clojure.core/defprotocol
potemkin.types/defrecord+ clojure.core/defrecord
potemkin.types/deftype+ clojure.core/deftype
potemkin/defprotocol+ clojure.core/defprotocol
potemkin/defrecord+ clojure.core/defrecord
potemkin/deftype+ clojure.core/deftype
toucan.db/with-call-counting clojure.core/fn
toucan2.core/with-call-count clojure.core/fn}

:hooks
{:analyze-call
Expand Down Expand Up @@ -818,7 +799,6 @@
metabase.api.embed-test/with-embedding-enabled-and-temp-dashcard-referencing macros.metabase.api.embed-test/with-embedding-enabled-and-temp-dashcard-referencing
metabase.api.public-test/with-sharing-enabled-and-temp-card-referencing macros.metabase.api.public-test/with-sharing-enabled-and-temp-card-referencing
metabase.api.public-test/with-sharing-enabled-and-temp-dashcard-referencing macros.metabase.api.public-test/with-sharing-enabled-and-temp-dashcard-referencing
metabase.domain-entities.malli/define-getters-and-setters macros.metabase.domain-entities.malli/define-getters-and-setters
metabase.lib.filter/deffilter macros.metabase.lib.filter/deffilter
metabase.lib.common/defop macros.metabase.lib.common/defop
metabase.models.params.chain-filter-test/chain-filter macros.metabase.models.params.chain-filter-test/chain-filter
Expand All @@ -834,7 +814,8 @@
metabase.test/with-group-for-user macros.metabase.test.data.users/with-group-for-user
metabase.test/with-persistence-enabled macros.metabase.test.persistence/with-persistence-enabled
metabase.test/with-temp-env-var-value! macros.metabase.test.util/with-temp-env-var-value!
metabase.test/with-temporary-raw-setting-values macros.metabase.test.util/with-temporary-raw-setting-values}}
metabase.test/with-temporary-raw-setting-values macros.metabase.test.util/with-temporary-raw-setting-values
metabase.xrays.domain-entities.malli/define-getters-and-setters macros.metabase.xrays.domain-entities.malli/define-getters-and-setters}}

:config-in-comment
{:linters {:unresolved-symbol {:level :off}}}
Expand All @@ -846,14 +827,14 @@
;; the following patterns are considered to be test namespaces:
;;
;; - Any namespace ending in `-test` or `-test.whatever`
;; - Any namespace ending in `test-util`
;; - Any namespace containing in `test-util`
;; - Any namespace that starts with `metabase.test`
;;
;; this list isn't exhaustive because it misses some stuff like the test runner and HTTP client but it's easier to go
;; fix those namespaces than it is to make this regex super hairy.
[{:pattern "(?:.*-test(?:\\..*)?$)|(?:.*test-util$)|(?:^metabase\\.test.*)"
[{:pattern "(?:.*-test(?:\\..*)?$)|(?:.*test-util)|(?:^metabase\\.test.*)"
:name test-namespaces}
{:pattern "^(?!.*-test(?:\\..*)?$)(?!.*test-util$)(?!^metabase\\.test.*).*$"
{:pattern "^(?!.*-test(?:\\..*)?$)(?!.*test-util)(?!^metabase\\.test.*).*$"
:name source-namespaces}
{:pattern "(?:(?:^metabase\\.cmd.*)|(?:^build.*)|(?:^metabuild-common.*)|(?:^release.*)|(?:^i18n.*)|(?:^lint-migrations-file$))"
:name printable-namespaces}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns macros.metabase.domain-entities.malli)
(ns macros.metabase.xrays.domain-entities.malli)

(defmacro define-getters-and-setters [schema & defs]
`(do
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@
:java-opts ["-Dfile.encoding=UTF-8"]}

:generate-automagic-dashboards-pot
{:main-opts ["-m" "metabase.automagic-dashboards.dashboard-templates"]}
{:main-opts ["-m" "metabase.xrays.automagic-dashboards.dashboard-templates"]}

;; Start a Network REPL (nrepl) that you can connect your editor to.
;;
Expand Down
75 changes: 69 additions & 6 deletions dev/src/dev/deps_graph.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(ns dev.deps-graph
(:require
[clojure.tools.namespace.dependency :as ns.deps]
[clojure.java.io :as io]
[clojure.tools.namespace.find :as ns.find]
[clojure.tools.namespace.parse :as ns.parse]
[clojure.java.io :as io]))
[clojure.tools.namespace.parse :as ns.parse]))

(set! *warn-on-reflection* true)

Expand Down Expand Up @@ -35,9 +34,10 @@
{:namespace ns-symb
:module (module ns-symb)
:deps (into #{}
(map (fn [dep-symb]
{:namespace dep-symb
:module (module dep-symb)}))
(keep (fn [dep-symb]
(when-let [module (module dep-symb)]
{:namespace dep-symb
:module module})))
deps)}))

(defn external-usages
Expand All @@ -56,3 +56,66 @@
"All namespaces from a module that are used outside that module."
[module-symb]
(into (sorted-set) (map :depends-on-namespace) (external-usages module-symb)))

(defn module-dependencies
"Build a graph of module => set of modules it refers to."
([]
(letfn [(reduce-module-deps [module-deps module deps]
(reduce
(fn [module-deps {dep-module :module, :as _dep}]
(cond-> module-deps
(not= dep-module module) (conj dep-module)))
(or module-deps (sorted-set))
deps))
(reduce-deps [module->deps {:keys [module deps]}]
(update module->deps module reduce-module-deps module deps))]
(reduce reduce-deps (sorted-map) (dependencies))))

([module]
(get (module-dependencies) module)))

(defn circular-dependencies
"Build a graph of module => set of modules it refers to that also refer to this module."
([]
(let [module->deps (module-dependencies)]
(letfn [(circular-dependency? [module-x module-y]
(and (contains? (get module->deps module-x) module-y)
(contains? (get module->deps module-y) module-x)))
(circular-deps [module]
(let [module-deps (get module->deps module)]
(not-empty (into (sorted-set)
(filter (fn [dep]
(circular-dependency? module dep)))
module-deps))))]
(into (sorted-map)
(keep (fn [module]
(when-let [circular-deps (circular-deps module)]
[module circular-deps])))
(keys module->deps)))))

([module]
(get (circular-dependencies) module)))

(defn non-circular-module-dependencies
"A graph of [[module-dependencies]], but with modules that have any circular dependencies filtered out. This is mostly
meant to make it easier to fill out the `:metabase/ns-module-checker` `:allowed-modules` section of the Kondo
config, or to figure out which ones can easily get a consolidated API namespace without drama."
[]
(let [circular-dependencies (circular-dependencies)]
(into (sorted-map)
(remove (fn [[module _deps]]
(contains? circular-dependencies module)))
(module-dependencies))))

(defn module-usages-of-other-module
"Information about how `module-x` uses `module-y`."
[module-x module-y]
(let [module-x-ns->module-y-ns (->> (external-usages module-y)
(filter #(= (:module %) module-x))
(map (juxt :namespace :depends-on-namespace)))]
(reduce
(fn [m [module-x-ns module-y-ns]]
(update m module-x-ns (fn [deps]
(conj (or deps (sorted-set)) module-y-ns))))
(sorted-map)
module-x-ns->module-y-ns)))
1 change: 0 additions & 1 deletion docs/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,5 @@ _* indicates endpoints used for features available on [paid plans](https://www.m
- [Tiles](api/tiles.md)
- [Timeline](api/timeline.md)
- [Timeline event](api/timeline-event.md)
- [Transform](api/transform.md)
- [User](api/user.md)
- [Util](api/util.md)
Loading

0 comments on commit 59e7b3d

Please sign in to comment.