فهرست منبع

fix: Python 3.9 compatibility and dependency pinning (v0.0.6)

Fixes #1332 - Remove Context type annotations for Python 3.9 compatibility

- Remove Context type annotations causing RuntimeError on Python 3.9
- Use click.get_current_context() for runtime context access
- Pin all dependencies to specific tested versions
- Add tests directory to gitignore

Tested on Python 3.9.2 with Typer 0.12.5 and 0.19.2
Christian Lempa 4 ماه پیش
والد
کامیت
3df73c20c7
4فایلهای تغییر یافته به همراه23 افزوده شده و 10 حذف شده
  1. 3 0
      .gitignore
  2. 4 1
      cli/__main__.py
  3. 11 4
      cli/core/module.py
  4. 5 5
      requirements.txt

+ 3 - 0
.gitignore

@@ -23,3 +23,6 @@
 
 # Installation tracking
 .installed-version
+
+# Test outputs
+tests/

+ 4 - 1
cli/__main__.py

@@ -58,7 +58,6 @@ def setup_logging(log_level: str = "WARNING") -> None:
 
 @app.callback(invoke_without_command=True)
 def main(
-  ctx: Context,
   version: Optional[bool] = Option(
     None,
     "--version",
@@ -84,6 +83,10 @@ def main(
     # Silence all logging (including third-party) unless user explicitly requests it
     logging.disable(logging.CRITICAL)
   
+  # Get context without type annotation (compatible with all Typer versions)
+  import click
+  ctx = click.get_current_context()
+  
   # Store log level in context for potential use by other commands
   ctx.ensure_object(dict)
   ctx.obj['log_level'] = log_level

+ 11 - 4
cli/core/module.py

@@ -196,17 +196,25 @@ class Module(ABC):
       if successful:
         logger.debug(f"Applied config defaults for: {', '.join(successful)}")
 
-  def _apply_cli_overrides(self, template: Template, var: Optional[List[str]], ctx: Context) -> None:
+  def _apply_cli_overrides(self, template: Template, var: Optional[List[str]], ctx=None) -> None:
     """Apply CLI variable overrides to template.
     
     Args:
         template: Template instance to apply overrides to
         var: List of variable override strings from --var flags
-        ctx: Typer context containing extra args
+        ctx: Context object containing extra args (optional, will get current context if None)
     """
     if not template.variables:
       return
     
+    # Get context if not provided (compatible with all Typer versions)
+    if ctx is None:
+      import click
+      try:
+        ctx = click.get_current_context()
+      except RuntimeError:
+        ctx = None
+    
     extra_args = list(ctx.args) if ctx and hasattr(ctx, "args") else []
     cli_overrides = parse_var_inputs(var or [], extra_args)
     
@@ -460,7 +468,6 @@ class Module(ABC):
     dry_run: bool = Option(False, "--dry-run", help="Preview template generation without writing files"),
     show_files: bool = Option(False, "--show-files", help="Display generated file contents in plain text (use with --dry-run)"),
     quiet: bool = Option(False, "--quiet", "-q", help="Suppress all non-error output"),
-    ctx: Context = None,
   ) -> None:
     """Generate from template.
     
@@ -495,7 +502,7 @@ class Module(ABC):
 
     # Apply defaults and overrides
     self._apply_variable_defaults(template)
-    self._apply_cli_overrides(template, var, ctx)
+    self._apply_cli_overrides(template, var)
     
     # Re-sort sections after all overrides (toggle values may have changed)
     if template.variables:

+ 5 - 5
requirements.txt

@@ -1,5 +1,5 @@
-typer[all]>=0.9.0
-rich>=13.0.0
-PyYAML>=6.0
-python-frontmatter>=1.0.0
-Jinja2>=3.0
+typer==0.19.2
+rich==14.1.0
+PyYAML==6.0.2
+python-frontmatter==1.1.0
+Jinja2==3.1.6