From 901f727f07c5580eafec5e87fd5ce4b690e4734f Mon Sep 17 00:00:00 2001 From: Leo Gordon Date: Tue, 24 Jul 2018 17:21:33 +0100 Subject: [PATCH] example of a "static env" entry Usage examples: * calling by the name: ck virtual env:python_simport --shell_cmd="python -m importme" * calling using tags: ck virtual env --tags=simport,lib --shell_cmd="python -m importme" --- .cm/alias-a-env | 1 + .cm/alias-u-9b9b3208ac44b891 | 1 + env/.cm/alias-a-python_simport | 1 + env/.cm/alias-u-5d14fc2889a207e6 | 1 + env/python_simport/.cm/desc.json | 1 + env/python_simport/.cm/info.json | 16 ++++++++++++++++ env/python_simport/.cm/meta.json | 6 ++++++ env/python_simport/env.bat | 18 ++++++++++++++++++ env/python_simport/env.sh | 15 +++++++++++++++ env/python_simport/importme.py | 11 +++++++++++ 10 files changed, 71 insertions(+) create mode 100644 .cm/alias-a-env create mode 100644 .cm/alias-u-9b9b3208ac44b891 create mode 100644 env/.cm/alias-a-python_simport create mode 100644 env/.cm/alias-u-5d14fc2889a207e6 create mode 100644 env/python_simport/.cm/desc.json create mode 100644 env/python_simport/.cm/info.json create mode 100644 env/python_simport/.cm/meta.json create mode 100644 env/python_simport/env.bat create mode 100644 env/python_simport/env.sh create mode 100755 env/python_simport/importme.py diff --git a/.cm/alias-a-env b/.cm/alias-a-env new file mode 100644 index 00000000..21d8915b --- /dev/null +++ b/.cm/alias-a-env @@ -0,0 +1 @@ +9b9b3208ac44b891 diff --git a/.cm/alias-u-9b9b3208ac44b891 b/.cm/alias-u-9b9b3208ac44b891 new file mode 100644 index 00000000..0a764a4d --- /dev/null +++ b/.cm/alias-u-9b9b3208ac44b891 @@ -0,0 +1 @@ +env diff --git a/env/.cm/alias-a-python_simport b/env/.cm/alias-a-python_simport new file mode 100644 index 00000000..91454c79 --- /dev/null +++ b/env/.cm/alias-a-python_simport @@ -0,0 +1 @@ +5d14fc2889a207e6 diff --git a/env/.cm/alias-u-5d14fc2889a207e6 b/env/.cm/alias-u-5d14fc2889a207e6 new file mode 100644 index 00000000..0fdb415e --- /dev/null +++ b/env/.cm/alias-u-5d14fc2889a207e6 @@ -0,0 +1 @@ +python_simport diff --git a/env/python_simport/.cm/desc.json b/env/python_simport/.cm/desc.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/env/python_simport/.cm/desc.json @@ -0,0 +1 @@ +{} diff --git a/env/python_simport/.cm/info.json b/env/python_simport/.cm/info.json new file mode 100644 index 00000000..37e8ba6b --- /dev/null +++ b/env/python_simport/.cm/info.json @@ -0,0 +1,16 @@ +{ + "backup_data_uid": "5d14fc2889a207e6", + "backup_module_uid": "9b9b3208ac44b891", + "backup_module_uoa": "env", + "control": { + "engine": "CK", + "iso_datetime": "2018-07-23T18:33:59.001180", + "version": [ + "1", + "9", + "4", + "4" + ] + }, + "data_name": "python_simport" +} diff --git a/env/python_simport/.cm/meta.json b/env/python_simport/.cm/meta.json new file mode 100644 index 00000000..7fc54e59 --- /dev/null +++ b/env/python_simport/.cm/meta.json @@ -0,0 +1,6 @@ +{ + "tags": [ + "simport", + "lib" + ] +} diff --git a/env/python_simport/env.bat b/env/python_simport/env.bat new file mode 100644 index 00000000..dafa9b64 --- /dev/null +++ b/env/python_simport/env.bat @@ -0,0 +1,18 @@ +@echo off + +if not [%1] == [1] (if defined CK_ENV_PYTHON_SIMPORT_SET exit /b 0) + +rem Finding the path to the directory that contains THIS batch script, +rem the solution borrowed from here: +rem https://stackoverflow.com/questions/8797983/can-a-windows-batch-file-determine-its-own-file-name +rem https://stackoverflow.com/questions/778135/how-do-i-get-the-equivalent-of-dirname-in-a-batch-file/778147 + +set PATH_TO_THIS_ENTRY_DIR=%~dp0 + +echo Adding %PATH_TO_THIS_ENTRY_DIR% to the PYTHONPATH ... + +set PYTHONPATH=%PATH_TO_THIS_ENTRY_DIR%;%PYTHONPATH% + +set CK_ENV_PYTHON_SIMPORT_SET=1 + +exit /b 0 diff --git a/env/python_simport/env.sh b/env/python_simport/env.sh new file mode 100644 index 00000000..94cc20fe --- /dev/null +++ b/env/python_simport/env.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ "$1" != "1" ]; then if [ "$CK_ENV_PYTHON_SIMPORT_SET" == "1" ]; then return; fi; fi + +# Finding the path to the directory that contains THIS bash script, +# the solution borrowed from here: +# https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself + +PATH_TO_THIS_ENTRY_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )" + +echo Adding $PATH_TO_THIS_ENTRY_DIR to the PYTHONPATH ... + +export PYTHONPATH=${PATH_TO_THIS_ENTRY_DIR}:${PYTHONPATH} + +export CK_ENV_PYTHON_SIMPORT_SET=1 diff --git a/env/python_simport/importme.py b/env/python_simport/importme.py new file mode 100755 index 00000000..122a2396 --- /dev/null +++ b/env/python_simport/importme.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +def runme(n = 100): + print( "runme({}): Hello, world!".format(n) ) + +if __name__ == '__main__': + + # When the entry's code is run as a script, perform local tests: + # + + runme(222)