Best Python code snippet using avocado_python
SConstruct
Source:SConstruct  
1#2# SConstruct file to build scons packages during development.3#4# See the README.rst file for an overview of how SCons is built and tested.5copyright_years = '2001 - 2019'6# This gets inserted into the man pages to reflect the month of release.7month_year = 'December 2019'8#9# __COPYRIGHT__10#11# Permission is hereby granted, free of charge, to any person obtaining12# a copy of this software and associated documentation files (the13# "Software"), to deal in the Software without restriction, including14# without limitation the rights to use, copy, modify, merge, publish,15# distribute, sublicense, and/or sell copies of the Software, and to16# permit persons to whom the Software is furnished to do so, subject to17# the following conditions:18#19# The above copyright notice and this permission notice shall be included20# in all copies or substantial portions of the Software.21#22# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY23# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE24# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND25# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE26# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION27# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION28# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.29#30import os.path31import sys32import textwrap33project = 'scons'34default_version = '3.9.9'35copyright = "Copyright (c) %s The SCons Foundation" % copyright_years36#37# We let the presence or absence of various utilities determine whether38# or not we bother to build certain pieces of things.  This should allow39# people to still do SCons packaging work even if they don't have all40# of the utilities installed41#42print("git    :%s"%git)43print("gzip   :%s"%gzip)44print("unzip  :%s"%unzip)45print("zip    :%s"%zip_path)46#47# Adding some paths to sys.path, this is mainly needed48# for the doc toolchain.49#50addpaths = [os.path.abspath(os.path.join(os.getcwd(), 'bin')),51            os.path.abspath(os.path.join(os.getcwd(), 'testing/framework'))]52for a in addpaths:53    if a not in sys.path:54        sys.path.append(a)55# Use site_scons logic to process command line arguments56command_line = BuildCommandLine(default_version)57command_line.process_command_line_vars()58Default('.', command_line.build_dir)59# Just make copies, don't symlink them.60SetOption('duplicate', 'copy')61packaging_flavors = [62    ('tar-gz', "The normal .tar.gz file for end-user installation."),63    ('local-tar-gz', "A .tar.gz file for dropping into other software " +64     "for local use."),65    ('zip', "The normal .zip file for end-user installation."),66    ('local-zip', "A .zip file for dropping into other software " +67     "for local use."),68    ('src-tar-gz', "A .tar.gz file containing all the source " +69     "(including tests and documentation)."),70    ('src-zip', "A .zip file containing all the source " +71     "(including tests and documentation)."),72]73test_tar_gz_dir = os.path.join(command_line.build_dir, "test-tar-gz")74test_src_tar_gz_dir = os.path.join(command_line.build_dir, "test-src-tar-gz")75test_local_tar_gz_dir = os.path.join(command_line.build_dir, "test-local-tar-gz")76test_zip_dir = os.path.join(command_line.build_dir, "test-zip")77test_src_zip_dir = os.path.join(command_line.build_dir, "test-src-zip")78test_local_zip_dir = os.path.join(command_line.build_dir, "test-local-zip")79unpack_tar_gz_dir = os.path.join(command_line.build_dir, "unpack-tar-gz")80unpack_zip_dir = os.path.join(command_line.build_dir, "unpack-zip")81if is_windows():82    tar_hflag = ''83    python_project_subinst_dir = os.path.join("Lib", "site-packages", project)84    project_script_subinst_dir = 'Scripts'85else:86    tar_hflag = 'h'87    python_project_subinst_dir = os.path.join("lib", project)88    project_script_subinst_dir = 'bin'89indent_fmt = '  %-26s  '90Help("""\91The following aliases build packages of various types, and unpack the92contents into build/test-$PACKAGE subdirectories, which can be used by the93runtest.py -p option to run tests against what's been actually packaged:94""")95aliases = sorted(packaging_flavors + [('doc', 'The SCons documentation.')])96for alias, help_text in aliases:97    tw = textwrap.TextWrapper(98        width=78,99        initial_indent=indent_fmt % alias,100        subsequent_indent=indent_fmt % '' + '  ',101    )102    Help(tw.fill(help_text) + '\n')103Help("""104The following command-line variables can be set:105""")106for variable, help_text in command_line.command_line_variables:107    tw = textwrap.TextWrapper(108        width=78,109        initial_indent=indent_fmt % variable,110        subsequent_indent=indent_fmt % '' + '  ',111    )112    Help(tw.fill(help_text) + '\n')113revaction = SCons_revision114revbuilder = Builder(action=Action(SCons_revision,115                                   varlist=['COPYRIGHT', 'VERSION']))116env = Environment(117    ENV=command_line.ENV,118    BUILD=command_line.build_id,119    BUILDDIR=command_line.build_dir,120    BUILDSYS=command_line.build_system,121    COPYRIGHT=copyright,122    DATE=command_line.date,123    DEB_DATE=deb_date,124    DEVELOPER=command_line.developer,125    DISTDIR=os.path.join(command_line.build_dir, 'dist'),126    MONTH_YEAR=month_year,127    REVISION=command_line.revision,128    VERSION=command_line.version,129    TAR_HFLAG=tar_hflag,130    ZIP=zip_path,131    ZIPFLAGS='-r',132    UNZIP=unzip,133    UNZIPFLAGS='-o -d $UNPACK_ZIP_DIR',134    ZCAT=zcat,135    TEST_SRC_TAR_GZ_DIR=test_src_tar_gz_dir,136    TEST_SRC_ZIP_DIR=test_src_zip_dir,137    TEST_TAR_GZ_DIR=test_tar_gz_dir,138    TEST_ZIP_DIR=test_zip_dir,139    UNPACK_TAR_GZ_DIR=unpack_tar_gz_dir,140    UNPACK_ZIP_DIR=unpack_zip_dir,141    BUILDERS={'SCons_revision': revbuilder,142              'SOElim': soelimbuilder},143    PYTHON='"%s"' % sys.executable,144    PYTHONFLAGS='-tt',145)146Version_values = [Value(command_line.version), Value(command_line.build_id)]147#148#149#150#151# Documentation.152#153Export('command_line', 'env', 'whereis', 'revaction')...load_data.py
Source:load_data.py  
1import os2import zipfile3from torch.utils.data import DataLoader, random_split4from dataset import ACIDataset5from parameters import (6    TRAIN_DIR, 7    TRAIN_ZIP_DIR, 8    TEST_DIR, 9    TEST_ZIP_DIR, 10    ANNOTATIONS_DIR, 11    TRANSFORM, 12    VALIDATION_PERC, 13    AUC_PERC, 14    BATCH_SIZE15)16if not os.path.exists(TRAIN_DIR):17    with zipfile.ZipFile(TRAIN_ZIP_DIR, 'r') as zip_ref:18        zip_ref.extractall('./')19if not os.path.exists(TEST_DIR):20    with zipfile.ZipFile(TEST_ZIP_DIR, 'r') as zip_ref:21        zip_ref.extractall('./')22data = ACIDataset(23    img_dir=TRAIN_DIR,24    annotations_file=ANNOTATIONS_DIR,25    transform=TRANSFORM,26    target_transform=None)27test_data = ACIDataset(28    img_dir=TEST_DIR,29    transform=TRANSFORM)30validation_size = int(len(data) * VALIDATION_PERC * 10 // 10)31auc_size = int(len(data) * AUC_PERC * 10 // 10)32train_data, val_data, auc_data = random_split(data, [len(data) - validation_size - auc_size,33                                                     validation_size,34                                                     auc_size])35train_dl = DataLoader(train_data, batch_size=BATCH_SIZE)36valid_dl = DataLoader(val_data, batch_size=BATCH_SIZE)37all_dl   = DataLoader(data, batch_size=BATCH_SIZE)38auc_dl   = DataLoader(auc_data, batch_size=1)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
