Why can't Poetry load my environment variables? - python-venv

I'm trying to get Poetry to load env vars from a file when the .venv is activated. I can't use the plugin to load a .env because I'm not allowed to use Poetry 1.2.
I've got my env vars in a file called creds.sh.
I've edited both my .venv\Scripts\activate and .venv\Scripts\activate.bat to source from that file:
set -a
. creds.sh
set +a
and,
for /f "delims== tokens=1,2" %%G in (%~dp0..\..\creds.sh) do set %%G=%%H
respectively.
When I open up a new bash, and \activate, it works. I can env | grep <my var> and find my vars.
When I open up a new cmd, and \activate.bat, it works. I can again env | grep <my var> and find my vars.
When I poetry shell or poetry run my-script, it can't find my vars! What the heck is going on.
One thought is somehow poetry's opening up some other kind of shell, so I've tried to look for the $SHELL var inside my .venv but it doesn't seem to exist.
Any ideas? How else might I inject env vars into the Poetry env when the env is activated?

Related

Is it possible to have mamba aggregate a list of yaml files during the create command?

I have a process where envs are created and then multiple env files are used to update the env via mamba env update .
The problem is that I'm running commands in parallel and the lockfile doesn't appear to work with mamba env update only for mamba env create . https://github.com/mamba-org/mamba/issues/1582
Without me having to merge all the env files myself is there a way to do something like this:
mamba create --yes --quiet --name=myenv python=3.6 --file=deps1.yml --file=deps2.yml --file=deps2.yml

Apache Airflow command not found with SSHOperator

I am trying to use the SSHOperator to SSH into a remote machine and run an external application through the command line. I have setup the SSH connection via the admin page.
This section of code is used to define the commands and the SSH connection to the external machine.
sshHook = SSHHook(ssh_conn_id='remote_comp')
command_1 ="""
cd /files/232-065/Rans
bash run.sh
"""
Where 'run.sh' runs the shell script:
#!/bin/sh
starccm+ -batch run_export.java Rans_Model.sim
Which simply runs the commercial software starccm+ with some options I have specified.
This section defines the task:
inlet_profile = SSHOperator(
task_id='inlet_profile',
ssh_hook=sshHook,
command=command_1
)
I have confirmed the SSH connection works by giving a simple 'ls' command and checking the output.
The error that I get is:
bash run.sh, error: run.sh: line 2: starccm+: command not found
The command in 'run.sh' works when I am logged into the machine (it does not require a GUI). This makes me think that there is a problem with the SSH session and it is not the same as the one that Apache Airflow logs into, but I am not sure how to solve this problem.
Does anyone have any experience with this?
There is no issue with SSH connection (at least from the error message). However, the issue is with starccm+ installation path.
Please check the installation path of starccm+ .
Check if the installation path is part of $PATH env variable
$ echo $PATH
If not, then install it in the standard locations like /bin or /usr/bin etc (provided they are included in $PATH variable), or export the installed director into PATH variable like this,
$ export PATH=$PATH:/<absolute_path>
It is not ideal but if you struggle with setting the path variable you can run starccm stating the full path like:
/directory/where/star/is/installed/starccm+ -batch run_export.java Rans_Model.sim

Access environment variable in a korn shell script

my dev/qa/uat/prod servers each have an environmental variable "DATADIR".
For example in a dev linux server:
echo $DATADIR
devl
Can I access that environment variable inside
a korn shell script?
I figured it out after reading more about variables.
System variables are available inside the script.
echo $SOMEPATH
/usr/bin/
path=$SOMEPATH
echo The path you want is $path
The path you want is /usr/bin

One liner ssh different enviroment variables than normal ssh

I am using AWS Beanstalk, in case it may be relevant to the question.
The issue that I have is that when I do from my local terminal:
ssh mozart-api printenv
I missing most of the enviroment variables, instead if I do:
ssh mozart-api
..wait to open..
printenv
I get all enviroment varibles as I was expecting.
At first I thought it could be an ssh configuration in server but can't find anything strange.
if I do:
ssh mozart-api "export hello=123 && echo $hello"
then it outputs 123, which means that variables can be set and queried, however I just cannot get the existing variables from the server.
This is causing an issue because I am preparing a script that will run a command in ssh on this server, but because the variables are not loaded the project fails to open the database.
I tried reimporting them in one liner:
ssh mozart-api "sudo chmod +777 /etc/profile.d/sh.local && (/opt/elasticbeanstalk/bin/get-config environment | jq -r 'keys[] as \$k | \"echo export \(\$k)=\(.[\$k])\"') > /etc/profile.d/sh.local && printenv"
But still can't see the new added variables.
ssh mozart-api executes a login shell, which probably sources one or more files that define your environment variables.
ssh mozart-api printenv executes printenv instead of a login shell, so the only variables you see are the ones you inherit from the parent process, not any of the variables defined in your shell configuration files.

Openshift rhc ssh IO error after env set JAVA_OPTS_EXTcommand

I've run into an issue with openshift - after setting the environment variable over rhc env set JAVA_OPTS_EXT=" -D spring.profile.active=production" my ssh access broke down giving me weird access rights error. Some ideas here?
I don't know for what reason after setting a different value onto the JAVA_OPTS_EXT it locked me out of permissions. It was sufficient to unset the variable and set it again to a desired value. Everything started to work smoothly again afterwards.
A command to unset the environment variable: "rhc env unset {VARIABLE1} -a {APP_NAME}"
A command to set the environment variable: "rhc env set {VARIABLE1}={VALUE1} -a {APP_NAME}"
For further info about the manipulation of environmnet variables refer to https://developers.openshift.com/managing-your-applications/environment-variables.html