Skip to main content

Run a subprocess in a different conda environment.

Project description

conda subprocess

Pipeline codecov

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 shell parameter and the env parameter are not supported in Popen() and all derived methods.
  • The pipesize parameter and the process_group parameter were removed for compatibility with python 3.9.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conda_subprocess-0.0.11.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

conda_subprocess-0.0.11-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file conda_subprocess-0.0.11.tar.gz.

File metadata

  • Download URL: conda_subprocess-0.0.11.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

Hashes for conda_subprocess-0.0.11.tar.gz
Algorithm Hash digest
SHA256 c474b041ea745ff52ab58c904a800b208db13c00a9139268ba70e60cd3aa925d
MD5 d52b46b9576e191e56b1c8ff49a6addd
BLAKE2b-256 12c1c3fb1978698e004d62b8b60022ce50137998596e5009d459f8c8d3d82148

See more details on using hashes here.

Provenance

The following attestation bundles were made for conda_subprocess-0.0.11.tar.gz:

Publisher: deploy.yml on pyiron/conda_subprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file conda_subprocess-0.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for conda_subprocess-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 f99479cb03d302a6b4476a3fd409e633a80dc5f7c02a782fc3a5d476f74d72f9
MD5 714af03b932b4059b1cfd7b1647ca694
BLAKE2b-256 da7cc9f2171804abb72d780796670d1d142f78c932d50d6ad94891d6775a1564

See more details on using hashes here.

Provenance

The following attestation bundles were made for conda_subprocess-0.0.11-py3-none-any.whl:

Publisher: deploy.yml on pyiron/conda_subprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page