Repository: palmetto/palm-cli (language: python)

Issue:
Improve boilerplate commands when scaffolding
<!-- Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below. -->
## Pull request checklist

Before submitting your PR, please review the following checklist:

- [ ] Consider adding a unit test if your PR resolves an issue.
- [x] All new and existing tests pass locally (`palm test`)
- [x] Lint (`palm lint`) has passed locally and any fixes were made for failures
- [x] Docs have been reviewed and added / updated if needed (for bug fixes / features)

### Breaking changes

- [ ] Check if this pull request introduces a breaking change

## What does this implement/fix? Explain your changes.

The `@click.pass_obj` decorator passes `ctx.obj` to the command, by naming this arg `environment` we create a much more obvious interface to `Environment` instance methods.
Also added some commented out examples for run_in_docker and run_on_host, which should improve developer experience for folks that are new to palm.

## Does this close any currently open issues?
…

## Any other comments?
…

## Where has this been tested?

**Operating System:** Mac OS



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml
index adeda4b..891301e 100644
--- a/.github/workflows/pull_request.yaml
+++ b/.github/workflows/pull_request.yaml
@@ -9,12 +9,20 @@ on:
 jobs:
   test:
     runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python-version:
+          - 3.6
+          - 3.7
+          - 3.8
+          - 3.9
     steps:
       - uses: actions/checkout@v2
       - name: Install Python 3
         uses: actions/setup-python@v1
         with:
-          python-version: 3.8
+          python-version: ${{ matrix.python-version }}
+          architecture: x64
       - name: Install dependencies
         run: |
           python -m pip install --upgrade pip
@@ -28,4 +36,5 @@ jobs:
       - uses: actions/checkout@v2
       - uses: psf/black@stable
         with:
-          options: '--check --diff --skip-string-normalization --exclude="\.tpl\.py"'
\ No newline at end of file
+          options: '--check --diff --skip-string-normalization --exclude="\.tpl\.py"'
+          version: '21.12b0'
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 843ab6f..e4c9cf7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,18 @@
 # Palm CLI Changelog
 
+## 2.1.1
+
+> 7/2/2022
+
+### Bug fixes
+* Resolve a template issue when running `palm plugin new` 
+
+### Improvements
+* Command templates now use click's @pass_obj decorator and pass the `environment`
+argument, this is a cleaner API for interacting with the Palm.Environment class
+* CI now runs against multiple python versions
+* Black version is pinned for consistency between local & CI runs
+
 ## 2.1.0
 
 > 12/01/2021
diff --git a/dev-requirements.txt b/dev-requirements.txt
index d6e7b8e..c7a6677 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,3 +1,3 @@
 -r requirements.txt
 pytest >= 6.2, < 6.3
-black >= 19.10b0, < 20.0
\ No newline at end of file
+black == 21.12b0
\ No newline at end of file
diff --git a/docs/source/conf.py b/docs/source/conf.py
index a5b6c9a..4a8f625 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -22,7 +22,7 @@
 author = 'Palmetto Data Team'
 
 # The full version, including alpha/beta/rc tags
-release = '2.1.0'
+release = '2.1.1'
 
 
 # -- General configuration ---------------------------------------------------
diff --git a/palm/plugins/core/templates/command/new_cmd.tpl.py b/palm/plugins/core/templates/command/new_cmd.tpl.py
index f214835..c2d484c 100644
--- a/palm/plugins/core/templates/command/new_cmd.tpl.py
+++ b/palm/plugins/core/templates/command/new_cmd.tpl.py
@@ -2,7 +2,12 @@
 
 
 @click.command('{{command}}')
-@click.pass_context
-def cli(ctx):
+@click.pass_obj
+def cli(environment):
     """{{command}}"""
-    click.echo("{{command}} command running!")
+    click.echo("palm executing {{command}}")
+    command = f"echo '{{command}} running!'"
+    # Run your command in docker:
+    # environment.run_in_docker(command)
+    # Or on the host:
+    # environment.run_on_host(command)
diff --git a/palm/plugins/core/templates/command_group/new_cmd_group.tpl.py b/palm/plugins/core/templates/command_group/new_cmd_group.tpl.py
index 9b27d57..4090006 100644
--- a/palm/plugins/core/templates/command_group/new_cmd_group.tpl.py
+++ b/palm/plugins/core/templates/command_group/new_cmd_group.tpl.py
@@ -9,9 +9,14 @@ def cli():
 
 {% for command in commands %}
 @cli.command()
-@click.pass_context
-def {{command}}(ctx):
+@click.pass_obj
+def {{command}}(environment):
     """{{command}}"""
     click.echo("{{command}} command running!")
+    command = "echo {{command}} running" 
+    # Run your command in docker:
+    # environment.run_in_docker(command)
+    # Or on the host:
+    # environment.run_on_host(command)
 
 {% endfor %}
\ No newline at end of file
diff --git a/palm/plugins/core/templates/plugin/template-config.yaml b/palm/plugins/core/templates/plugin/template-config.yaml
index c7465aa..1107395 100644
--- a/palm/plugins/core/templates/plugin/template-config.yaml
+++ b/palm/plugins/core/templates/plugin/template-config.yaml
@@ -8,4 +8,4 @@ files:
     - plugin_template.tpl.py: 'palm/plugins/{{plugin_name}}/{{plugin_name}}_plugin.py'
     - empty_file.py: 'palm/plugins/{{plugin_name}}/commands/__init__.py'
     - empty_file.py: 'README.md'
-    - setup.py: 'setup.py'
\ No newline at end of file
+    - setup.tpl.py: 'setup.py'
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 40054dc..4bab112 100644
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@
 
 setup(
     name='palm',
-    version='2.1.0',  # Don't forget to bump the version in docs/source/conf.py too!
+    version='2.1.1',  # Don't forget to bump the version in docs/source/conf.py too!
     description='Palm CLI',
     long_description=long_description,
     long_description_content_type='text/markdown',


Test patch:
diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py
index 2a85a09..2f786f6 100644
--- a/tests/unit/test_cli.py
+++ b/tests/unit/test_cli.py
@@ -90,7 +90,7 @@ def test_scaffold_new_command_group(use_palm_dir):
     target_path = Path('.palm', 'cmd_groupname.py')
     assert target_path.exists()
     assert "@click.group()" in target_path.read_text()
-    assert "def test(ctx):" in target_path.read_text()
+    assert "def test(environment):" in target_path.read_text()
 
 
 def test_scaffold_config(use_palm_dir):
diff --git a/tests/unit/test_plugin_new.py b/tests/unit/test_plugin_new.py
new file mode 100644
index 0000000..153f859
--- /dev/null
+++ b/tests/unit/test_plugin_new.py
@@ -0,0 +1,12 @@
+import yaml
+from pathlib import Path
+
+path_suffix = "palm/plugins/core/templates/plugin/"
+plugin_dir = Path.cwd() / path_suffix
+
+
+def test_defined_template_files_exist():
+    """Simple but a place bugs hide"""
+    plugin_conf = yaml.safe_load((plugin_dir / "template-config.yaml").read_text())
+    for filename in [list(f.keys())[0] for f in plugin_conf["files"]]:
+        assert (plugin_dir / filename).exists()