Skip to content

Instantly share code, notes, and snippets.

@rameezk
Created March 4, 2021 07:34
Show Gist options
  • Save rameezk/c6e467510192edf9a963cfba067f0c18 to your computer and use it in GitHub Desktop.
Save rameezk/c6e467510192edf9a963cfba067f0c18 to your computer and use it in GitHub Desktop.
Get latest python deps from Pipfile
;;;; usage: cat Pipfile | bb -io get_latest_python_deps_from_pipfile.clj
;;;; prerequisites
;;;; - lastversion (pipx install lastversion)
;;;; - babashka (brew install borkdude/brew/babashka)
(ns script
(:require [clojure.java.io :as io]
[clojure.java.shell :refer [sh]]
[clojure.string :as str]))
(def lines
(line-seq (io/reader *in*)))
(defn- is-package?
"Checks if line is a valid package"
[line]
(some? (re-find #"\w+\s*=\s\"[~|=]=.*" line)))
(defn- package-name
"Get the package name"
[line]
(second (re-matches #"([-\w]+)\s*=\s*.*" line)))
(defn- latest-version
"Get latest version of package"
[package]
(str/trim-newline
(:out
(sh "lastversion" "--at" "pip" package))))
(defn find-latest-versions
"Find the latest versions"
[lines]
(for [line lines
:let [pkg (package-name line)]
:when (is-package? line)]
(let [latest-version (latest-version pkg)]
(str pkg "==" latest-version))))
(find-latest-versions lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment