Skip to content

Commit

Permalink
example of a "static env" entry
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
ens-lg4 committed Jul 24, 2018
1 parent 0018575 commit 901f727
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cm/alias-a-env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9b9b3208ac44b891
1 change: 1 addition & 0 deletions .cm/alias-u-9b9b3208ac44b891
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env
1 change: 1 addition & 0 deletions env/.cm/alias-a-python_simport
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5d14fc2889a207e6
1 change: 1 addition & 0 deletions env/.cm/alias-u-5d14fc2889a207e6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_simport
1 change: 1 addition & 0 deletions env/python_simport/.cm/desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
16 changes: 16 additions & 0 deletions env/python_simport/.cm/info.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions env/python_simport/.cm/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tags": [
"simport",
"lib"
]
}
18 changes: 18 additions & 0 deletions env/python_simport/env.bat
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions env/python_simport/env.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions env/python_simport/importme.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 901f727

Please sign in to comment.