deps-new

hlship 2024-01-09T00:39:53.871089Z

Has there been any thought about having deps-new not require the awkward '-Sdeps' part, to use a custom template? Ideally, I should be able to clj -Tnew create :template ... and the tool should (somehow!) find the latest version of the dependency and download it; possibly it could create a temporary deps.edn and invoke clojure in a subshell to do the actual download & execution?

practicalli-johnny 2024-01-09T01:14:23.016129Z

I use the following command form when creating new templates (which I do quite regularly several times a month)

clojure -T:project/create :template :practicalli/service :name practicalli/project-name

practicalli-johnny 2024-01-09T01:18:03.343069Z

I use deps-new via an alias rather than an installed tool. An alias allows for default options and additional libraries (I.e. template libraries) to be included (which a tool currently doesn't as far as I am aware) https://practical.li/clojure/clojure-cli/projects/templates/

seancorfield 2024-01-09T01:28:27.530439Z

@jr0cket The issue is for third-party templates in general tho'...

seancorfield 2024-01-09T01:29:02.205539Z

@hlship Can you open an issue on GH so I don't forget -- and I'll give it some thought.

seancorfield 2024-01-09T01:30:47.135349Z

Currently, the template arg is a qualified path into the GH repo so it isn't the repo group/artifact ID. That said, I believe clj-new does have a sort of solution for this using an expanded template arg...

hlship 2024-01-09T23:34:29.481369Z

https://github.com/seancorfield/deps-new/issues/55

hlship 2024-01-09T00:40:37.131549Z

Fortunately, the current approach is not something you do every day!

hlship 2024-01-09T23:23:43.728559Z

Am I missing something? I'm look at https://github.com/seancorfield/deps-new/blob/develop/src/org/corfield/new/impl.clj#L30 and it is looking for the template.edn file specifically as a file on the classpath; this works for :git/url coordinates, because those are downloaded to a local workspace directory, but not for templates that have been packaged into JARs:

> clojure  -Sdeps '{:deps {io.pedestal/pedestal.embedded {:mvn/version "0.7.0-SNAPSHOT"}}}' -Tnew create :template io.pedestal/embedded :name com
Execution error (ExceptionInfo) at org.corfield.new/create (new.clj:58).
Unable to find template.edn for io.pedestal/embedded

Full report at:
/var/folders/yg/vytvxpw500520vzjlc899dlm0000gn/T/clojure-8259462039828199215.edn
> cat /var/folders/yg/vytvxpw500520vzjlc899dlm0000gn/T/clojure-8259462039828199215.edn
{:clojure.main/message
 "Execution error (ExceptionInfo) at org.corfield.new/create (new.clj:58).\nUnable to find template.edn for io.pedestal/embedded\n",
 :clojure.main/triage
 {:clojure.error/class clojure.lang.ExceptionInfo,
  :clojure.error/line 58,
  :clojure.error/cause
  "Unable to find template.edn for io.pedestal/embedded",
  :clojure.error/symbol org.corfield.new/create,
  :clojure.error/source "new.clj",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.ExceptionInfo,
    :message "Unable to find template.edn for io.pedestal/embedded",
    :data {},
    :at [org.corfield.new$create invokeStatic "new.clj" 58]}],
  :trace
  [[org.corfield.new$create invokeStatic "new.clj" 58]
   [org.corfield.new$create invoke "new.clj" 41]
   [clojure.lang.Var invoke "Var.java" 384]
   [clojure.run.exec$exec invokeStatic "exec.clj" 89]
   [clojure.run.exec$exec invoke "exec.clj" 78]
   [clojure.run.exec$_main$fn__220 invoke "exec.clj" 228]
   [clojure.run.exec$_main invokeStatic "exec.clj" 224]
   [clojure.run.exec$_main doInvoke "exec.clj" 192]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause "Unable to find template.edn for io.pedestal/embedded",
  :data {}}}

>

seancorfield 2024-01-10T08:43:02.845169Z

I have a format for the extended template name -> git repo + deps/root + template-symbol + tag (version), but part of the resolution for that is to add that as a local dependency to the classpath and that bit needs more thought...

seancorfield 2024-01-10T09:39:01.526979Z

(~/clojure)-(!2007)-> clj -Ttools install io.github.seancorfield/deps-new '{:git/sha "047c9650e1005a543bb0c8462e56cebd6c6d9661"}' :as new
new: Installed io.github.seancorfield/deps-new 047c965

Wed Jan 10 01:36:50
(~/clojure)-(!2008)-> clojure -A:1.12 -Tnew create :template io.github.pedestal/pedestal%embedded%io.pedestal/embedded :name what/ever
Resolving io.github.pedestal/pedestal as a git dependency
Creating project from io.pedestal/embedded in ever

Wed Jan 10 01:37:00
(~/clojure)-(!2009)-> tree ever
ever
├── CHANGELOG.md
├── LICENSE
├── README.md
├── build.clj
├── deps.edn
├── dev
│   ├── dev.clj
│   └── user.clj
├── doc
│   └── intro.md
├── resources
│   └── public
│       └── index.html
├── src
│   └── what
│       └── ever
│           ├── routes.clj
│           └── service.clj
├── test
│   └── what
│       └── ever
│           └── service_test.clj
└── test-resources
    └── logback-test.xml

11 directories, 13 files

