Repository: hylang/hy

Issue:
Add documentation for package management
What's the correct idiomatic way to publish hylang packages? should it be published on pip using `hylang-[packagename]`?

I want to write a package that uses hylang features that python doesn't have (ie: macros)

Edit: This should be added to the docs


Discussion:
This is Hy's issue list. For help using Hy, try elsewhere.
@Kodiologist Apologies, I didn't phrase this well -- this is an actionable item: Adding documentation for how to package Hy packages

Resolving patch:
diff --git a/hy/core/result_macros.py b/hy/core/result_macros.py
--- a/hy/core/result_macros.py
+++ b/hy/core/result_macros.py
@@ -162,6 +162,17 @@ def compile_inline_python(compiler, expr, root, code):
     return Result(stmts=o) if exec_mode else o
 
 
+@pattern_macro("pragma", [many(KEYWORD + FORM)])
+def compile_pragma(compiler, expr, root, kwargs):
+    for kw, value in kwargs:
+        if kw == Keyword("warn-on-core-shadow"):
+            compiler.local_state_stack[-1]['warn_on_core_shadow'] = (
+                bool(compiler.eval(value)))
+        else:
+            raise compiler._syntax_error(kw, f"Unknown pragma `{kw}`. Perhaps it's implemented by a newer version of Hy.")
+    return Result()
+
+
 # ------------------------------------------------
 # * Quoting
 # ------------------------------------------------
@@ -470,6 +481,19 @@ def compile_def_expression(compiler, expr, root, decls):
     return result
 
 
+@pattern_macro("let", [brackets(many(maybe_annotated(FORM) + FORM)), many(FORM)])
+def compile_let(compiler, expr, root, bindings, body):
+    res = Result()
+    bindings = bindings[0]
+    scope = compiler.scope.create(ScopeLet)
+
+    for (target, ann), value in bindings:
+        res += compile_assign(compiler, ann, target, value, let_scope=scope)
+
+    with scope:
+        return res + compiler.compile(mkexpr("do", *body).replace(expr))
+
+
 @pattern_macro(["annotate"], [FORM, FORM])
 def compile_basic_annotation(compiler, expr, root, target, ann):
     return compile_assign(compiler, ann, target, None)
@@ -526,6 +550,14 @@ def compile_assign(
     return result
 
 
+@pattern_macro(((3, 12), "deftype"), [maybe(type_params), SYM, FORM])
+def compile_deftype(compiler, expr, root, tp, name, value):
+    return asty.TypeAlias(expr,
+       name = asty.Name(name, id = mangle(name), ctx = ast.Store()),
+       value = compiler.compile(value).force_expr,
+        **digest_type_params(compiler, tp))
+
+
 @pattern_macro(["global", "nonlocal"], [many(SYM)])
 def compile_global_or_nonlocal(compiler, expr, root, syms):
     if not syms:
@@ -2003,38 +2035,6 @@ def compile_assert_expression(compiler, expr, root, test, msg):
     )
 
 
-@pattern_macro("let", [brackets(many(maybe_annotated(FORM) + FORM)), many(FORM)])
-def compile_let(compiler, expr, root, bindings, body):
-    res = Result()
-    bindings = bindings[0]
-    scope = compiler.scope.create(ScopeLet)
-
-    for (target, ann), value in bindings:
-        res += compile_assign(compiler, ann, target, value, let_scope=scope)
-
-    with scope:
-        return res + compiler.compile(mkexpr("do", *body).replace(expr))
-
-
-@pattern_macro(((3, 12), "deftype"), [maybe(type_params), SYM, FORM])
-def compile_deftype(compiler, expr, root, tp, name, value):
-    return asty.TypeAlias(expr,
-       name = asty.Name(name, id = mangle(name), ctx = ast.Store()),
-       value = compiler.compile(value).force_expr,
-        **digest_type_params(compiler, tp))
-
-
-@pattern_macro("pragma", [many(KEYWORD + FORM)])
-def compile_pragma(compiler, expr, root, kwargs):
-    for kw, value in kwargs:
-        if kw == Keyword("warn-on-core-shadow"):
-            compiler.local_state_stack[-1]['warn_on_core_shadow'] = (
-                bool(compiler.eval(value)))
-        else:
-            raise compiler._syntax_error(kw, f"Unknown pragma `{kw}`. Perhaps it's implemented by a newer version of Hy.")
-    return Result()
-
-
 @pattern_macro(
     "unquote unquote-splice unpack-mapping except except* finally else".split(),
     [many(FORM)],


Test patch: