How to use run_lambda method in localstack

Best Python code snippet using localstack_python

collect_env.py

Source:collect_env.py Github

copy

Full Screen

...43 err = err.decode(enc)44 return rc, output.strip(), err.strip()45def run_and_read_all(run_lambda, command):46 """Runs command using run_lambda; reads and returns entire output if rc is 0"""47 rc, out, _ = run_lambda(command)48 if rc != 0:49 return None50 return out51def run_and_parse_first_match(run_lambda, command, regex):52 """Runs command using run_lambda, returns the first regex match if it exists"""53 rc, out, _ = run_lambda(command)54 if rc != 0:55 return None56 match = re.search(regex, out)57 if match is None:58 return None59 return match.group(1)60def get_conda_packages(run_lambda):61 if get_platform() == 'win32':62 grep_cmd = r'findstr /R "torch soumith mkl magma"'63 else:64 grep_cmd = r'grep "torch\|soumith\|mkl\|magma"'65 conda = os.environ.get('CONDA_EXE', 'conda')66 out = run_and_read_all(run_lambda, conda + ' list | ' + grep_cmd)67 if out is None:68 return out69 # Comment starting at beginning of line70 comment_regex = re.compile(r'^#.*\n')71 return re.sub(comment_regex, '', out)72def get_gcc_version(run_lambda):73 return run_and_parse_first_match(run_lambda, 'gcc --version', r'gcc (.*)')74def get_cmake_version(run_lambda):75 return run_and_parse_first_match(run_lambda, 'cmake --version', r'cmake (.*)')76def get_nvidia_driver_version(run_lambda):77 if get_platform() == 'darwin':78 cmd = 'kextstat | grep -i cuda'79 return run_and_parse_first_match(run_lambda, cmd,80 r'com[.]nvidia[.]CUDA [(](.*?)[)]')81 smi = get_nvidia_smi()82 return run_and_parse_first_match(run_lambda, smi, r'Driver Version: (.*?) ')83def get_gpu_info(run_lambda):84 if get_platform() == 'darwin':85 if TORCH_AVAILABLE and torch.cuda.is_available():86 return torch.cuda.get_device_name(None)87 return None88 smi = get_nvidia_smi()89 uuid_regex = re.compile(r' \(UUID: .+?\)')90 rc, out, _ = run_lambda(smi + ' -L')91 if rc != 0:92 return None93 # Anonymize GPUs by removing their UUID94 return re.sub(uuid_regex, '', out)95def get_running_cuda_version(run_lambda):96 return run_and_parse_first_match(run_lambda, 'nvcc --version', r'V(.*)$')97def get_cudnn_version(run_lambda):98 """This will return a list of libcudnn.so; it's hard to tell which one is being used"""99 if get_platform() == 'win32':100 cudnn_cmd = 'where /R "%CUDA_PATH%\\bin" cudnn*.dll'101 elif get_platform() == 'darwin':102 # CUDA libraries and drivers can be found in /usr/local/cuda/. See103 # https://docs.nvidia.com/cuda/cuda-installation-guide-mac-os-x/index.html#install104 # https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installmac105 # Use CUDNN_LIBRARY when cudnn library is installed elsewhere.106 cudnn_cmd = 'ls /usr/local/cuda/lib/libcudnn*'107 else:108 cudnn_cmd = 'ldconfig -p | grep libcudnn | rev | cut -d" " -f1 | rev'109 rc, out, _ = run_lambda(cudnn_cmd)110 # find will return 1 if there are permission errors or if not found111 if len(out) == 0 or (rc != 1 and rc != 0):112 l = os.environ.get('CUDNN_LIBRARY')113 if l is not None and os.path.isfile(l):114 return os.path.realpath(l)115 return None116 files = set()117 for fn in out.split('\n'):118 fn = os.path.realpath(fn) # eliminate symbolic links119 if os.path.isfile(fn):120 files.add(fn)121 if not files:122 return None123 # Alphabetize the result because the order is non-deterministic otherwise...

Full Screen

Full Screen

collection_env.py

Source:collection_env.py Github

copy

Full Screen

...38 err = err.decode("ascii")39 return rc, output.strip(), err.strip()40def run_and_read_all(run_lambda, command):41 """Runs command using run_lambda; reads and returns entire output if rc is 0"""42 rc, out, _ = run_lambda(command)43 if rc is not 0:44 return None45 return out46def run_and_parse_first_match(run_lambda, command, regex):47 """Runs command using run_lambda, returns the first regex match if it exists"""48 rc, out, _ = run_lambda(command)49 if rc is not 0:50 return None51 match = re.search(regex, out)52 if match is None:53 return None54 return match.group(1)55def get_conda_packages(run_lambda):56 if get_platform() == 'win32':57 grep_cmd = 'findstr /R "torch soumith"'58 else:59 grep_cmd = 'grep "torch\|soumith"'60 out = run_and_read_all(run_lambda, 'conda list | ' + grep_cmd)61 if out is None:62 return out63 # Comment starting at beginning of line64 comment_regex = re.compile(r'^#.*\n')65 return re.sub(comment_regex, '', out)66def get_gcc_version(run_lambda):67 return run_and_parse_first_match(run_lambda, 'gcc --version', r'gcc (.*)')68def get_cmake_version(run_lambda):69 return run_and_parse_first_match(run_lambda, 'cmake --version', r'cmake (.*)')70def get_nvidia_driver_version(run_lambda):71 smi = get_nvidia_smi()72 return run_and_parse_first_match(run_lambda, smi, r'Driver Version: (.*?) ')73def get_gpu_info(run_lambda):74 smi = get_nvidia_smi()75 uuid_regex = re.compile(' \(UUID: .+?\)')76 rc, out, _ = run_lambda(smi + ' -L')77 if rc is not 0:78 return None79 # Anonymize GPUs by removing their UUID80 return re.sub(uuid_regex, '', out)81def get_running_cuda_version(run_lambda):82 return run_and_parse_first_match(run_lambda, 'nvcc --version', r'V(.*)$')83def get_cudnn_version(run_lambda):84 """This will return a list of libcudnn.so; it's hard to tell which one is being used"""85 if get_platform() == 'win32':86 cudnn_cmd = 'where /R "%CUDA_PATH%\\bin" cudnn*.dll'87 else:88 cudnn_cmd = 'find /usr/local /usr/lib -type f -name "libcudnn*" 2> /dev/null'89 rc, out, _ = run_lambda(cudnn_cmd)90 # find will return 1 if there are permission errors or if not found91 if len(out) == 0:92 return None93 if rc != 1 and rc != 0:94 return None95 # Alphabetize the result because the order is non-deterministic otherwise96 result = '\n'.join(sorted(out.split('\n')))97 return 'Probably one of the following:\n{}'.format(result)98def get_nvidia_smi():99 smi = 'nvidia-smi'100 if get_platform() == 'win32':101 smi = '"C:\\Program Files\\NVIDIA Corporation\\NVSMI\\%s"' % smi102 return smi103def get_platform():...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful