Skip to content

Commit

Permalink
Add commands for the python virtual environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
flenniken committed Feb 27, 2021
1 parent da94433 commit 62b27f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
3 changes: 2 additions & 1 deletion env/linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ RUN mkdir -p /home/steve/code/metar/ \
RUN export PATH=/home/steve/.nimble/bin:$PATH \
&& nimble install -y nimpy@#c8ec14a # metarVersion*

RUN echo "PS1='\u:\w\$ '" >> .bashrc

# Create metarenv virtual environment.
ENV VIRTUAL_ENV=/home/steve/code/metar/env/linux/metarenv
RUN python3 -m venv $VIRTUAL_ENV
Expand All @@ -54,4 +56,3 @@ RUN python3 -m venv $VIRTUAL_ENV \

WORKDIR /home/steve/code/metar/
CMD /bin/bash

39 changes: 32 additions & 7 deletions metar.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ proc build_metar_and_python_module(host = hostOS, name = "metar", libName = "met
ignoreOutput = false, release = true, strip = true, xcompile = false,
nimOptions = "", buildExe=true, buildLib=true) =

let hints = "--hint[Processing]:off --hint[CC]:off --hint[Link]:off "
let hints = "--hint[Processing]:off --hint[CC]:off --hint[Link]:off --hint[Conf]:off "

var ignore: string
if ignoreOutput:
Expand Down Expand Up @@ -101,25 +101,23 @@ proc build_metar_and_python_module(host = hostOS, name = "metar", libName = "met
echo "===> Building Python Lib $1 $2 for $3 <===" % [relDisplay, libName, host]
exec r"rm -f $1" % [output]

let cmd = "$5nim c $2--out:$1 $3-d:buildingLib --app:lib $6metar/metar $4" % [output, rel, nimOptions, ignore, docker, hints]
var cmd = "$5nim c $2--out:$1 $3-d:buildingLib --app:lib $6metar/metar $4" % [output, rel, nimOptions, ignore, docker, hints]
echo cmd
exec cmd

# Put the setup file next to the lib ready to install.
var dirName = getDirName(host)
let setupFilename = "bin/$1/setup.py" % [dirName]
# if not system.fileExists(setupFilename):
if true:
let cmd = r"cp python/setup.py $1" % [setupFilename]
echo cmd
exec cmd
cmd = r"cp python/setup.py $1" % [setupFilename]
echo cmd
exec cmd

exec r"find . -name \*.pyc -delete"

if strip:
exec r"strip -x $1" % [output]


proc createDependencyGraph() =
# Create my.dot file with the contents of metar.dot after stripping
# out nim modules.
Expand All @@ -128,6 +126,8 @@ proc createDependencyGraph() =
exec "python python/dotMetar.py names.txt metar/metar.dot >metar/my.dot"
exec "dot -Tsvg metar/my.dot -o docs/html//dependencies.svg"

task t, "Show the list of tasks.":
exec "nimble tasks"

task m, "Build metar exe and python module, release versions.":
build_metar_and_python_module()
Expand All @@ -144,6 +144,11 @@ task md, "Build debug version of metar.":
task mdlib, "Build debug version of the python module.":
build_metar_and_python_module(buildExe=false, release=false)

task pipinstall, "Install the release python metar module in the virtual env.":
# Install the version just built in the virtual environment.
var cmd = "pip3 install bin/linux"
echo cmd
exec cmd

proc get_test_module_cmd(filename: string, release = false): string =
## Return the command line to test one module.
Expand Down Expand Up @@ -468,3 +473,23 @@ task mxmac, "Compile for mac 64 bit using the xcompile docker image.":
task mxlinux, "Compile for linux 64 bit using the xcompile docker image.":

build_metar_and_python_module(host = "linux", name = "metar", libName = "metar.so", release = true, strip = true, nimOptions = "--os:linux --cpu:amd64 ", xcompile = true)

task pyactivate, "Activate the python virtual env. Create it when missing.":
var dirName = getDirName(hostOS)
let virtualEnv = "env/$1/metarenv" % dirName
if system.dirExists(virtualEnv):
if system.getEnv("VIRTUAL_ENV", "") == "":
var cmd = ". $1/bin/activate" % [virtualEnv]
echo "run:"
echo cmd
else:
echo "Creating virtual environment: $1" % [virtualEnv]
var cmd = "python3 -m venv $1" % [virtualEnv]
echo cmd
exec cmd
cmd = "source $1/bin/activate" % [virtualEnv]
echo cmd
exec cmd
cmd = "pip3 install wheel"
echo cmd
exec cmd

0 comments on commit 62b27f2

Please sign in to comment.