Skip to content

Commit

Permalink
chore: Use bdist_wheel instead of custom script (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 committed Dec 9, 2020
1 parent 58f212e commit c606344
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 110 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -27,7 +27,7 @@ jobs:
pip install -r local-requirements.txt
pip install -e .
- name: Build package
run: python build_package.py
run: python setup.py bdist_wheel
- name: Install browsers
run: python -m playwright install
- name: Lint
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
pip install -r local-requirements.txt
pip install -e .
- name: Build package
run: python build_package.py
run: python setup.py bdist_wheel
- name: Install browsers
run: python -m playwright install
- name: Test Sync API
Expand Down Expand Up @@ -113,6 +113,6 @@ jobs:
pip install -r local-requirements.txt
pip install -e .
- name: Build package
run: python build_package.py
run: python setup.py bdist_wheel
- name: Test package installation
run: bash buildbots/test-package-installations.sh
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
pip install -r local-requirements.txt
pip install -e .
- name: Build package
run: python build_package.py
run: python setup.py bdist_wheel
- name: Publish package
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
pip install -r local-requirements.txt
pip install -e .
- name: Build package
run: python build_package.py
run: python setup.py bdist_wheel
- name: Install
run: python -m playwright install
- name: Build Docker image
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_canary_docker.yml
Expand Up @@ -31,7 +31,7 @@ jobs:
pip install -r local-requirements.txt
pip install -e .
- name: Build package
run: python build_package.py
run: python setup.py bdist_wheel
- name: Install
run: python -m playwright install
- run: docker build -t playwright-python:localbuild .
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/test_docker.yml
Expand Up @@ -3,13 +3,11 @@ on:
push:
paths:
- '.github/workflows/test_docker.yml'
- 'build_package.py'
branches:
- master
pull_request:
paths:
- '.github/workflows/test_docker.yml'
- 'build_package.py'
branches:
- master
jobs:
Expand All @@ -28,7 +26,7 @@ jobs:
pip install -r local-requirements.txt
pip install -e .
- name: Build package
run: python build_package.py
run: python setup.py bdist_wheel
- name: Install
run: python -m playwright install
- name: Build Docker image
Expand All @@ -38,6 +36,6 @@ jobs:
CONTAINER_ID="$(docker run --rm -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-python:localbuild /bin/bash)"
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -r local-requirements.txt
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -e .
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" python build_package.py
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" python setup.py bdist_wheel
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv tests/sync/
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv tests/async/
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Expand Up @@ -17,6 +17,7 @@ Install required dependencies:
python -m pip install --upgrade pip wheel
pip install -r local-requirements.txt
pip install -e .
python setup.py bdist_wheel
```

For more details look at the [CI configuration](./blob/master/.github/workflows/ci.yml).
Expand Down
96 changes: 0 additions & 96 deletions build_package.py

This file was deleted.

7 changes: 3 additions & 4 deletions docs/development.md
Expand Up @@ -4,7 +4,7 @@

```sh
pip install -e .
python ./build_driver.py
python setup.py bdist_wheel
```

## Run tests:
Expand All @@ -23,9 +23,8 @@ open htmlcov/index.html
## Deploy:

```sh
python ./build_package.py
... check
python ./upload_package.py
python setup.py bdist_wheel
python setup.py upload
```

## Checking for typing errors
Expand Down
77 changes: 77 additions & 0 deletions setup.py
Expand Up @@ -12,11 +12,87 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import glob
import os
import shutil
import stat
import subprocess
import sys
import zipfile

import setuptools
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand

driver_version = "0.170.0-next.1605573954344"


with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()


class PlaywrightBDistWheelCommand(BDistWheelCommand):
def run(self) -> None:
if os.path.exists("build"):
shutil.rmtree("build")
if os.path.exists("dist"):
shutil.rmtree("dist")
if os.path.exists("playwright.egg-info"):
shutil.rmtree("playwright.egg-info")
super().run()
os.makedirs("driver", exist_ok=True)
os.makedirs("playwright/driver", exist_ok=True)
for platform in ["mac", "linux", "win32", "win32_x64"]:
zip_file = f"playwright-cli-{driver_version}-{platform}.zip"
if not os.path.exists("driver/" + zip_file):
url = "https://playwright.azureedge.net/builds/cli/next/" + zip_file
print("Fetching ", url)
subprocess.check_call(
["curl", "--http1.1", url, "-o", "driver/" + zip_file]
)
base_wheel_location = glob.glob("dist/*.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"]:
zip_file = f"driver/playwright-cli-{driver_version}-{platform}.zip"
with zipfile.ZipFile(zip_file, "r") as zip:
zip.extractall(f"driver/{platform}")
if platform_map[sys.platform] == platform:
with zipfile.ZipFile(zip_file, "r") as zip:
zip.extractall("playwright/driver")
for file in os.listdir("playwright/driver"):
if file == "playwright-cli" or file.startswith("ffmpeg"):
print(f"playwright/driver/{file}")
os.chmod(
f"playwright/driver/{file}",
os.stat(f"playwright/driver/{file}").st_mode | stat.S_IEXEC,
)
wheel = ""
if platform == "mac":
wheel = "macosx_10_13_x86_64.whl"
if platform == "linux":
wheel = "manylinux1_x86_64.whl"
if platform == "win32":
wheel = "win32.whl"
if platform == "win32_x64":
wheel = "win_amd64.whl"
wheel_location = without_platform + wheel
shutil.copy(base_wheel_location, wheel_location)
with zipfile.ZipFile(wheel_location, "a") as zip:
for file in os.listdir(f"driver/{platform}"):
from_location = f"driver/{platform}/{file}"
to_location = f"playwright/driver/{file}"
if file == "playwright-cli" or file.startswith("ffmpeg"):
os.chmod(
from_location, os.stat(from_location).st_mode | stat.S_IEXEC
)
zip.write(from_location, to_location)
os.remove(base_wheel_location)


setuptools.setup(
name="playwright",
author="Microsoft Corporation",
Expand All @@ -40,6 +116,7 @@
"Operating System :: OS Independent",
],
python_requires=">=3.7",
cmdclass={"bdist_wheel": PlaywrightBDistWheelCommand},
use_scm_version={
"version_scheme": "post-release",
"write_to": "playwright/_repo_version.py",
Expand Down

0 comments on commit c606344

Please sign in to comment.