How to use _install_using_setup_py_and_rsync method in autotest

Best Python code snippet using autotest_python

external_packages.py

Source:external_packages.py Github

copy

Full Screen

...155 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'):221 """222 Assuming the cwd is the extracted python package, execute a simple223 python setup.py bdist_egg.224 :param setup_py - The name of the setup.py file to execute.225 :return: The relative path to the resulting egg file or '' on failure.226 """227 if not os.path.exists(setup_py):228 raise Error('%s does not exist in %s' % (setup_py, os.getcwd()))229 egg_subdir = 'dist'230 if os.path.isdir(egg_subdir):231 shutil.rmtree(egg_subdir)232 status = system("'%s' %s bdist_egg" % (sys.executable, setup_py))233 if status:234 logging.error('bdist_egg of setuptools failed.')235 return ''236 # I've never seen a bdist_egg lay multiple .egg files.237 for filename in os.listdir(egg_subdir):238 if filename.endswith('.egg'):239 return os.path.join(egg_subdir, filename)240 def _install_from_egg(self, install_dir, egg_path):241 """242 Install a module from an egg file by unzipping the necessary parts243 into install_dir.244 :param install_dir - The installation directory.245 :param egg_path - The pathname of the egg file.246 """247 status = system("unzip -q -o -d '%s' '%s'" % (install_dir, egg_path))248 if status:249 logging.error('unzip of %s failed', egg_path)250 return False251 egg_info = os.path.join(install_dir, 'EGG-INFO')252 if os.path.isdir(egg_info):253 shutil.rmtree(egg_info)254 return True255 def _get_temp_dir(self):256 return tempfile.mkdtemp(dir='/​var/​tmp')257 def _site_packages_path(self, temp_dir):258 # This makes assumptions about what python setup.py install259 # does when given a prefix. Is this always correct?260 python_xy = 'python%s' % sys.version[:3]261 return os.path.join(temp_dir, 'lib', python_xy, 'site-packages')262 def _install_using_setup_py_and_rsync(self, install_dir,263 setup_py='setup.py',264 temp_dir=None):265 """266 Assuming the cwd is the extracted python package, execute a simple:267 python setup.py install --prefix=BLA268 BLA will be a temporary directory that everything installed will269 be picked out of and rsynced to the appropriate place under270 install_dir afterwards.271 Afterwards, it deconstructs the extra lib/​pythonX.Y/​site-packages/​272 directory tree that setuptools created and moves all installed273 site-packages directly up into install_dir itself.274 :param install_dir the directory for the install to happen under.275 :param setup_py - The name of the setup.py file to execute.276 :return: True on success, False otherwise....

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Assessing Risks in the Scrum Framework

Software Risk Management (SRM) combines a set of tools, processes, and methods for managing risks in the software development lifecycle. In SRM, we want to make informed decisions about what can go wrong at various levels within a company (e.g., business, project, and software related).

Running Tests In Cypress With GitHub Actions [Complete Guide]

In today’s tech world, where speed is the key to modern software development, we should aim to get quick feedback on the impact of any change, and that is where CI/CD comes in place.

Desired Capabilities in Selenium Webdriver

Desired Capabilities is a class used to declare a set of basic requirements such as combinations of browsers, operating systems, browser versions, etc. to perform automated cross browser testing of a web application.

Keeping Quality Transparency Throughout the organization

In general, software testers have a challenging job. Software testing is frequently the final significant activity undertaken prior to actually delivering a product. Since the terms “software” and “late” are nearly synonymous, it is the testers that frequently catch the ire of the whole business as they try to test the software at the end. It is the testers who are under pressure to finish faster and deem the product “release candidate” before they have had enough opportunity to be comfortable. To make matters worse, if bugs are discovered in the product after it has been released, everyone looks to the testers and says, “Why didn’t you spot those bugs?” The testers did not cause the bugs, but they must bear some of the guilt for the bugs that were disclosed.

Test Optimization for Continuous Integration

“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.

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 autotest 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