kumarshantanu / lein-sub

Leiningen plugin for executing tasks on sub-projects
67 stars 10 forks source link

Inheritence of select `project.clj` keys #16

Open enspritz opened 1 month ago

enspritz commented 1 month ago

An idea to increase utility of lein-sub: Ability to nominate which keys and values in project.clj are propagated to / inherited by sub-projects' project.cljs. This would reduce management load and reliance on humans to correctly propagate such hierarchical information into sub-projects.

Keys

In the larger picture, referencing Leiningen's sample.project.clj, I'm not seeing a clear pattern of which keys should be inherited by default and are safe to do so in the general case. Perhaps if lein-sub offered an affordance to allow authors to select which project.clj keys are inherited, (using my immediate self-interested needs for the sake of exposition):

; In the parent, and maybe in the sub-projects:
:sub-inheritable-project-keys [:manifest :min-lein-version :url :version]

With a default value of an empty seq or nil or whatever, no surprises will be foisted onto current, unsuspecting lein-sub users, and authors would be free to choose their own sets of keys to be subjected to inheritance. Maximal flexibility with no disruption.

As authors, our mental models will remain consistent if sub-projects can override inherited KV pairs by providing their own.

Back-references to parent projects

lein running in sub-projects will need some mechanism for accessing their inherited key/value pairs. Because sub-project path designations can be arbitrary, sub-projects will need to establish "parent" or back-link reckoning on their own terms. Maven solves this using the notion of parent POMs:

<parent>
   <relativePath>../pom.xml</relativePath>
...

Leiningen directly uses that mechanism with the :parent key. A similar approach seems entirely workable here:

; In project.clj:
:subs ["module/foo-common"]

; In module/foo-common/project.clj:
:sub-parent "../.."

This necessitates thinking of nested projects and inheritance of project KVs in multi-level, transitive terms.

Nomenclature: Maven and indeed Leiningen has already established the notion of "parent", although the more correct antonym of "sub" is "super". Maybe there is an opportunity to create a catchy, memorable key to indicate the parent (not) like :sub-super.

I fully expect management of forward and backward filesystem path references for authors to be a low-load task, easy to debug, nearly pain free. A delight, in fact, for the gains we receive in return!

enspritz commented 1 month ago

Just riffing on some ideas for simple structuring


; lib/project.clj
:sub ["module-a"
      "module-b"
      "module-c"
      :keys [:exclusions :repositories]]

; lib/module-a/project.clj
:sub [:parent ".."]
enspritz commented 1 month ago

Just noticed https://github.com/achin/lein-parent ...