#!/usr/bin/env hy ;;; Copyright © 2019 Jakob L. Kreuze ;;; ;;; This program is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as ;;; published by the Free Software Foundation; either version 3 of the ;;; License, or (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see ;;; . (require [hy.contrib.walk [let]]) (import [ast [parse Return]]) (import [copy [deepcopy]]) (import [os [getenv]]) (import [os.path [splitext]]) (import [sys [argv exit]]) (import [hy.compiler [hy-compile]]) (import [hy.lex [hy-parse]]) (import DUCK.Serpentine.visitor) (import [DUCK.Tools [buildhelper]]) (defn walk-ast [node] (when (and (isinstance node Return) (= node.value.id "None")) (setv node.value.id None)) (when (hasattr node "body") (for [child node.body] (walk-ast child)))) (defn my-hy-compile [source] (let [ast (hy-compile (hy-parse source) "")] (walk-ast ast) ast)) (defclass HyVisitor [DUCK.Serpentine.visitor.Visitor] (defn load [self file-name &optional [imports None]] (let [imports (or imports {})] (setv self.imports imports) (setv self.file-name- file-name) (try (with [source (open file-name :encoding (.get-coding self file-name))] (setv self.root (if (.endswith file-name ".hy") (my-hy-compile (.read source)) (parse (.read source))))) (except [err SyntaxError] (.write stderr (.format "In '{}': " file-name)) (raise err))) (let [module (.visit self self.root)] (assoc self.imports (first (splitext file-name)) module) (return module))))) (setv DUCK.Serpentine.visitor.Visitor HyVisitor) (when (= __name__ "__main__") (let [app-name "HelloHy" package-name "com.example.hellohy" res-files {"drawable" {"ic_launcher" "icon.svg"}} code-file "hello.hy" include-paths [] layout None features [] permissions [] docs-dir (getenv "DOCS_DIR") args (deepcopy argv)] (exit (.main buildhelper __file__ app-name package-name res-files layout code-file include-paths features permissions args :docs-dir docs-dir))))