Best Python code snippet using playwright-python
setup.py
Source:setup.py  
...118                    and wheel["machine"] == platform.machine().lower(),119                    base_wheel_bundles,120                )121            )[:1]122        self._build_wheels(wheels)123    def _build_wheels(124        self,125        wheels: List[Dict[str, str]],126    ) -> None:127        base_wheel_location: str = glob.glob(os.path.join(self.dist_dir, "*.whl"))[0]128        without_platform = base_wheel_location[:-7]129        for wheel_bundle in wheels:130            download_driver(wheel_bundle["zip_name"])131            zip_file = (132                f"driver/playwright-{driver_version}-{wheel_bundle['zip_name']}.zip"133            )134            with zipfile.ZipFile(zip_file, "r") as zip:135                extractall(zip, f"driver/{wheel_bundle['zip_name']}")136            wheel_location = without_platform + wheel_bundle["wheel"]137            shutil.copy(base_wheel_location, wheel_location)...build.py
Source:build.py  
...22        self._create_build_copies()23        self._transpile_py2()24        if run_test:25            self._run_unit_tests_py2(True)26        self._build_wheels()27        self._upload_to_nexus()2829    def run_py2_tests(self, run_slow_tests=False):30        self._cleanup_last_build()31        self._create_build_copies()32        self._transpile_py2()33        self._run_unit_tests_py2(run_slow_tests)343536    def _increment_version(self):37        # Increment the version number38        self.version = increment_version(r"{}\__init__.py".format(app_name), app_name, format='increment')3940    def _cleanup_last_build(self):41        # Cleanup last build42        if (self.topdir / 'dist').is_dir():43            shutil.rmtree(self.topdir / 'dist')44        if(self.topdir / 'build').is_dir():45            shutil.rmtree(self.topdir / 'build')4647    def _create_build_copies(self):48        # Copy existing code into python 3 and 2 folders49        (self.topdir / 'build').mkdir()50        (self.topdir / 'build' / 'py3').mkdir()51        (self.topdir / 'build' / 'py2').mkdir()52        self._copy_to_build(self.topdir / 'build' / 'py2', py2=True)53        self._copy_to_build(self.topdir / 'build' / 'py3', py2=False)5455    def _copy_to_build(self, output_dir: Path, py2=False):56        for root, dirs, files in os.walk(self.topdir.str):57            if 'build' in root:58                continue59            if '.git' in root:60                continue61            if '.idea' in root:62                continue63            if '__pycache__' in root:64                continue65            ext_dir = output_dir / Path(root).relative_to(self.topdir)66            if not ext_dir.is_dir():67                ext_dir.mkdir()68            for fn in files:69                if not (fn.endswith(".py") or fn.endswith(".txt")):70                    continue71                fp = Path(root) / fn72                ext = fp.relative_to(self.topdir)7374                if fn.endswith(".py2.py"):75                    # Overwite the py3 version with py276                    py3fn = output_dir / ext.str.replace(".py2.py", ".py")77                    assert py3fn.is_file(), f"Missing: {py3fn}"7879                    if py2:80                        shutil.copy(fp, os.path.join(output_dir, ext.str.replace(".py2.py", ".py")))81                    else:82                        pass # noop: skip file83                else:84                    shutil.copy(fp, os.path.join(output_dir, ext.str))858687    def _transpile_py2(self):88        # Run 3to6 on py2 folder89        from lib3to6.common import  BuildContext, BuildConfig, CheckError90        from lib3to6.transpile import transpile_module_data9192        cfg = BuildConfig(target_version='2.7',93                          cache_enabled=False,94                          default_mode='enabled',95                          fixers=['AnnotationsFutureFixer', 'GeneratorStopFutureFixer',96                                    'UnicodeLiteralsFutureFixer', 'RemoveUnsupportedFuturesFixer',97                                    'PrintFunctionFutureFixer', 'WithStatementFutureFixer',98                                    'AbsoluteImportFutureFixer', 'DivisionFutureFixer',99                                    'GeneratorsFutureFixer', 'NestedScopesFutureFixer',100                                    'XrangeToRangeFixer',101                                    'UnicodeToStrFixer', 'UnichrToChrFixer', 'RawInputToInputFixer',102                                    'RemoveFunctionDefAnnotationsFixer', 'ForwardReferenceAnnotationsFixer',103                                    'RemoveAnnAssignFixer', 'ShortToLongFormSuperFixer',104                                    'InlineKWOnlyArgsFixer', 'NewStyleClassesFixer',105                                    'UnpackingGeneralizationsFixer',106                                    'NamedTupleClassToAssignFixer', 'FStringToStrFormatFixer',107                                    'UnpackingGeneralizationsFixer'],108                          checkers=['NoAsyncAwait', 'NoComplexNamedTuple',109                                    'NoYieldFromChecker', 'NoMatMultOpChecker'],110                          install_requires=None)111        for filepath in (self.topdir / 'build' / 'py2' / 'pjmlib').walk_files():112            if filepath.suffix != '.py':113                continue114            with open(filepath, mode='rb') as fobj:115                module_source_data = fobj.read()116117            ctx = BuildContext(cfg, str(filepath))118            try:119                fixed_module_source_data = transpile_module_data(ctx,120                                                                 module_source_data)121            except CheckError as err:122                loc = str(filepath)123                if err.lineno >= 0:124                    loc += '@' + str(err.lineno)125                err.args = (loc + ' - ' + err.args[0],) + err.args[1:]126                raise127            with open(filepath, mode='wb') as fobj:128                fobj.write(fixed_module_source_data)129130    def _run_unit_tests_py2(self, run_slow_tests):131        (self.topdir / 'build' / 'py2').chdir()132        os.environ['SLOW_TESTS'] = 'yes' if run_slow_tests else 'no'133        # os.system(r"C:\Personal\projects\venvs\venv_pjmlib_py27\Scripts\python.exe -m pjmlib.test_pjmlib")134        os.system(r"C:\Python27\python.exe -m unittest discover "135                  rf"-s {self.topdir / 'pjmlib' / 'tests'}"136                  rf"-t {self.topdir / 'pjmlib' / 'tests'}")137138        print('-' * 80)139        print("Did the tests pass?")140        input(">>>")141142    def _build_wheels(self):143        if self.version is None:144            from pjmlib import __version__145            self.version = __version__146147        (self.topdir / 'dist').mkdir()148149        (self.topdir / 'build' / 'py3').chdir()150        print("building py3 wheel...")151        os.system('python.exe setup.py sdist bdist_wheel')152        shutil.copy(self.topdir / 'build' / 'py3' / 'dist' / f"{app_name}-{self.version}-py3-none-any.whl",153                    self.topdir / 'dist')154155        (self.topdir / 'build' / 'py2').chdir()156        print("building py2 wheel...")
...LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!
