From 052405c565a11c237991ef55ce098b76ef26f132 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 4 Mar 2021 14:04:21 +0530 Subject: [PATCH] feat: Installation from github --- .github/workflows/publish.yml | 2 +- .pre-commit-config.yaml | 1 + CONTRIBUTING.md | 2 ++ pyproject.toml | 3 +++ setup.py | 39 +++++++++++++++++++++++------------ 5 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 pyproject.toml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ef090e1da..79bcc7166 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ jobs: python -m pip install --upgrade pip pip install -r local-requirements.txt pip install -e . - python setup.py bdist_wheel + python setup.py bdist_wheel --all python -m playwright install-deps - name: Publish package env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c7b54980c..63c5cae96 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,6 +8,7 @@ repos: - id: end-of-file-fixer exclude: ^playwright/drivers/browsers.json$ - id: check-yaml + - id: check-toml - id: requirements-txt-fixer - repo: https://github.com/psf/black rev: 20.8b1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1bc4e9ca4..2af0ab7f2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,6 +24,8 @@ Build and install drivers: ```sh pip install -e. python setup.py bdist_wheel +# For all platforms +python setup.py bdist_wheel --all ``` Run tests: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..05e6283de --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools-scm", "wheel", "auditwheel"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index a403456f4..ce0f8150e 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,15 @@ def extractall(zip: zipfile.ZipFile, path: str) -> None: class PlaywrightBDistWheelCommand(BDistWheelCommand): + user_options = BDistWheelCommand.user_options + [ + ("all", "a", "create wheels for all platforms") + ] + boolean_options = BDistWheelCommand.boolean_options + ["all"] + + def initialize_options(self) -> None: + super().initialize_options() + self.all = False + def run(self) -> None: if os.path.exists("build"): shutil.rmtree("build") @@ -47,7 +56,16 @@ def run(self) -> None: super().run() os.makedirs("driver", exist_ok=True) os.makedirs("playwright/driver", exist_ok=True) - for platform in ["mac", "linux", "win32", "win32_x64"]: + platform_map = { + "darwin": "mac", + "linux": "linux", + "win32": "win32_x64" if sys.maxsize > 2 ** 32 else "win32", + } + if self.all: + platforms = ["mac", "linux", "win32", "win32_x64"] + else: + platforms = [platform_map[sys.platform]] + for platform in platforms: zip_file = f"playwright-{driver_version}-{platform}.zip" if not os.path.exists("driver/" + zip_file): url = "https://playwright.azureedge.net/builds/driver/" @@ -56,14 +74,10 @@ def run(self) -> None: print("Fetching ", url) # Don't replace this with urllib - Python won't have certificates to do SSL on all platforms. subprocess.check_call(["curl", url, "-o", "driver/" + zip_file]) - base_wheel_location = glob.glob("dist/*.whl")[0] + base_wheel_location = glob.glob(os.path.join(self.dist_dir, "*.whl"))[0] without_platform = base_wheel_location[:-7] - platform_map = { - "darwin": "mac", - "linux": "linux", - "win32": "win32_x64" if sys.maxsize > 2 ** 32 else "win32", - } - for platform in ["mac", "linux", "win32", "win32_x64"]: + + for platform in platforms: zip_file = f"driver/playwright-{driver_version}-{platform}.zip" with zipfile.ZipFile(zip_file, "r") as zip: extractall(zip, f"driver/{platform}") @@ -88,7 +102,7 @@ def run(self) -> None: from_path = os.path.join(dir_path, file) to_path = os.path.relpath(from_path, driver_root) zip.write(from_path, f"playwright/driver/{to_path}") - if platform == "mac": + if platform == "mac" and self.all: # Ship mac both as 10_13 as and 11_0 universal to work across Macs. universal_location = without_platform + "macosx_11_0_universal2.whl" shutil.copyfile(wheel_location, universal_location) @@ -96,8 +110,7 @@ def run(self) -> None: zip.writestr("playwright/driver/README.md", "Universal Mac package") os.remove(base_wheel_location) - for whlfile in glob.glob("dist/*.whl"): - + for whlfile in glob.glob(os.path.join(self.dist_dir, "*.whl")): os.makedirs("wheelhouse", exist_ok=True) with InWheel( in_wheel=whlfile, @@ -105,9 +118,9 @@ def run(self) -> None: ret_self=True, ): print("Updating RECORD file of %s" % whlfile) - shutil.rmtree("dist") + shutil.rmtree(self.dist_dir) print("Copying new wheels") - shutil.move("wheelhouse", "dist") + shutil.move("wheelhouse", self.dist_dir) setuptools.setup(