Skip to content

Instantly share code, notes, and snippets.

@nkabir
Created December 1, 2020 17:46
Show Gist options
  • Save nkabir/1bdc1ab1d6682fb61dae2bd46f779fd6 to your computer and use it in GitHub Desktop.
Save nkabir/1bdc1ab1d6682fb61dae2bd46f779fd6 to your computer and use it in GitHub Desktop.
Project Initialization
;; #############################################################################
;;
;; glassware.hy
;; glassware utilities
;;
;; #############################################################################
(import subprocess)
(import [autologging [logged]])
(import [bench.fp.util.path :as path])
(import [bench.fp.mount.YamlFileKit :as YamlFileKit])
(import [catalog.fp.util.glasswork :as glasswork])
(import [glassmith.fp.prepost.core :as prepost])
;; ignore
;; glassware.yaml - project configuration
;; glassware - glassware collection
(setv RSYNC-CMD "rsync --delete -Ccavz --exclude=glassware.yaml --exclude=glassware.dhall --exclude=glassware --exclude=/.git {}/ {}")
;; :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#@(logged
(defclass Glassmith [YamlFileKit.YamlFile]
"Glassmith parses a project's 'glassware.yaml' and generates the
associated 'glass' for the project."
;; ------------------------------------------------------------------
(defn --init-- [self &kwargs kwargs]
(.--init-- (super) (unpack-mapping kwargs)))
;; ------------------------------------------------------------------
(defn refresh [self]
"""Refreshes a glassware project. Starting with the root of
the configuration file, traverse names and properties and
generate associated cookiecutter templates into a temporary
folder.
The new temporary folder is then rsynced with delete into this
project folder. This ensures that entries from
`glassware.yaml` that have been removed are also deleted from
the generated source."""
(do
(setv output-path (. self.path parent))
(.debug self.--log f"output-path {output-path}")
(setv temp-folder (path.extend (path.temp-path-rand)
output-path.name))
(setv config-tree (glasswork.config-tree (.yaml self)))
(glasswork.render-tree config-tree
temp-folder
self.folio-path
self.common-settings
self.no-input?
self.overwrite?)
;; rsync temp folder to output-path
(setv cmd-rsync (.format RSYNC-CMD temp-folder output-path))
(.call subprocess (.split cmd-rsync " "))
(.debug self.--log "Completing refresh...")))))
;; :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#@(logged
(defn make [glassware-yaml-path ; path to yaml configuration
&optional
[folio-path prepost.TEMPLATES-DA]
[common-settings None]
[no-input? True]
[overwrite? True]
[loaded? True]]
(do
(if-not common-settings
(setv common-settings {}))
(setv glassmith (Glassmith :path glassware-yaml-path
:folio-path folio-path
:common-settings common-settings
:no-input? no-input?
:overwrite? overwrite?))
(if loaded?
(.load glassmith))
(return glassmith))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment