Run a subprocess in a different conda environment.
Project description
conda subprocess
Run a subprocess in a different conda environment.
Example
Create a new conda environment - in this example a conda environment for Python 3.12:
conda create -n py312 python=3.12
Subprocess Interface
Open a python shell in your base environment where conda_subprocess is installed and execute python --version in the
py312 environment:
from conda_subprocess import check_output
check_output("python --version", prefix_name="py312")
>>> b'Python 3.12.1\n'
Alternatively, the environment can be specified with the absolute path:
from conda_subprocess import check_output
check_output("python --version", prefix_path="/Users/janssen/mambaforge/envs/py312")
>>> b'Python 3.12.1\n'
As expected the process for the arguments for the subprocess call can also be defined as list:
from conda_subprocess import check_output
check_output(["python", "--version"], prefix_path="/Users/janssen/mambaforge/envs/py312")
>>> b'Python 3.12.1\n'
In addition to the check_output() function also the check_call() function is implemented:
from conda_subprocess import check_call
check_call("python --version", prefix_name="py312")
>>> Python 3.12.1
>>> 0
As well as the call() function:
from conda_subprocess import call
call("python --version", prefix_name="py312")
>>> Python 3.12.1
>>> 0
And the run() function:
from conda_subprocess import run
run("python --version", prefix_name="py312")
>>> Python 3.12.1
>>> CompletedProcess(args=['/bin/bash', '/var/folders/9p/rztyv06d0xv4h26cyv8nrw3m0000gq/T/tmpm8b8i0r3'], returncode=0)
As the CompletedProcess arguments illustrate conda_subprocess is internally writing the commands to a temporary file
for execution, to guarantee the conda environment is correctly activated.
For interactive communication conda_subprocess implements the Popen interface:
from subprocess import PIPE
from conda_subprocess import Popen
process = Popen(["python", "--version"], stdout=PIPE, prefix_name="py312")
process.communicate()
>>> (b'Python 3.12.1\n', None)
Decorator
In analogy to the subprocess interface the conda_subprocess also introduces the @conda decorator to
execute python functions in a separate conda environment:
from conda_subprocess.decorator import conda
@conda(prefix_name="py312")
def add_function(parameter_1, parameter_2):
return parameter_1 + parameter_2
add_function(parameter_1=1, parameter_2=2)
>>> 3
Remarks
- The
shellparameter and theenvparameter are not supported inPopen()and all derived methods. - The
pipesizeparameter and theprocess_groupparameter were removed for compatibility with python 3.9.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file conda_subprocess-0.0.10.tar.gz.
File metadata
- Download URL: conda_subprocess-0.0.10.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d0c9de1744a0020dab5131d8e07d7576b0c7bb40252ad6c237714f914467628
|
|
| MD5 |
a052f71aa1c1cb9a9696ff88d8af08e4
|
|
| BLAKE2b-256 |
08f771a48fedbd1e9322f9692654dc8fb82ef3af9ca317c55fd0f849f6b759b3
|
Provenance
The following attestation bundles were made for conda_subprocess-0.0.10.tar.gz:
Publisher:
deploy.yml on pyiron/conda_subprocess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
conda_subprocess-0.0.10.tar.gz -
Subject digest:
0d0c9de1744a0020dab5131d8e07d7576b0c7bb40252ad6c237714f914467628 - Sigstore transparency entry: 623316720
- Sigstore integration time:
-
Permalink:
pyiron/conda_subprocess@435910bba61d0d6d7cba57ab457e6317cf4c765f -
Branch / Tag:
refs/tags/conda_subprocess-0.0.10 - Owner: https://github.com/pyiron
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@435910bba61d0d6d7cba57ab457e6317cf4c765f -
Trigger Event:
push
-
Statement type:
File details
Details for the file conda_subprocess-0.0.10-py3-none-any.whl.
File metadata
- Download URL: conda_subprocess-0.0.10-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b13d2f03edbae17ccf4a0ca972cbed8768a4bed3e70bd0e724e2d8cc2fa62f3c
|
|
| MD5 |
c0ab8c44c988167576306cf4716e9eb1
|
|
| BLAKE2b-256 |
58a33eb97f8ace0b9d5d16931f888bd7a36e2bae3c5b2cc2ffca8b22dbf387be
|
Provenance
The following attestation bundles were made for conda_subprocess-0.0.10-py3-none-any.whl:
Publisher:
deploy.yml on pyiron/conda_subprocess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
conda_subprocess-0.0.10-py3-none-any.whl -
Subject digest:
b13d2f03edbae17ccf4a0ca972cbed8768a4bed3e70bd0e724e2d8cc2fa62f3c - Sigstore transparency entry: 623316727
- Sigstore integration time:
-
Permalink:
pyiron/conda_subprocess@435910bba61d0d6d7cba57ab457e6317cf4c765f -
Branch / Tag:
refs/tags/conda_subprocess-0.0.10 - Owner: https://github.com/pyiron
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@435910bba61d0d6d7cba57ab457e6317cf4c765f -
Trigger Event:
push
-
Statement type: