Skip to content

Commit

Permalink
generate python wheel when merge into master (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinkle23897 authored Nov 25, 2021
1 parent 25c45dd commit c193a30
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.17.2'
go-version: '^1.17.3'
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release PyPI Wheel

on:
push:
branches:
- master

jobs:
release:
runs-on: [self-hosted, Linux, X64, Wheel]
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- name: Cancel previous run
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.17.3'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
- name: Build
run: |
make pypi-wheel BAZELOPT="--remote_cache=http://bazel-cache.sail:8080"
pip3 install wheelhouse/*.whl
- name: Test
run: |
make release-test
- name: Upload artifact
uses: actions/upload-artifact@master
with:
name: wheel
path: wheelhouse/
6 changes: 1 addition & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.17.2'
go-version: '^1.17.3'
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
# make bazel-install
- name: Build
run: |
make bazel-build BAZELOPT="--remote_cache=http://bazel-cache.sail:8080"
- name: Test
run: |
make bazel-test BAZELOPT="--remote_cache=http://bazel-cache.sail:8080"
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ doc-install:
$(call check_install_extra, sphinxcontrib.spelling, sphinxcontrib.spelling pyenchant)

auditwheel-install:
$(call check_install, auditwheel)
$(call check_install_extra, auditwheel, auditwheel typed-ast)

# python linter

Expand Down Expand Up @@ -87,7 +87,7 @@ bazel-build: bazel-install
bazel-test: bazel-install
bazel test --test_output=all $(BAZELOPT) //... --config=release

bazel-clean:
bazel-clean: bazel-install
bazel clean --expunge

# documentation
Expand Down Expand Up @@ -120,13 +120,13 @@ format: py-format-install clang-format-install buildifier-install addlicense-ins

docker-dev:
docker build --network=host -t $(PROJECT_NAME):$(COMMIT_HASH) -f docker/dev.dockerfile .
docker run -v /:/host -it $(PROJECT_NAME):$(COMMIT_HASH) bash
docker run --network=host -v /:/host -it $(PROJECT_NAME):$(COMMIT_HASH) bash
echo successfully build docker image with tag $(PROJECT_NAME):$(COMMIT_HASH)

docker-release:
docker build --network=host -t $(PROJECT_NAME)-release:$(COMMIT_HASH) -f docker/release.dockerfile .
mkdir -p wheelhouse
docker run -v `pwd`/wheelhouse:/whl -it $(PROJECT_NAME)-release:$(COMMIT_HASH) bash -c "cp wheelhouse/* /whl"
docker run --network=host -v `pwd`/wheelhouse:/whl -it $(PROJECT_NAME)-release:$(COMMIT_HASH) bash -c "cp wheelhouse/* /whl"
echo successfully build docker image with tag $(PROJECT_NAME)-release:$(COMMIT_HASH)

pypi-wheel: bazel-clean auditwheel-install bazel-build
Expand Down
6 changes: 6 additions & 0 deletions docker/release.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ RUN ln -sf /usr/local/go/bin/go /usr/bin/go

RUN go install github.com/bazelbuild/bazelisk@latest && ln -sf $HOME/go/bin/bazelisk $HOME/go/bin/bazel

# install big wheels

RUN for i in 7 8 9; do ln -sf /usr/bin/python3.$i /usr/bin/python3; pip3 install torch opencv-python-headless; done

RUN bazel version

WORKDIR /app
COPY . .

Expand Down
7 changes: 6 additions & 1 deletion docs/pages/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ EnvPool requires gcc/g++ version >= 9.0 to build the source code. To install:

.. code-block:: bash
sudo apt install -y gcc-9 g++-9
# optional
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
# install
sudo apt install -y gcc-9 g++-9 build-essential
# to change the default cc to gcc-9:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9
Expand Down
14 changes: 8 additions & 6 deletions envpool/atari/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
"""Unit test for atari envpool and speed benchmark."""

from typing import no_type_check

import dm_env
import gym
import numpy as np
Expand All @@ -24,6 +26,7 @@

class _SpecTest(absltest.TestCase):

@no_type_check
def test_spec(self) -> None:
action_nums = {"pong": 6, "breakout": 4}
for task in ["pong", "breakout"]:
Expand All @@ -35,9 +38,8 @@ def test_spec(self) -> None:
spec.action_array_spec["action"].maximum + 1, action_num
)
# check dm spec
dm_obs_spec: dm_env.specs.BoundedArray = spec.observation_spec(
).obs # type: ignore
dm_act_spec: dm_env.specs.DiscreteArray = spec.action_spec()
dm_obs_spec = spec.observation_spec().obs
dm_act_spec = spec.action_spec()
self.assertEqual(len(spec.action_array_spec), 3)
self.assertIsInstance(dm_obs_spec, dm_env.specs.BoundedArray)
self.assertEqual(dm_obs_spec.dtype, np.uint8)
Expand Down Expand Up @@ -94,6 +96,7 @@ def test_metadata(self) -> None:

class _DMSyncTest(absltest.TestCase):

@no_type_check
def test_spec(self) -> None:
action_nums = {"pong": 6, "breakout": 4}
for task in ["pong", "breakout"]:
Expand All @@ -104,9 +107,8 @@ def test_spec(self) -> None:
self.assertIsInstance(env, dm_env.Environment)
logging.info(env)
# check dm spec
dm_obs_spec: dm_env.specs.BoundedArray = env.observation_spec(
).obs # type: ignore
dm_act_spec: dm_env.specs.DiscreteArray = env.action_spec()
dm_obs_spec = env.observation_spec().obs
dm_act_spec = env.action_spec()
self.assertIsInstance(dm_obs_spec, dm_env.specs.BoundedArray)
self.assertEqual(dm_obs_spec.dtype, np.uint8)
self.assertEqual(dm_obs_spec.maximum, 255)
Expand Down
1 change: 1 addition & 0 deletions envpool/workspace0.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def workspace():
sha256 = "e39e9fc379fe3f336911d928ce0a52e6ff6861258906efc5e849390867ff35f5",
urls = [
"https://roms8.s3.us-east-2.amazonaws.com/Roms.tar.gz",
"https://cdn.sail.sea.com/sail/Roms.tar.gz",
],
build_file = "//third_party/atari_roms:atari_roms.BUILD",
)
Expand Down

0 comments on commit c193a30

Please sign in to comment.