Best Python code snippet using autotest_python
external_packages.py
Source:external_packages.py  
...153        if not egg_path:154            return False155        return self._install_from_egg(install_dir, egg_path)156    def _build_and_install_current_dir_noegg(self, install_dir):157        if not self._build_using_setup_py():158            return False159        return self._install_using_setup_py_and_rsync(install_dir)160    def _build_and_install_from_package(self, install_dir):161        """162        This method may be used as a _build_and_install() implementation163        for subclasses if they implement _build_and_install_current_dir().164        Extracts the .tar.gz file, chdirs into the extracted directory165        (which is assumed to match the tar filename) and calls166        _build_and_isntall_current_dir from there.167        Afterwards the build (regardless of failure) extracted .tar.gz168        directory is cleaned up.169        :return: True on success, False otherwise.170        :raise OSError If the expected extraction directory does not exist.171        """172        self._extract_compressed_package()173        if self.verified_package.endswith('.tar.gz'):174            extension = '.tar.gz'175        elif self.verified_package.endswith('.tar.bz2'):176            extension = '.tar.bz2'177        elif self.verified_package.endswith('.zip'):178            extension = '.zip'179        else:180            raise Error('Unexpected package file extension on %s' %181                        self.verified_package)182        os.chdir(os.path.dirname(self.verified_package))183        os.chdir(self.local_filename[:-len(extension)])184        extracted_dir = os.getcwd()185        try:186            return self._build_and_install_current_dir(install_dir)187        finally:188            os.chdir(os.path.join(extracted_dir, '..'))189            shutil.rmtree(extracted_dir)190    def _extract_compressed_package(self):191        """Extract the fetched compressed .tar or .zip within its directory."""192        if not self.verified_package:193            raise Error('Package must have been fetched first.')194        os.chdir(os.path.dirname(self.verified_package))195        if self.verified_package.endswith('gz'):196            status = system("tar -xzf '%s'" % self.verified_package)197        elif self.verified_package.endswith('bz2'):198            status = system("tar -xjf '%s'" % self.verified_package)199        elif self.verified_package.endswith('zip'):200            status = system("unzip '%s'" % self.verified_package)201        else:202            raise Error('Unknown compression suffix on %s.' %203                        self.verified_package)204        if status:205            raise Error('tar failed with %s' % (status,))206    def _build_using_setup_py(self, setup_py='setup.py'):207        """208        Assuming the cwd is the extracted python package, execute a simple209        python setup.py build.210        :param setup_py - The name of the setup.py file to execute.211        :return: True on success, False otherwise.212        """213        if not os.path.exists(setup_py):214            raise Error('%s does not exist in %s' % (setup_py, os.getcwd()))215        status = system("'%s' %s build" % (sys.executable, setup_py))216        if status:217            logging.error('%s build failed.' % self.name)218            return False219        return True220    def _build_egg_using_setup_py(self, setup_py='setup.py'):...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!!