Wed Jan 10 01:37:03
(~/clojure)-(!2010)->
The only wrinkle is that it requires Clojure 1.12 for the dynamic addition of a dependency to the classpath -- hence the :1.12 alias:
:1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.0-alpha5"}}}
(in my user deps.edn)

seancorfield 2024-01-10T09:52:06.582959Z

io.github.pedestal/pedestal%embedded%io.pedestal/embedded is pretty much the worst scenario since it's a multi-repo so it requires a deps/root value. The simplest would be io.github.pedestal/embedded -- a separate repo under the pedestal org and then resources/io/github/pedestal/embedded/template.edn as the location of EDN file.

hlship 2024-01-10T16:54:00.281949Z

I've gotten around the classpath issue by building a basis, generating a classpath, then spawning a subprocess running Java w/ that classpath to do the actual work.

seancorfield 2024-01-10T17:21:31.787779Z

Yeah, I'm not sure I want to add that level of complexity but it's not off the table. I'm talking to Alex about the 1.11/1.12 tool-running issue and we'll see how that turns out.

seancorfield 2024-01-09T23:41:29.366089Z

The README says: > deps-new only supports :local/root and git-based coordinates, not Maven/Clojars coordinates. (near the top)

hlship 2024-01-09T23:41:50.940349Z

I missed that! Would you be open to a PR on this subject?

seancorfield 2024-01-09T23:42:01.034839Z

A PR to do... what?

hlship 2024-01-09T23:42:19.767869Z

Allow the template.edn and other files to be on the classpath.

hlship 2024-01-09T23:42:34.829189Z

As JAR resources, rather than local files.

seancorfield 2024-01-09T23:43:38.755489Z

From further down in the README: > Note: because deps-new is based on tools.build and uses its file copying functions, the template must ultimately live on the filesystem, so :local/root and git-based coordinates are supported, but Maven/Clojars coordinates are not.

hlship 2024-01-09T23:45:49.812959Z

There are surely ways to work around that, either by not using the tools.build functions if they can't work around using Java resources rather than purely filesystem ... or by unpacking the JAR file to the filesystem so that copying can take place.

hlship 2024-01-09T23:46:35.044319Z

Getting away from implementation details, do you agree that distribution via Maven repo, rather exclusively by Git coord, would be valuable? I think it would be.

seancorfield 2024-01-09T23:46:44.487549Z

No, I don't agree.

seancorfield 2024-01-09T23:47:40.346729Z

deps-new is specifically designed for local- and git- deps. clj-new supports Maven artifacts but has programmatic, rather than declarative templates (and I'm not actively maintaining that any more really).

hlship 2024-01-09T23:51:28.995419Z

As a template creator, I want to streamline the process for my end-users to leverage my template. We have a long-established method of packaging code and resources together, a Maven artifact. deps-new needs a small amount of code, and some resources to generate a project from a template. I fail to see why having that code and resources be file-system based is an advantage.

hlship 2024-01-09T23:52:09.712979Z

Now I not only will have to document using -Sdeps, but I'll have to either write docs that say "download this thing and unpack it" or "use the Git URL, sha, and tag".

seancorfield 2024-01-09T23:53:45.097509Z

The issue you created to have deps-new deduce the Git URL and template "name" from the group/artifact will remove the need for -Sdeps and streamline the process.

seancorfield 2024-01-09T23:55:21.933659Z

io.github.pedestal/some-repo or io.github.pedestal/some-repo:some-template will be the full template name. Something like that. clj-new supports something like that for git-deps as I recall?

hlship 2024-01-09T23:55:40.534489Z

I never used clj-new, so I can't say.

hlship 2024-01-09T23:57:01.069959Z

Because Pedestal is a multi-project, when using a :git/url coordinate, I have to specify :deps/root. Not sure how that's going to work, as it's not something actually encoded into the artifact id.

hlship 2024-01-09T23:57:24.143629Z

These concerns are far from universal, but not nearly unique either.

hlship 2024-01-09T23:58:36.635059Z

I suppose io.github.pedestal/pedestal:embedded might work, with the embedded suffix turning into a :deps/root.

hlship 2024-01-10T00:01:44.265729Z

With the further question on how to resolve, from that, the correct namespace (`io.pedestal.deps`) -- or I'll have to move that code elsewhere.

seancorfield 2024-01-10T00:02:36.696969Z

Hmm, clj-new's git-dep usage isn't as nice as I remembered -- but it predates a lot of the git provider URL deduction logic inside tools.deps. Anyway, I will make this a lot more pleasant when I address that issue.

hlship 2024-01-10T00:02:57.383249Z

I can't way to see and try!

seancorfield 2024-01-10T00:05:05.047559Z

Forgive my slightly sharp responses here -- I've had a very trying few days with my partner caught up in the storms in Texas (they were supposed to be back here on West Coast yesterday -- now they should be flying back tomorrow), so I've been holding down the fort here on my own for five days at this point...

seancorfield 2024-01-10T00:05:46.204799Z

I'm headed out to the gym in a few. Expect to see some movement on deps-new and friendlier templates this weekend (my partner will be away again).

hlship 2024-01-10T00:06:04.823909Z

Looking forward to it!

hlship 2024-01-09T23:26:47.599049Z

I was blind-sided because the template worked fine locally.

2024-01-09T23:34:26.941199Z

2024-02-03T20:48:55.924779Z