From faa3d6cc2357013b24e555ea0a5f90bf70776200 Mon Sep 17 00:00:00 2001 From: Rafael Delboni Date: Tue, 2 May 2023 10:30:29 -0300 Subject: [PATCH 1/2] refact: renames libraries to namespace --- src/codes/clj/docs/extractor/adapters.clj | 52 +++++++------- src/codes/clj/docs/extractor/analysis.clj | 2 +- src/codes/clj/docs/extractor/datalevin.clj | 35 +++++---- .../clj/docs/extractor/adapters_test.clj | 8 +-- .../clj/docs/extractor/datalevin_test.clj | 66 ++++++++--------- .../clj/docs/extractor/fixtures/analysis.clj | 72 +++++++++---------- 6 files changed, 117 insertions(+), 118 deletions(-) diff --git a/src/codes/clj/docs/extractor/adapters.clj b/src/codes/clj/docs/extractor/adapters.clj index 9aeab50..9d95046 100644 --- a/src/codes/clj/docs/extractor/adapters.clj +++ b/src/codes/clj/docs/extractor/adapters.clj @@ -68,38 +68,38 @@ :project/manifest (:deps/manifest project)))) analysis)) -(defn analysis->libraries +(defn analysis->namespaces [analysis] (reduce - (fn [accum {:keys [project libraries]}] + (fn [accum {:keys [project namespaces]}] (into accum (let [{:git/keys [url tag] :deps/keys [root]} project [group artifact] (-> project :project-name (str/split #"/"))] - (->> libraries + (->> namespaces group-multi-langs (mapv (fn [{:keys [end-row meta name-end-col name-end-row name-row added name author filename col name-col end-col doc row]}] (let [trim-filename (str/replace filename root "")] (assoc-some - {:library/id (str/join "/" [group artifact name]) - :library/project {:project/id (:project-name project)} - :library/group group - :library/artifact artifact - :library/name (str name)} - :library/end-row end-row - :library/meta meta - :library/name-end-col name-end-col - :library/name-end-row name-end-row - :library/name-row name-row - :library/added added - :library/author author - :library/filename trim-filename - :library/git-source (str url "/blob/" tag trim-filename "#L" row) - :library/col col - :library/name-col name-col - :library/end-col end-col - :library/doc doc - :library/row row)))))))) + {:namespace/id (str/join "/" [group artifact name]) + :namespace/project {:project/id (:project-name project)} + :namespace/group group + :namespace/artifact artifact + :namespace/name (str name)} + :namespace/end-row end-row + :namespace/meta meta + :namespace/name-end-col name-end-col + :namespace/name-end-row name-end-row + :namespace/name-row name-row + :namespace/added added + :namespace/author author + :namespace/filename trim-filename + :namespace/git-source (str url "/blob/" tag trim-filename "#L" row) + :namespace/col col + :namespace/name-col name-col + :namespace/end-col end-col + :namespace/doc doc + :namespace/row row)))))))) [] analysis)) @@ -127,8 +127,8 @@ :definition/artifact artifact :definition/name (str name)} :definition/defined-by (some-> defined-by str) - :definition/namespace (some-> ns str) - :definition/library (when ns {:library/id (str/join "/" [group artifact ns])}) + :definition/namespace (when ns {:namespace/id (str/join "/" [group artifact ns]) + :namespace/name (str ns)}) :definition/fixed-arities fixed-arities :definition/arglist-strs arglist-strs :definition/end-row end-row @@ -153,7 +153,7 @@ []) (id-by (juxt :definition/group :definition/artifact - :definition/namespace + #(get-in % [:definition/namespace :namespace/name]) :definition/name) :definition/id) (remove inrelevant-definitions))) @@ -161,5 +161,5 @@ (defn analysis->datoms [analysis] (concat (analysis->projects analysis) - (analysis->libraries analysis) + (analysis->namespaces analysis) (analysis->definitions analysis))) diff --git a/src/codes/clj/docs/extractor/analysis.clj b/src/codes/clj/docs/extractor/analysis.clj index 45025e5..cacce84 100644 --- a/src/codes/clj/docs/extractor/analysis.clj +++ b/src/codes/clj/docs/extractor/analysis.clj @@ -29,7 +29,7 @@ (let [{:keys [paths] :as project-meta} (download-project! project git) {:keys [var-definitions namespace-definitions]} (kondo-run! paths)] {:project project-meta - :libraries namespace-definitions + :namespaces namespace-definitions :definitions var-definitions})) (defn extract! diff --git a/src/codes/clj/docs/extractor/datalevin.clj b/src/codes/clj/docs/extractor/datalevin.clj index b9efb73..7321b6d 100644 --- a/src/codes/clj/docs/extractor/datalevin.clj +++ b/src/codes/clj/docs/extractor/datalevin.clj @@ -16,28 +16,27 @@ :project/sha {:db/valueType :db.type/string} :project/manifest {:db/valueType :db.type/keyword}}) -(def library-schema - {:library/id {:db/valueType :db.type/string - :unique :db.unique/identity} - :library/name {:db/valueType :db.type/string} - :library/project {:db/valueType :db.type/ref} - :library/group {:db/valueType :db.type/string} - :library/artifact {:db/valueType :db.type/string} - :library/doc {:db/valueType :db.type/string - :db/fulltext true} - :library/author {:db/valueType :db.type/string} - :library/filename {:db/valueType :db.type/string} - :library/git-source {:db/valueType :db.type/string} - :library/added {:db/valueType :db.type/string} - :library/row {:db/valueType :db.type/long} - :library/col {:db/valueType :db.type/long}}) +(def namespace-schema + {:namespace/id {:db/valueType :db.type/string + :unique :db.unique/identity} + :namespace/name {:db/valueType :db.type/string} + :namespace/project {:db/valueType :db.type/ref} + :namespace/group {:db/valueType :db.type/string} + :namespace/artifact {:db/valueType :db.type/string} + :namespace/doc {:db/valueType :db.type/string + :db/fulltext true} + :namespace/author {:db/valueType :db.type/string} + :namespace/filename {:db/valueType :db.type/string} + :namespace/git-source {:db/valueType :db.type/string} + :namespace/added {:db/valueType :db.type/string} + :namespace/row {:db/valueType :db.type/long} + :namespace/col {:db/valueType :db.type/long}}) (def definition-schema {:definition/id {:db/valueType :db.type/string :unique :db.unique/identity} :definition/name {:db/valueType :db.type/string} - :definition/namespace {:db/valueType :db.type/string} - :definition/library {:db/valueType :db.type/ref} + :definition/namespace {:db/valueType :db.type/ref} :definition/group {:db/valueType :db.type/string} :definition/artifact {:db/valueType :db.type/string} :definition/doc {:db/valueType :db.type/string @@ -56,7 +55,7 @@ :definition/protocol-name {:db/valueType :db.type/string}}) (def db-schemas - (merge project-schema library-schema definition-schema)) + (merge project-schema namespace-schema definition-schema)) (defn bulk-transact! [datoms config] (let [conn (-> config :db :dir (d/get-conn db-schemas))] diff --git a/test/codes/clj/docs/extractor/adapters_test.clj b/test/codes/clj/docs/extractor/adapters_test.clj index 6f23773..eba244e 100644 --- a/test/codes/clj/docs/extractor/adapters_test.clj +++ b/test/codes/clj/docs/extractor/adapters_test.clj @@ -9,10 +9,10 @@ (is (match? fixtures.analysis/projects-adapted (adapters/analysis->projects fixtures.analysis/raw))))) -(deftest analysis->libraries-test - (testing "analysis -> libraries" - (is (match? fixtures.analysis/libraries-adapted - (adapters/analysis->libraries fixtures.analysis/raw))))) +(deftest analysis->namespaces-test + (testing "analysis -> namespaces" + (is (match? fixtures.analysis/namespaces-adapted + (adapters/analysis->namespaces fixtures.analysis/raw))))) (deftest analysis->definitions-test (testing "analysis -> definitions" diff --git a/test/codes/clj/docs/extractor/datalevin_test.clj b/test/codes/clj/docs/extractor/datalevin_test.clj index 7459e79..39bc5a7 100644 --- a/test/codes/clj/docs/extractor/datalevin_test.clj +++ b/test/codes/clj/docs/extractor/datalevin_test.clj @@ -43,41 +43,41 @@ "org.clojure/clojure") ffirst))) - (is (match? {:library/project {:db/id 1 - :project/manifest :pom - :project/tag "clojure-1.11.1" - :project/sha "ce55092f2b2f5481d25cff6205470c1335760ef6" - :project/url "https://github.com/clojure/clojure" - :project/artifact "clojure" - :project/paths ["/src/clj" - "/src/main/clojure" - "/src/main/java" - "/src/resources"] - :project/name "org.clojure/clojure" - :project/group "org.clojure" - :project/id "org.clojure/clojure"} + (is (match? {:namespace/project {:db/id 1 + :project/manifest :pom + :project/tag "clojure-1.11.1" + :project/sha "ce55092f2b2f5481d25cff6205470c1335760ef6" + :project/url "https://github.com/clojure/clojure" + :project/artifact "clojure" + :project/paths ["/src/clj" + "/src/main/clojure" + "/src/main/java" + "/src/resources"] + :project/name "org.clojure/clojure" + :project/group "org.clojure" + :project/id "org.clojure/clojure"} :db/id 2 - :library/artifact "clojure" - :library/name-end-col 19 - :library/added "1.2" - :library/end-col 40 - :library/end-row 39 - :library/git-source "https://github.com/clojure/clojure/blob/clojure-1.11.1/src/clj/clojure/pprint.clj#L14" - :library/name-row 37 - :library/meta {} - :library/row 14 - :library/name-col 5 - :library/author "Tom Faulhaber" - :library/col 1 - :library/name "clojure.pprint" - :library/doc "A Pretty Printer for Clojure\n\nclojure.pprint implements a flexible system for printing structured data\nin a pleasing easy-to-understand format. Basic use of the pretty printer is \nsimple just call pprint instead of println. More advanced users can use \nthe building blocks provided to create custom output formats. \n\nOut of the box pprint supports a simple structured format for basic data \nand a specialized format for Clojure source code. More advanced formats \nincluding formats that don't look like Clojure data at all like XML and \nJSON can be rendered by creating custom dispatch functions. \n\nIn addition to the pprint function this module contains cl-format a text \nformatting function which is fully compatible with the format function in \nCommon Lisp. Because pretty printing directives are directly integrated with\ncl-format it supports very concise custom dispatch. It also provides\na more powerful alternative to Clojure's standard format function.\n\nSee documentation for pprint and cl-format for more information or \ncomplete documentation on the Clojure web site on GitHub." - :library/id "org.clojure/clojure/clojure.pprint" - :library/name-end-row 37 - :library/filename "/src/clj/clojure/pprint.clj" - :library/group "org.clojure"} - (-> (d/q '[:find (pull ?e [* {:library/project [*]}]) + :namespace/artifact "clojure" + :namespace/name-end-col 19 + :namespace/added "1.2" + :namespace/end-col 40 + :namespace/end-row 39 + :namespace/git-source "https://github.com/clojure/clojure/blob/clojure-1.11.1/src/clj/clojure/pprint.clj#L14" + :namespace/name-row 37 + :namespace/meta {} + :namespace/row 14 + :namespace/name-col 5 + :namespace/author "Tom Faulhaber" + :namespace/col 1 + :namespace/name "clojure.pprint" + :namespace/doc "A Pretty Printer for Clojure\n\nclojure.pprint implements a flexible system for printing structured data\nin a pleasing easy-to-understand format. Basic use of the pretty printer is \nsimple just call pprint instead of println. More advanced users can use \nthe building blocks provided to create custom output formats. \n\nOut of the box pprint supports a simple structured format for basic data \nand a specialized format for Clojure source code. More advanced formats \nincluding formats that don't look like Clojure data at all like XML and \nJSON can be rendered by creating custom dispatch functions. \n\nIn addition to the pprint function this module contains cl-format a text \nformatting function which is fully compatible with the format function in \nCommon Lisp. Because pretty printing directives are directly integrated with\ncl-format it supports very concise custom dispatch. It also provides\na more powerful alternative to Clojure's standard format function.\n\nSee documentation for pprint and cl-format for more information or \ncomplete documentation on the Clojure web site on GitHub." + :namespace/id "org.clojure/clojure/clojure.pprint" + :namespace/name-end-row 37 + :namespace/filename "/src/clj/clojure/pprint.clj" + :namespace/group "org.clojure"} + (-> (d/q '[:find (pull ?e [* {:namespace/project [*]}]) :in $ ?q - :where [?e :library/name ?q]] + :where [?e :namespace/name ?q]] db "clojure.pprint") ffirst))) diff --git a/test/codes/clj/docs/extractor/fixtures/analysis.clj b/test/codes/clj/docs/extractor/fixtures/analysis.clj index ade3a08..0933aea 100644 --- a/test/codes/clj/docs/extractor/fixtures/analysis.clj +++ b/test/codes/clj/docs/extractor/fixtures/analysis.clj @@ -12,20 +12,20 @@ "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/resources" "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/clj"] :project-name "org.clojure/clojure"} - :libraries [{:end-row 39 - :meta {} - :name-end-col 19 - :name-end-row 37 - :name-row 37 - :added "1.2" - :name 'clojure.pprint - :author "Tom Faulhaber" - :filename "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/clj/clojure/pprint.clj" - :col 1 - :name-col 5 - :end-col 40 - :doc "A Pretty Printer for Clojure\n\nclojure.pprint implements a flexible system for printing structured data\nin a pleasing easy-to-understand format. Basic use of the pretty printer is \nsimple just call pprint instead of println. More advanced users can use \nthe building blocks provided to create custom output formats. \n\nOut of the box pprint supports a simple structured format for basic data \nand a specialized format for Clojure source code. More advanced formats \nincluding formats that don't look like Clojure data at all like XML and \nJSON can be rendered by creating custom dispatch functions. \n\nIn addition to the pprint function this module contains cl-format a text \nformatting function which is fully compatible with the format function in \nCommon Lisp. Because pretty printing directives are directly integrated with\ncl-format it supports very concise custom dispatch. It also provides\na more powerful alternative to Clojure's standard format function.\n\nSee documentation for pprint and cl-format for more information or \ncomplete documentation on the Clojure web site on GitHub." - :row 14}] + :namespaces [{:end-row 39 + :meta {} + :name-end-col 19 + :name-end-row 37 + :name-row 37 + :added "1.2" + :name 'clojure.pprint + :author "Tom Faulhaber" + :filename "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/clj/clojure/pprint.clj" + :col 1 + :name-col 5 + :end-col 40 + :doc "A Pretty Printer for Clojure\n\nclojure.pprint implements a flexible system for printing structured data\nin a pleasing easy-to-understand format. Basic use of the pretty printer is \nsimple just call pprint instead of println. More advanced users can use \nthe building blocks provided to create custom output formats. \n\nOut of the box pprint supports a simple structured format for basic data \nand a specialized format for Clojure source code. More advanced formats \nincluding formats that don't look like Clojure data at all like XML and \nJSON can be rendered by creating custom dispatch functions. \n\nIn addition to the pprint function this module contains cl-format a text \nformatting function which is fully compatible with the format function in \nCommon Lisp. Because pretty printing directives are directly integrated with\ncl-format it supports very concise custom dispatch. It also provides\na more powerful alternative to Clojure's standard format function.\n\nSee documentation for pprint and cl-format for more information or \ncomplete documentation on the Clojure web site on GitHub." + :row 14}] :definitions [{:end-row 109 :meta {} :name-end-col 30 @@ -89,31 +89,31 @@ :project/sha "ce55092f2b2f5481d25cff6205470c1335760ef6" :project/manifest :pom}]) -(def libraries-adapted - [{:library/id "org.clojure/clojure/clojure.pprint" - :library/name "clojure.pprint" - :library/project {:project/id "org.clojure/clojure"} - :library/group "org.clojure" - :library/artifact "clojure" - :library/doc "A Pretty Printer for Clojure\n\nclojure.pprint implements a flexible system for printing structured data\nin a pleasing easy-to-understand format. Basic use of the pretty printer is \nsimple just call pprint instead of println. More advanced users can use \nthe building blocks provided to create custom output formats. \n\nOut of the box pprint supports a simple structured format for basic data \nand a specialized format for Clojure source code. More advanced formats \nincluding formats that don't look like Clojure data at all like XML and \nJSON can be rendered by creating custom dispatch functions. \n\nIn addition to the pprint function this module contains cl-format a text \nformatting function which is fully compatible with the format function in \nCommon Lisp. Because pretty printing directives are directly integrated with\ncl-format it supports very concise custom dispatch. It also provides\na more powerful alternative to Clojure's standard format function.\n\nSee documentation for pprint and cl-format for more information or \ncomplete documentation on the Clojure web site on GitHub." - :library/author "Tom Faulhaber" - :library/filename "/src/clj/clojure/pprint.clj" - :library/git-source "https://github.com/clojure/clojure/blob/clojure-1.11.1/src/clj/clojure/pprint.clj#L14" - :library/meta {} - :library/added "1.2" - :library/name-col 5 - :library/name-end-col 19 - :library/name-end-row 37 - :library/end-col 40 - :library/end-row 39 - :library/name-row 37 - :library/row 14 - :library/col 1}]) +(def namespaces-adapted + [{:namespace/id "org.clojure/clojure/clojure.pprint" + :namespace/name "clojure.pprint" + :namespace/project {:project/id "org.clojure/clojure"} + :namespace/group "org.clojure" + :namespace/artifact "clojure" + :namespace/doc "A Pretty Printer for Clojure\n\nclojure.pprint implements a flexible system for printing structured data\nin a pleasing easy-to-understand format. Basic use of the pretty printer is \nsimple just call pprint instead of println. More advanced users can use \nthe building blocks provided to create custom output formats. \n\nOut of the box pprint supports a simple structured format for basic data \nand a specialized format for Clojure source code. More advanced formats \nincluding formats that don't look like Clojure data at all like XML and \nJSON can be rendered by creating custom dispatch functions. \n\nIn addition to the pprint function this module contains cl-format a text \nformatting function which is fully compatible with the format function in \nCommon Lisp. Because pretty printing directives are directly integrated with\ncl-format it supports very concise custom dispatch. It also provides\na more powerful alternative to Clojure's standard format function.\n\nSee documentation for pprint and cl-format for more information or \ncomplete documentation on the Clojure web site on GitHub." + :namespace/author "Tom Faulhaber" + :namespace/filename "/src/clj/clojure/pprint.clj" + :namespace/git-source "https://github.com/clojure/clojure/blob/clojure-1.11.1/src/clj/clojure/pprint.clj#L14" + :namespace/meta {} + :namespace/added "1.2" + :namespace/name-col 5 + :namespace/name-end-col 19 + :namespace/name-end-row 37 + :namespace/end-col 40 + :namespace/end-row 39 + :namespace/name-row 37 + :namespace/row 14 + :namespace/col 1}]) (def definitions-adapted [{:definition/id "org.clojure/clojure/clojure.pprint/pprint-logical-block/0" :definition/name "pprint-logical-block" - :definition/library {:library/id "org.clojure/clojure/clojure.pprint"} + :definition/namespace {:namespace/id "org.clojure/clojure/clojure.pprint"} :definition/group "org.clojure" :definition/artifact "clojure" :definition/doc "Execute the body as a pretty printing logical block with output to *out* which \nmust be a pretty printing writer. When used from pprint or cl-format this can be \nassumed. \n\nThis function is intended for use when writing custom dispatch functions.\n\nBefore the body the caller can optionally specify options: :prefix :per-line-prefix \nand :suffix." @@ -135,7 +135,7 @@ :definition/col 1} {:definition/id "org.clojure/clojure/clojure.pprint/print-table/0" :definition/defined-by "clojure.core/defn" - :definition/library {:library/id "org.clojure/clojure/clojure.pprint"} + :definition/namespace {:namespace/id "org.clojure/clojure/clojure.pprint"} :definition/filename "/src/clj/clojure/pprint/print_table.clj" :definition/row 11 :definition/added "1.3" From 4e331cfa4ab8ba661f25baa6bd86f92856a0db4a Mon Sep 17 00:00:00 2001 From: Rafael Delboni Date: Tue, 2 May 2023 10:43:37 -0300 Subject: [PATCH 2/2] test: adds namespace query on playground --- dev/playground.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/playground.clj b/dev/playground.clj index 4442b0c..4707c12 100644 --- a/dev/playground.clj +++ b/dev/playground.clj @@ -67,8 +67,8 @@ :definition/name :definition/group :definition/artifact - :definition/namespace - :definition/git-source]) ...] + :definition/git-source + {:definition/namespace [:namespace/name]}]) ...] :in $ ?q :where [(str ".*" ?q ".*") ?pattern]