Skip to content

Commit

Permalink
Merge pull request #7 from clj-codes/refact/library-to-namespace
Browse files Browse the repository at this point in the history
Refact/library to namespace
  • Loading branch information
rafaeldelboni authored May 2, 2023
2 parents 652a980 + 4e331cf commit ea7d95f
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 120 deletions.
4 changes: 2 additions & 2 deletions dev/playground.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
52 changes: 26 additions & 26 deletions src/codes/clj/docs/extractor/adapters.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand All @@ -153,13 +153,13 @@
[])
(id-by (juxt :definition/group
:definition/artifact
:definition/namespace
#(get-in % [:definition/namespace :namespace/name])
:definition/name)
:definition/id)
(remove inrelevant-definitions)))

(defn analysis->datoms
[analysis]
(concat (analysis->projects analysis)
(analysis->libraries analysis)
(analysis->namespaces analysis)
(analysis->definitions analysis)))
2 changes: 1 addition & 1 deletion src/codes/clj/docs/extractor/analysis.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
35 changes: 17 additions & 18 deletions src/codes/clj/docs/extractor/datalevin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))]
Expand Down
8 changes: 4 additions & 4 deletions test/codes/clj/docs/extractor/adapters_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
66 changes: 33 additions & 33 deletions test/codes/clj/docs/extractor/datalevin_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Loading

0 comments on commit ea7d95f

Please sign in to comment.