-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
neil new
: Add support for deps-based templates
#51
Merged
Merged
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6719349
Add support for deps-based templates
rads c3ad5ba
Add tests
rads 88295d7
Add :dry-run option
rads 3d20a98
Update tests
rads d44b50e
Add new-overrides-test
rads ed3ec1f
Update tests
rads 550d00c
Use requiring-resolve in deps-new-create
rads 4a76ad3
Clean up opts
rads 73bd509
Restrict lib options to only valid combinations
rads bc92e9d
Use :git/tag instead of :git/sha by default when omitted
rads 249e2d4
Improve template-libs logic and update tests
rads a6ee586
Clean up template-deps function and add docstrings
rads 1a8243d
Add support for :sha and :latest-sha
rads 6369e5e
Update help
rads 8c149dd
Infer GitHub repo from :git/url instead of :template
rads 233eda5
Update docs
rads 619a7b6
Move docs to neil new --help
rads 57d9a3e
Add --local/root to docs
rads d3693ff
Add create-opts-deny-list
rads 471d6fe
Clean up duplicated code
rads cc7bc47
Fix Clojure compatibility
rads e08f386
Use prn instead of pr
rads f838cd7
Use "external" instead of "remote"
rads 1085be8
Fix error when using built-in templates from babashka
rads aa6eea6
Update docstring
rads File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,13 @@ | |
(require '[babashka.classpath :as cp] | ||
'[babashka.cli :as cli] | ||
'[babashka.curl :as curl] | ||
'[babashka.deps :as deps] | ||
'[babashka.fs :as fs] | ||
'[borkdude.rewrite-edn :as r] | ||
'[cheshire.core :as cheshire] | ||
'[clojure.edn :as edn] | ||
'[clojure.string :as str]) | ||
|
||
;; deps-new reads classpath from property | ||
(System/setProperty "java.class.path" (cp/get-classpath)) | ||
|
||
(def spec {:lib {:desc "Fully qualified library name."} | ||
:version {:desc "Optional. When not provided, picks newest version from Clojars or Maven Central."} | ||
:sha {:desc "When provided, assumes lib refers to Github repo."} | ||
|
@@ -364,6 +362,11 @@ | |
:target-dir | ||
:overwrite | ||
|
||
; template deps overrides | ||
:local/root | ||
:git/url | ||
:git/sha | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the deps-new docs:
|
||
|
||
; optional overrides | ||
:artifact/id | ||
:description | ||
|
@@ -381,11 +384,29 @@ | |
:user | ||
:version]) | ||
|
||
(defn- built-in-template? [template] | ||
(contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) | ||
|
||
(defn- github-repo-url [lib] | ||
(str "https://github.com/" (clean-github-lib lib))) | ||
|
||
(defn- add-template-deps [template opts] | ||
(let [lib (edn/read-string template) | ||
rads marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local-root (:local/root opts)] | ||
(if local-root | ||
(deps/add-deps {:deps {lib {:local/root local-root}}}) | ||
(let [url (or (:git/url opts) (github-repo-url lib)) | ||
sha (or (:git/sha opts) (latest-github-sha lib))] | ||
(deps/add-deps {:deps {lib {:git/url url :git/sha sha}}}))))) | ||
|
||
(defn run-deps-new [{:keys [opts]}] | ||
(require 'org.corfield.new) | ||
(let [{:keys [template] | ||
:or {template "scratch"}} opts | ||
template-fn (requiring-resolve (symbol "org.corfield.new" template))] | ||
(template-fn (dissoc opts :template)) | ||
:or {template "scratch"}} opts] | ||
(when-not (built-in-template? template) | ||
(add-template-deps template opts)) | ||
(System/setProperty "java.class.path" (cp/get-classpath)) | ||
((resolve 'org.corfield.new/create) opts) | ||
nil)) | ||
|
||
(defn print-help [_] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{:paths ["src"] | ||
:deps {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(ns scratch | ||
"FIXME: my new io.github.rads/kit project.") | ||
|
||
(defn exec | ||
"Invoke me with clojure -X scratch/exec" | ||
[opts] | ||
(println "exec with" opts)) | ||
|
||
(defn -main | ||
"Invoke me with clojure -M -m scratch" | ||
[& args] | ||
(println "-main with" args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{:paths ["src"] | ||
:deps {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(ns scratch | ||
"FIXME: my new org.corfield.new/scratch project.") | ||
|
||
(defn exec | ||
"Invoke me with clojure -X scratch/exec" | ||
[opts] | ||
(println "exec with" opts)) | ||
|
||
(defn -main | ||
"Invoke me with clojure -M -m scratch" | ||
[& args] | ||
(println "-main with" args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary to explicitly list all the options. Babashka CLI automatically parses all command line flags. The list your using here is for converting options in order to options, using
:cmds-opts
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I updated the
:cmds-opts
to be[:template :name :target-dir]
. These are the ones that made most sense to me as positional arguments.For the special named arguments which are not directly supported by
deps-new
(:git/url
,:git/sha
,:git/tag
,:local/root
), we'll probably want to add those to theneil help
docs in addition to the existing link to thedeps-new
override options.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On line 16 (on main) we already have a bunch of options. I'd prefer if we could align the names of options, even if they are used in different contexts. Since we already have
:sha
, maybe we should re-use that one? Or should we deprecate it and rename it to:git/sha
(with:sha
being an:alias
for:git/sha
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@borkdude: Here's the solution I came up with:
neil new
will always accept namespaced keys like:git/sha
neil new
also supports the existing:sha
and:latest-sha
options:sha
is simply renamed to:git/sha
before parsing:latest-sha
provides an alternative to fetching the latest:git/tag
(which is the default behavior when neither:git/tag
,:git/sha
, nor:latest-sha
is provided)neil new
that are not already inbabashka.neil/spec
should be documented specifically forneil new
. If we find someneil new
options to be useful elsewhere, we can promote them tobabashka.neil/spec
as needed.What do you think about this?