From 38957bf97f10b0a4efad2b2889966fe539c59a2a Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 16 May 2022 16:47:04 -0700 Subject: [PATCH 1/9] copy jinja and sphinx dependancies from Salt repo. Don't run lint against noxfile.py. --- src/saltext/cli/project/.pylintrc | 2 +- src/saltext/cli/project/setup.cfg.j2 | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/saltext/cli/project/.pylintrc b/src/saltext/cli/project/.pylintrc index 9ead2f3..15612f9 100644 --- a/src/saltext/cli/project/.pylintrc +++ b/src/saltext/cli/project/.pylintrc @@ -12,7 +12,7 @@ profile=no # Add files or directories to the blacklist. They should be base names, not # paths. -ignore=CVS,_version.py +ignore=CVS,_version.py,noxfile.py # Pickle collected data for later comparisons. persistent=yes diff --git a/src/saltext/cli/project/setup.cfg.j2 b/src/saltext/cli/project/setup.cfg.j2 index d74704f..c40ba6a 100644 --- a/src/saltext/cli/project/setup.cfg.j2 +++ b/src/saltext/cli/project/setup.cfg.j2 @@ -72,13 +72,15 @@ salt.loader= tests = pytest==6.2.4 pytest-salt-factories==0.911.0 + jinja2<3.1 dev = nox pre-commit==2.13.0 pylint SaltPyLint docs = - sphinx + sphinx>=3.5.1 + jinja2<3.1 furo sphinx-copybutton sphinx-prompt From f0cb8a75c2709fc17f0c9879438e0730b2735ead Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Mon, 14 Nov 2022 00:10:25 -0500 Subject: [PATCH 2/9] Fix SDB loader and add SDB template --- src/saltext/cli/__main__.py | 9 ++++++++- src/saltext/cli/templates.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/saltext/cli/__main__.py b/src/saltext/cli/__main__.py index 4eb9f92..8ee31ea 100644 --- a/src/saltext/cli/__main__.py +++ b/src/saltext/cli/__main__.py @@ -22,6 +22,7 @@ from saltext.cli.templates import MODULE_LOADER_TEMPLATE from saltext.cli.templates import PACKAGE_INIT from saltext.cli.templates import STATE_LOADER_TEMPLATE +from saltext.cli.templates import SDB_LOADER_TEMPLATE LICENSES: Dict[str, str] = { "apache": "License :: OSI Approved :: Apache Software License", @@ -250,7 +251,11 @@ def main( loaders_integration_tests_path = destdir / "tests" / "integration" for loader_name in loader: templating_context["loader"] = loader_name - loader_dir = loaders_package_path / (loader_name.rstrip("s") + "s") + loader_dir = None + if loader_name in ["sdb"]: + loader_dir = loaders_package_path / loader_name.rstrip("s") + else: + loader_dir = loaders_package_path / (loader_name.rstrip("s") + "s") loader_dir.mkdir(0o755) loader_dir_init = loader_dir / "__init__.py" if not loader_dir_init.exists(): @@ -259,6 +264,8 @@ def main( loader_template = MODULE_LOADER_TEMPLATE elif loader_name == "states": loader_template = STATE_LOADER_TEMPLATE + elif loader_name == "sdb": + loader_template = SDB_LOADER_TEMPLATE else: loader_template = LOADER_TEMPLATE loader_module_contents = Template(loader_template).render(**templating_context) diff --git a/src/saltext/cli/templates.py b/src/saltext/cli/templates.py index 6cfee6d..8427b4c 100644 --- a/src/saltext/cli/templates.py +++ b/src/saltext/cli/templates.py @@ -134,6 +134,41 @@ def exampled(name): return ret ''' +SDB_LOADER_TEMPLATE = '''\ +{%- set loader_name = loader.rstrip("s") %} +""" +Salt {{ loader_name }} SDB module +""" +import logging + +log = logging.getLogger(__name__) + +__virtualname__ = "{{ package_name }}" + + +def __virtual__(): + # To force a module not to load return something like: + # return (False, "The {{ project_name }} {{ loader_name }} module is not implemented yet") + + # Replace this with your own logic + if "{{package_name}}.example_function" not in __salt__: + return False, "The '{{package_name}}' execution module is not available" + return __virtualname__ + + +def get(key, profile=None): + """ + This example function should be replaced + + CLI Example: + + .. code-block:: bash + + salt '*' sdb.get "sdb://{{ package_name}}/foo" + """ + return key +''' + LOADER_MODULE_UNIT_TEST_TEMPLATE = """\ import pytest import salt.modules.test as testmod From 83f3b2f0832c6e695e51a0142f7caaa6eafcafb0 Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Mon, 14 Nov 2022 00:30:48 -0500 Subject: [PATCH 3/9] Fix template title --- src/saltext/cli/templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/saltext/cli/templates.py b/src/saltext/cli/templates.py index 8427b4c..8af7605 100644 --- a/src/saltext/cli/templates.py +++ b/src/saltext/cli/templates.py @@ -137,7 +137,7 @@ def exampled(name): SDB_LOADER_TEMPLATE = '''\ {%- set loader_name = loader.rstrip("s") %} """ -Salt {{ loader_name }} SDB module +Salt {{ loader_name }} module """ import logging From ca9c2a1b5a643b6438602edabb9ab32d83bd4d4f Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Mon, 14 Nov 2022 01:09:47 -0500 Subject: [PATCH 4/9] Revert "copy jinja and sphinx dependancies from Salt repo. Don't run lint against noxfile.py." This reverts commit 38957bf97f10b0a4efad2b2889966fe539c59a2a. --- src/saltext/cli/project/.pylintrc | 2 +- src/saltext/cli/project/setup.cfg.j2 | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/saltext/cli/project/.pylintrc b/src/saltext/cli/project/.pylintrc index 15612f9..9ead2f3 100644 --- a/src/saltext/cli/project/.pylintrc +++ b/src/saltext/cli/project/.pylintrc @@ -12,7 +12,7 @@ profile=no # Add files or directories to the blacklist. They should be base names, not # paths. -ignore=CVS,_version.py,noxfile.py +ignore=CVS,_version.py # Pickle collected data for later comparisons. persistent=yes diff --git a/src/saltext/cli/project/setup.cfg.j2 b/src/saltext/cli/project/setup.cfg.j2 index c40ba6a..d74704f 100644 --- a/src/saltext/cli/project/setup.cfg.j2 +++ b/src/saltext/cli/project/setup.cfg.j2 @@ -72,15 +72,13 @@ salt.loader= tests = pytest==6.2.4 pytest-salt-factories==0.911.0 - jinja2<3.1 dev = nox pre-commit==2.13.0 pylint SaltPyLint docs = - sphinx>=3.5.1 - jinja2<3.1 + sphinx furo sphinx-copybutton sphinx-prompt From 712ee78f5e52a0c3a95a0d10ca2cc47949a15d6a Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Mon, 14 Nov 2022 01:28:02 -0500 Subject: [PATCH 5/9] Fix tests path for sdb --- src/saltext/cli/__main__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/saltext/cli/__main__.py b/src/saltext/cli/__main__.py index 8ee31ea..6aec835 100644 --- a/src/saltext/cli/__main__.py +++ b/src/saltext/cli/__main__.py @@ -274,7 +274,11 @@ def main( loader_dir_module = loader_dir_module.with_suffix(".new") loader_dir_module.write_text(loader_module_contents.rstrip() + "\n") - loader_unit_tests_dir = loaders_unit_tests_path / (loader_name.rstrip("s") + "s") + loader_unit_tests_dir = None + if loader_name in ["sdb"]: + loader_unit_tests_dir = loaders_unit_tests_path / loader_name.rstrip("s") + else: + loader_unit_tests_dir = loaders_unit_tests_path / (loader_name.rstrip("s") + "s") loader_unit_tests_dir.mkdir(0o755, exist_ok=True) loader_unit_tests_dir_init = loader_unit_tests_dir / "__init__.py" if not loader_unit_tests_dir_init.exists(): @@ -291,9 +295,13 @@ def main( loader_unit_test_module = loader_unit_test_module.with_suffix(".new") loader_unit_test_module.write_text(loader_unit_test_contents.rstrip() + "\n") - loader_integration_tests_dir = loaders_integration_tests_path / ( - loader_name.rstrip("s") + "s" - ) + loader_integration_tests_dir = None + if loader_name in ["sdb"]: + loader_integration_tests_dir = loaders_integration_tests_path / loader_name.rstrip("s") + else: + loader_integration_tests_dir = loaders_integration_tests_path / ( + loader_name.rstrip("s") + "s" + ) loader_integration_tests_dir.mkdir(0o755, exist_ok=True) loader_integration_tests_dir_init = loader_integration_tests_dir / "__init__.py" if not loader_integration_tests_dir_init.exists(): From a0cffa364a3f00b791d2e36aaa0efccd1912d6e4 Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Mon, 14 Nov 2022 02:02:14 -0500 Subject: [PATCH 6/9] Fix unit test imports for sdb --- src/saltext/cli/__main__.py | 3 +++ src/saltext/cli/templates.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/saltext/cli/__main__.py b/src/saltext/cli/__main__.py index 6aec835..51277a7 100644 --- a/src/saltext/cli/__main__.py +++ b/src/saltext/cli/__main__.py @@ -16,6 +16,7 @@ from saltext.cli.templates import LOADER_MODULE_INTEGRATION_TEST_TEMPLATE from saltext.cli.templates import LOADER_MODULE_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADER_STATE_UNIT_TEST_TEMPLATE +from saltext.cli.templates import LOADER_SDB_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADER_TEMPLATE from saltext.cli.templates import LOADER_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADERS_TEMPLATE @@ -287,6 +288,8 @@ def main( loader_test_template = LOADER_MODULE_UNIT_TEST_TEMPLATE elif loader_name == "states": loader_test_template = LOADER_STATE_UNIT_TEST_TEMPLATE + elif loader_name == "sdb": + loader_test_template = LOADER_SDB_UNIT_TEST_TEMPLATE else: loader_test_template = LOADER_UNIT_TEST_TEMPLATE loader_unit_test_contents = Template(loader_test_template).render(**templating_context) diff --git a/src/saltext/cli/templates.py b/src/saltext/cli/templates.py index 8af7605..3d7adb5 100644 --- a/src/saltext/cli/templates.py +++ b/src/saltext/cli/templates.py @@ -224,6 +224,27 @@ def test_replace_this_this_with_something_meaningful(): assert {{ package_name }}_state.exampled(echo_str) == expected """ +LOADER_SDB_TEST_TEMPLATE = """\ +{%- set loader_name = loader.rstrip("s") %} +import pytest +import {{ package_namespace_pkg }}{{ package_name }}.{{ loader.rstrip("s") }}.{{ package_name }}_mod as {{ package_name }}_{{ loader_name }} + + +@pytest.fixture +def configure_loader_modules(): + module_globals = { + "__salt__": {"this_does_not_exist.please_replace_it": lambda: True}, + } + return { + {{ package_name }}_{{ loader_name }}: module_globals, + } + + +def test_replace_this_this_with_something_meaningful(): + assert "this_does_not_exist.please_replace_it" in {{ package_name }}_{{ loader_name }}.__salt__ + assert {{ package_name }}_{{ loader_name }}.__salt__["this_does_not_exist.please_replace_it"]() is True +""" + LOADER_UNIT_TEST_TEMPLATE = """\ {%- set loader_name = loader.rstrip("s") %} import pytest From 02e86acc69780745dba9d85304ef84076fad746c Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Mon, 14 Nov 2022 02:04:29 -0500 Subject: [PATCH 7/9] Fix typo in template name --- src/saltext/cli/templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/saltext/cli/templates.py b/src/saltext/cli/templates.py index 3d7adb5..f4688fc 100644 --- a/src/saltext/cli/templates.py +++ b/src/saltext/cli/templates.py @@ -224,7 +224,7 @@ def test_replace_this_this_with_something_meaningful(): assert {{ package_name }}_state.exampled(echo_str) == expected """ -LOADER_SDB_TEST_TEMPLATE = """\ +LOADER_SDB_UNIT_TEST_TEMPLATE = """\ {%- set loader_name = loader.rstrip("s") %} import pytest import {{ package_namespace_pkg }}{{ package_name }}.{{ loader.rstrip("s") }}.{{ package_name }}_mod as {{ package_name }}_{{ loader_name }} From 49ddd9543e3fa2b9cf5113b51d87d54b483c63cc Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Mon, 14 Nov 2022 23:28:53 -0500 Subject: [PATCH 8/9] pre-commit fixes --- src/saltext/cli/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/saltext/cli/__main__.py b/src/saltext/cli/__main__.py index 51277a7..c0a6486 100644 --- a/src/saltext/cli/__main__.py +++ b/src/saltext/cli/__main__.py @@ -15,15 +15,15 @@ from saltext.cli import PACKAGE_ROOT from saltext.cli.templates import LOADER_MODULE_INTEGRATION_TEST_TEMPLATE from saltext.cli.templates import LOADER_MODULE_UNIT_TEST_TEMPLATE -from saltext.cli.templates import LOADER_STATE_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADER_SDB_UNIT_TEST_TEMPLATE +from saltext.cli.templates import LOADER_STATE_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADER_TEMPLATE from saltext.cli.templates import LOADER_UNIT_TEST_TEMPLATE from saltext.cli.templates import LOADERS_TEMPLATE from saltext.cli.templates import MODULE_LOADER_TEMPLATE from saltext.cli.templates import PACKAGE_INIT -from saltext.cli.templates import STATE_LOADER_TEMPLATE from saltext.cli.templates import SDB_LOADER_TEMPLATE +from saltext.cli.templates import STATE_LOADER_TEMPLATE LICENSES: Dict[str, str] = { "apache": "License :: OSI Approved :: Apache Software License", From 0393b2ce8b9a9779c84fbf6f7a38daa04d7e86f1 Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Fri, 18 Nov 2022 07:42:42 -0500 Subject: [PATCH 9/9] Merge upstream/main --- .pre-commit-config.yaml | 0 requirements/py3.10/tests.txt | 0 requirements/py3.6/tests.txt | 0 requirements/py3.7/tests.txt | 0 requirements/py3.8/tests.txt | 0 requirements/py3.9/tests.txt | 0 src/saltext/cli/__main__.py | 0 src/saltext/cli/project/.pre-commit-config.yaml.j2 | 0 src/saltext/cli/project/.pylintrc | 0 src/saltext/cli/project/docs/conf.py.j2 | 0 src/saltext/cli/project/noxfile.py.j2 | 0 src/saltext/cli/project/setup.cfg.j2 | 0 src/saltext/cli/templates.py | 0 13 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .pre-commit-config.yaml mode change 100644 => 100755 requirements/py3.10/tests.txt mode change 100644 => 100755 requirements/py3.6/tests.txt mode change 100644 => 100755 requirements/py3.7/tests.txt mode change 100644 => 100755 requirements/py3.8/tests.txt mode change 100644 => 100755 requirements/py3.9/tests.txt mode change 100644 => 100755 src/saltext/cli/__main__.py mode change 100644 => 100755 src/saltext/cli/project/.pre-commit-config.yaml.j2 mode change 100644 => 100755 src/saltext/cli/project/.pylintrc mode change 100644 => 100755 src/saltext/cli/project/docs/conf.py.j2 mode change 100644 => 100755 src/saltext/cli/project/noxfile.py.j2 mode change 100644 => 100755 src/saltext/cli/project/setup.cfg.j2 mode change 100644 => 100755 src/saltext/cli/templates.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml old mode 100644 new mode 100755 diff --git a/requirements/py3.10/tests.txt b/requirements/py3.10/tests.txt old mode 100644 new mode 100755 diff --git a/requirements/py3.6/tests.txt b/requirements/py3.6/tests.txt old mode 100644 new mode 100755 diff --git a/requirements/py3.7/tests.txt b/requirements/py3.7/tests.txt old mode 100644 new mode 100755 diff --git a/requirements/py3.8/tests.txt b/requirements/py3.8/tests.txt old mode 100644 new mode 100755 diff --git a/requirements/py3.9/tests.txt b/requirements/py3.9/tests.txt old mode 100644 new mode 100755 diff --git a/src/saltext/cli/__main__.py b/src/saltext/cli/__main__.py old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/.pre-commit-config.yaml.j2 b/src/saltext/cli/project/.pre-commit-config.yaml.j2 old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/.pylintrc b/src/saltext/cli/project/.pylintrc old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/docs/conf.py.j2 b/src/saltext/cli/project/docs/conf.py.j2 old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/noxfile.py.j2 b/src/saltext/cli/project/noxfile.py.j2 old mode 100644 new mode 100755 diff --git a/src/saltext/cli/project/setup.cfg.j2 b/src/saltext/cli/project/setup.cfg.j2 old mode 100644 new mode 100755 diff --git a/src/saltext/cli/templates.py b/src/saltext/cli/templates.py old mode 100644 new mode 100755