Skip to content

tools.deps friendly utility for searching clojars and maven

Notifications You must be signed in to change notification settings

hagmonk/find-deps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

find-deps

What?

find-deps helps you quickly find dependencies via the Clojars and Maven search APIs. Use it via the command line, or from the REPL.

find-deps utilizes clj-fuzzy to refine the search results returned from repository APIs. It also factors in the freshness of the dependencies, and the popularity of the dependency’s group ID. We hope this results in a near-perfect suggestion every time!

See the Future section below for some ideas around where this can be taken. In particular, it would be great to enable searching for deps.edn files on github …

TL;DR

Add a dependency to your current deps.edn as easily as this:

clj -A:find-deps -F:save priority-map

Changelog

  • Note taken on [2018-06-25 Mon 10:39]
  • 2018-06-25
    • hide snapshot versions by default in clojars (fixes #2)
  • 2018-06-24
    • merged @pesterhazy’s README fix
  • 2018-06-23
    • fixed bug wherein it wasn’t possible to save deps without a preexisting deps.edn
    • added -F:cli format flag to print deps as command line option to `clojure` binary
  • 2018-06-17
    • change -S flag to -s to avoid conflict with tools.deps cli
    • enable piping of invocations together to produced merged deps.edn map
    • enable saving of deps.edn map with format :save
    • renamed :merged to :merge
  • 2018-06-16
    • Initial commit

CLI Usage

To use find-deps from the command line, create an alias in your ~/.clojure/deps.edn map:

{:aliases {:find-deps {:extra-deps
                         {find-deps
                            {:git/url "https://github.com/hagmonk/find-deps",
                             :sha "6fc73813aafdd2288260abb2160ce0d4cdbac8be"}},
                       :main-opts ["-m" "find-deps.core"]}}}

You can invoke find-deps with -h to see the supported options:

% clj -A:find-deps -h
find-deps

Usage: [options*] [search-strings*]

Options:
  -s, --sources SOURCES  :clojars:mvn  Concatenated source types
  -R, --rank METHOD      :fuzzy        Ranking method - :fuzzy, :regex
  -F, --format FORMAT    :deps         Format for printing results - :deps, :merge, :table, :save, :cli
  -l, --limit NUM        1             Limit per-search results to NUM
  -h, --help

Examples

Search for a dependency like http-kit:

clj -A:find-deps http-kit
{:deps {http-kit/http-kit {:mvn/version "2.3.0"}}}

Search for multiple dependencies:

clj -A:find-deps http-kit tools.logging priority-map
{:deps
 {http-kit/http-kit {:mvn/version "2.3.0"},
  org.clojure/tools.logging {:mvn/version "0.5.0-alpha"},
  org.clojure/data.priority-map {:mvn/version "0.0.9"}}}

Chain together multiple invocations using different query arguments:

clj -A:find-deps -s:mvn roaringbitmap | clj -A:find-deps -s:clojars -R:regex -l 5 io.pedestal
{:deps
 {org.roaringbitmap/RoaringBitmap  {:mvn/version "0.7.13"},
  io.pedestal/pedestal.jetty       {:mvn/version "0.5.3"},
  io.pedestal/pedestal.tomcat      {:mvn/version "0.5.3"},
  io.pedestal/pedestal.log         {:mvn/version "0.5.3"},
  io.pedestal/pedestal.service     {:mvn/version "0.5.3"},
  io.pedestal/pedestal.interceptor {:mvn/version "0.5.3"}}}

Merge the search results into the current project’s deps.edn. You can also save these results to deps.edn by specifying :save instead.

clj -A:find-deps -F:merge http-kit tools.logging priority-map
{:paths ["src"],
 :deps
 {org.clojure/clojure           {:mvn/version "1.9.0"},
  org.clojure/tools.logging     {:mvn/version "0.5.0-alpha"},
  org.clojure/spec.alpha        {:mvn/version "0.1.143"},
  clj-fuzzy                     {:mvn/version "0.4.1"},
  http-kit                      {:mvn/version "2.3.0"},
  tools.deps.alpha
  {:git/url "https://github.com/clojure/tools.deps.alpha",
   :sha     "884d7ae5b9c228ff795e4385291708102f1cd46d"},
  metosin/jsonista              {:mvn/version "0.1.1"},
  org.clojure/data.priority-map {:mvn/version "0.0.9"},
  inflections                   {:mvn/version "0.13.0"},
  http-kit/http-kit             {:mvn/version "2.3.0"}}
;; ... snip
 }

String search returning multiple matches in a table:

clj -A:find-deps -F:table -l 10 "apache kafka"

|                              :lib | :version |
|-----------------------------------+----------|
|      org.apache.kafka/kafka-tools |    1.1.0 |
|      org.apache.kafka/kafka_2.9.2 |  0.8.2.2 |
|      org.apache.kafka/kafka_2.9.1 |  0.8.2.2 |
|      org.apache.kafka/kafka_2.8.0 |  0.8.1.1 |
|      org.apache.kafka/kafka_2.8.2 |    0.8.1 |
|    org.apache.hadoop/hadoop-kafka |    3.1.0 |
|    org.apache.kafka/kafka-streams |    1.1.0 |
|    org.apache.kafka/kafka-clients |    1.1.0 |
|   org.apache.kafka/kafka-examples |    1.1.0 |
| org.apache.kafka/kafka-perf_2.8.0 |  0.8.1.1 |

Print out a command line invocation of the deps:

clj -A:find-deps -F:cli http-kit jsonista
clojure -Sdeps '{:deps {http-kit/http-kit {:mvn/version "2.3.0"}, metosin/jsonista {:mvn/version "0.2.1"}}}'

API

The find-deps.core namespace contains a number of helpers you can use from the REPL. Assuming you have an alias for rebel-readline:

clj -A:rebel
[Rebel readline] Type :repl/help for online help info
user=> (use 'find-deps.core)
nil
user=> (print-deps "http-kit")

|              :lib | :version |
|-------------------+----------|
| http-kit/http-kit |    2.3.0 |
nil
user=> (deps "http-kit")
{:deps #:http-kit{http-kit #:mvn{:version "2.3.0"}}}

See the find-deps.core namespace for more helpers.

Future

  • [ ] search github for deps.edn files
  • [ ] search github for project.clj files
    • [ ] page rank deps based on dependency graph
    • [ ] recommended other dependencies based on clustering
  • [ ] incorporate download counts into weighting factor
  • [x] support writing directly into deps.edn
  • [ ] support add-lib
  • [ ] add validation support to cli parser

About

tools.deps friendly utility for searching clojars and maven

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published