1
1
import argparse
2
2
import os
3
+ import subprocess
3
4
from datetime import date
4
5
5
- from ts_scripts .utils import try_and_handle
6
+ from ts_scripts .utils import try_and_handle , find_conda_binary
6
7
7
8
conda_build_dir = os .path .dirname (os .path .abspath (__file__ ))
8
9
REPO_ROOT = os .path .join (conda_build_dir , ".." , ".." )
9
10
MINICONDA_DOWNLOAD_URL = (
10
11
"https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh"
11
12
)
12
- CONDA_BINARY = (
13
- os .popen ("which conda" ).read ().strip ()
14
- if os .system (f"conda --version" ) == 0
15
- else f"$HOME/miniconda/condabin/conda"
16
- )
13
+ CONDA_BINARY = find_conda_binary ()
17
14
18
15
CONDA_PACKAGES_PATH = os .path .join (REPO_ROOT , "binaries" , "conda" , "output" )
19
16
CONDA_LINUX_PACKAGES_PATH = os .path .join (
32
29
33
30
if os .name == "nt" :
34
31
# Assumes miniconda is installed in windows
35
- CONDA_BINARY = "conda"
36
-
32
+ CONDA_BINARY = "conda"
37
33
38
34
def add_nightly_suffix_conda (binary_name : str ) -> str :
39
35
"""
@@ -52,29 +48,29 @@ def install_conda_build(dry_run):
52
48
"""
53
49
54
50
# Check if conda binary already exists
55
- exit_code = os .system (f"conda --version" )
56
- if exit_code == 0 :
57
- print (
58
- f"'conda' already present on the system. Proceeding without a fresh conda installation."
59
- )
51
+ try :
52
+ subprocess .run (["conda" , "--version" ], check = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
53
+ print ("'conda' already present on the system. Proceeding without a fresh conda installation." )
60
54
return
61
- try_and_handle (
62
- f"{ CONDA_BINARY } install python=3.8 conda-build anaconda-client -y" , dry_run
63
- )
55
+ except subprocess .CalledProcessError :
56
+ # Conda is not available, proceed with installation
57
+ try_and_handle (
58
+ f"{ CONDA_BINARY } install python=3.8 conda-build anaconda-client -y" , dry_run
59
+ )
64
60
65
61
66
62
def install_miniconda (dry_run ):
67
63
"""
68
64
Installs miniconda, a slimmer anaconda installation to build conda packages
69
65
"""
70
66
71
- # Check if conda binary already exists
72
- exit_code = os .system (f"conda --version" )
73
- if exit_code == 0 :
74
- print (
75
- f"'conda' already present on the system. Proceeding without a fresh minconda installation."
76
- )
67
+ try :
68
+ subprocess .run (["conda" , "--version" ], check = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
69
+ print ("'conda' already present on the system. Proceeding without a fresh conda installation." )
77
70
return
71
+ except subprocess .CalledProcessError as e :
72
+ raise (e )
73
+
78
74
if os .name == "nt" :
79
75
print (
80
76
"Identified as Windows system. Please install miniconda using this URL: https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe"
0 commit comments