From 81f05e8304a32a57316595fe6d86121640315ced Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Sat, 15 Jun 2024 18:10:47 +0200 Subject: [PATCH 1/5] Update .gitattributes --- project-template/{{ project_repo_name }}/.gitattributes | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project-template/{{ project_repo_name }}/.gitattributes b/project-template/{{ project_repo_name }}/.gitattributes index 2537ef8..5fc52ef 100644 --- a/project-template/{{ project_repo_name }}/.gitattributes +++ b/project-template/{{ project_repo_name }}/.gitattributes @@ -1 +1,2 @@ -*.xsh text linguist-language=Python +*.xsh* text linguist-language=Python +*.py* text linguist-language=Python From 3fa64d0ebec8df37fc5186930e1589091402d270 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Sat, 15 Jun 2024 18:12:07 +0200 Subject: [PATCH 2/5] Rename {{project_package_name}}.{%if pure_py %}py{%else%}xsh{%endif%} to {{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} --- ...project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%}} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{{project_package_name}}.{%if pure_py %}py{%else%}xsh{%endif%} => {{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%}} (100%) diff --git a/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}.{%if pure_py %}py{%else%}xsh{%endif%} b/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} similarity index 100% rename from project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}.{%if pure_py %}py{%else%}xsh{%endif%} rename to project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} From c752abde6e9591ba681ce320d0c40f4cd913525f Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Sat, 15 Jun 2024 18:20:39 +0200 Subject: [PATCH 3/5] Update {{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} --- ...e_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} b/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} index 26480a9..39e0913 100644 --- a/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} +++ b/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} @@ -20,10 +20,14 @@ print('This is {{ project_repo_name }}!') # Note! If you want to create new env variables please name it with the beginning of the xontrib name # i.e. if the xontrib called xontrib-hello-world name the variables as XONTRIB_HELLO_WORLD_NEW_VARIABLE {% if pure_py %} -# Some code in Using Python API: -var = XSH.env.get("VAR", "default") -result = XSH.subproc_captured_stdout(['echo', '1']) +# If your xontrib was made only for interactive mode it's good practice to check this before executing. +if XSH.env.get("XONSH_INTERACTIVE", "default"): + # Some code in Using Python API: + var = XSH.env.get("VAR", "default") + result = XSH.subproc_captured_stdout(['echo', '1']) {% else %} -var = ${...}.get('VAR', 'default') -result = $(echo 1) +# If your xontrib was made only for interactive mode it's good practice to check this before executing. +if $XONSH_INTERACTIVE: + var = XSH.env.get('VAR', 'default') + result = $(echo 1) {% endif %} From b08bcc4fbb0d5a8cb94e5b4ce6ade6e6240f75b1 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Sat, 15 Jun 2024 18:22:18 +0200 Subject: [PATCH 4/5] Update {{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} --- ...roject_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} b/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} index 39e0913..133c71b 100644 --- a/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} +++ b/project-template/{{ project_repo_name }}/{% if not enable_autoloading %}xontrib{%endif%}/{{project_package_name}}{%if pure_py %}.py{%else%}.xsh{%endif%} @@ -21,7 +21,7 @@ print('This is {{ project_repo_name }}!') # i.e. if the xontrib called xontrib-hello-world name the variables as XONTRIB_HELLO_WORLD_NEW_VARIABLE {% if pure_py %} # If your xontrib was made only for interactive mode it's good practice to check this before executing. -if XSH.env.get("XONSH_INTERACTIVE", "default"): +if XSH.env.get("XONSH_INTERACTIVE"): # Some code in Using Python API: var = XSH.env.get("VAR", "default") result = XSH.subproc_captured_stdout(['echo', '1']) From 635893ad0e3475823f447d79d9d330f0bb82b9a9 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Sat, 15 Jun 2024 18:25:01 +0200 Subject: [PATCH 5/5] Update main.py --- .../main.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py b/project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py index a3b2ccb..c043567 100644 --- a/project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py +++ b/project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py @@ -2,16 +2,17 @@ def _load_xontrib_(xsh: XonshSession, **_): - # getting environment variable - var = xsh.env.get("VAR", "default") - print("Autoloading xontrib: {{ project_repo_name }}") + # If your xontrib was made only for interactive mode it's good practice to check this before executing. + if XSH.env.get("XONSH_INTERACTIVE"): + var = xsh.env.get("VAR", "default") + print("Autoloading xontrib: {{ project_repo_name }}") - {% if has_events %} - from .event_hooks import listen_cd - xsh.builtins.events.on_chdir(listen_cd) - {% endif %} - {% if has_aliases %} - from .aliases import git_log - xsh.aliases["gl"] = git_log - {% endif %} + {% if has_events %} + from .event_hooks import listen_cd + xsh.builtins.events.on_chdir(listen_cd) + {% endif %} + {% if has_aliases %} + from .aliases import git_log + xsh.aliases["gl"] = git_log + {% endif %}