Skip to content

Commit

Permalink
Merge pull request #2 from kngwyu/release0.0.2
Browse files Browse the repository at this point in the history
Release 0.0.2
  • Loading branch information
kngwyu authored May 30, 2019
2 parents aabbbb9 + bd24fb4 commit dff4658
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 92 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cache:

env:
global:
- TRAVIS_RUST_VERSION=nightly
- RUST_VERSION=nightly
- RUST_BACKTRACE=1
- FEATURES=python3

Expand All @@ -27,13 +27,13 @@ addons:
- libiberty-dev

before_install:
- source ./ci/setup.sh
- source ./ci/travis/setup.sh

install:
- pip install setuptools-rust tox

script:
- ./ci/test.sh
- ./ci/travis/test.sh

notifications:
email: false
6 changes: 6 additions & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Developper notes

## Build manylinux wheel
```
docker run --rm -v $PWD:/io quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh
```
76 changes: 76 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
jobs:
- job: WindowsTest
pool: {vmImage: 'vs2017-win2016'}
strategy:
maxParallel: 2
matrix:
Python36:
PYTHON_VERSION: '3.6'
Python37:
PYTHON_VERSION: '3.7'
steps:
- template: ci/azure/install.yml
parameters:
python_version: $(PYTHON_VERSION)
- bash: |
rustup default nightly
cargo test --manifest-path=core/Cargo.toml
cd python
cargo test --no-default-features
tox -e py
displayName: Test on windows
- job: MacOsWheel
pool: {vmImage: 'macOS-10.13'}
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
strategy:
maxParallel: 2
matrix:
Python36:
PYTHON_VERSION: '3.6'
Python37:
PYTHON_VERSION: '3.7'
steps:
- template: ci/azure/install.yml
parameters:
python_version: $(PYTHON_VERSION)
- template: ci/azure/buildwheel.yml
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: wheelhouse
artifactName: MacOsWheel

- job: WindowsWheel
pool: {vmImage: 'vs2017-win2016'}
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
strategy:
maxParallel: 2
matrix:
Python36:
PYTHON_VERSION: '3.6'
Python37:
PYTHON_VERSION: '3.7'
steps:
- template: ci/azure/install.yml
parameters:
python_version: $(PYTHON_VERSION)
- template: ci/azure/buildwheel.yml
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: wheelhouse
artifactName: WindowsWheel

- job: ManyLinux1Wheel
pool: {vmImage: 'Ubuntu-16.04'}
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
steps:
- script: |
docker pull quay.io/pypa/manylinux1_x86_64
docker run --rm -v $PWD:/io quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh
mkdir wheelhouse
sudo mv python/dist/*manylinux1*.whl wheelhouse
displayName: Build manylinux1 wheel
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: wheelhouse
artifactName: ManyLinux1Wheel
1 change: 0 additions & 1 deletion build-wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ done
for whl in dist/*.whl; do
auditwheel repair "$whl" -w dist/
done

8 changes: 8 additions & 0 deletions ci/azure/buildwheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- bash: |
rustup default nightly
mkdir wheelhouse
cd python
python setup.py bdist_wheel
mv dist/*.whl ../wheelhouse
displayName: Build wheel
40 changes: 40 additions & 0 deletions ci/azure/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
parameters:
rust_version: nightly
python_version: 3.6
python_arch: x64

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: ${{ parameters.python_version }}
addToPath: true
architecture: ${{ parameters.python_arch }}

- script: |
ci/travis/setup.sh
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
env:
RUST_VERSION: ${{ parameters.rust_version }}
displayName: Install Rust for Mac or Linux
condition: not(eq(variables['Agent.OS'], 'Windows_NT'))
- script: |
curl -sSf -o rustup-init.exe https://win.rustup.rs
rustup-init.exe -y --default-toolchain %RUST_VERSION%
echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
env:
RUST_VERSION: ${{parameters.rust_version}}
displayName: Install Rust for Windows
condition: eq(variables['Agent.OS'], 'Windows_NT')
- script: |
python -m pip install --upgrade pip setuptools wheel
pip install tox tox-venv setuptools-rust
displayName: Install Python packages
- script: |
rustup -V
rustup component list --installed
rustc -Vv
cargo -V
displayName: Query Rust versions
9 changes: 0 additions & 9 deletions ci/test.sh

This file was deleted.

4 changes: 2 additions & 2 deletions ci/setup.sh → ci/travis/setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

set -e

Expand All @@ -15,7 +15,7 @@ _latest() {
}

### Setup Rust toolchain #######################################################
curl -SsL "https://sh.rustup.rs/" | sh -s -- -y --default-toolchain=$TRAVIS_RUST_VERSION
curl -SsL "https://sh.rustup.rs/" | sh -s -- -y --default-toolchain=$RUST_VERSION
export PATH=$PATH:$HOME/.cargo/bin

### Setup python linker flags ##################################################
Expand Down
9 changes: 9 additions & 0 deletions ci/travis/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -ex

cargo build --verbose --all
cargo test --manifest-path=core/Cargo.toml
cd python
cargo test --no-default-features
tox -e py
3 changes: 1 addition & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ version = "1.0"
features = ["serde"]
version = "0.6"

[dependencies.termion]
optional = true
[target.'cfg(unix)'.dependencies.termion]
version = "1.5.1"

[features]
Expand Down
2 changes: 1 addition & 1 deletion core/src/dungeon/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Coord {
pub fn is_lefter(self, other: Coord) -> bool {
self.x < other.x
}
#[cfg(feature = "termion")]
#[cfg(unix)]
pub fn into_cursor(self) -> termion::cursor::Goto {
let (x, y) = (self.x.0, self.y.0).map(|i| i as u16).add((1, 1));
termion::cursor::Goto(x, y)
Expand Down
4 changes: 2 additions & 2 deletions core/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ mod keymap_test {
}
}

#[cfg(feature = "termion")]
#[cfg(unix)]
use termion::event::Key as TermionKey;

#[cfg(feature = "termion")]
#[cfg(unix)]
impl From<TermionKey> for Key {
fn from(key: TermionKey) -> Key {
use self::TermionKey::*;
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern crate regex;
extern crate serde;
extern crate serde_json;
extern crate smallvec;
#[cfg(feature = "termion")]
#[cfg(unix)]
extern crate termion;
#[cfg(feature = "bench")]
extern crate test;
Expand Down
5 changes: 3 additions & 2 deletions devui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ clap = "2.31"
failure = "0.1.2"
fern = "0.5.5"
log = "0.4.1"
termion = "1.5"
tuple-map = "0.4.0"
chrono = "0.4.2"

[target.'cfg(unix)'.dependencies.termion]
version = "1.5.1"

[dependencies.rogue-gym-core]
features = ["termion"]
path = "../core/"
version = "0.1.0"

Expand Down
11 changes: 7 additions & 4 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ crate-type = ["cdylib"]
[dependencies]
failure = "0.1.3"
ndarray = "0.12"
numpy = "0.5.0"
numpy = "0.6.0"
rect-iter = "0.2.0"

[dependencies.pyo3]
version = "0.6.0"
features = ["extension-module"]
version = "0.7.0"

[dependencies.rogue-gym-core]
path = "../core/"
version = "0.1.0"

[target.'cfg(unix)'.dependencies.rogue-gym-devui]
path = "../devui/"
version = "0.1.0"
version = "0.1.0"

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]
11 changes: 2 additions & 9 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# rogue-gym python API

You can use rogue-gym as [Open AI Gym](https://github.com/openai/gym) environment.
Python interface of [Rogue-Gym](https://github.com/kngwyu/rogue-gym) compatible with
[Open AI Gym](https://github.com/openai/gym) environments.

# API documents
COMING SOON
Expand Down Expand Up @@ -43,11 +44,3 @@ COMING SOON

Level: 1 Gold: 0 Hp: 12(12) Str: 16(16) Arm: 0 Exp: 1/ 0
```
# Developper notes
Build wheel
```
cd ../
docker run --rm -v $PWD:/io quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh
```
3 changes: 3 additions & 0 deletions python/rogue_gym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
from . import rainy_impls
except ImportError:
pass


__version__ = '0.0.2'
11 changes: 7 additions & 4 deletions python/rogue_gym/envs/rogue_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
from numpy import ndarray
from typing import Dict, List, NamedTuple, Optional, Tuple, Union
from rogue_gym_python import _rogue_gym as rogue_gym_inner
from rogue_gym_python._rogue_gym import GameState, PlayerState


Expand Down Expand Up @@ -182,14 +183,16 @@ def save_actions(self, fname: str) -> None:
f.write(self.game.dump_history())

def replay(self, interval_ms: int = 100) -> None:
if not hasattr(self.game, 'replay'):
if not hasattr(rogue_gym_inner, 'replay'):
raise RuntimeError('Currently replay is only supported on UNIX')
self.game.replay(interval_ms)
rogue_gym_inner.replay(self.game, interval_ms)
print()

def play_cli(self) -> None:
if not hasattr(self.game, 'play_cli'):
if not hasattr(rogue_gym_inner, 'play_cli'):
raise RuntimeError('CLI playing is only supported on UNIX')
self.game.play_cli()
rogue_gym_inner.play_cli(self.game)
print()

def state_to_image(
self,
Expand Down
22 changes: 0 additions & 22 deletions python/rogue_gym/envs/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,3 @@ def step(
reward[i] += self.stair_reward
self.current_levels[i] = level
return state, reward, end, info


class Parallel(ParallelRogueEnv):
def __init__(self, *args, **kwargs) -> None:
self.stair_reward = 50.0 # default reward
if 'stair_reward' in kwargs:
self.stair_reward = kwargs['stair_reward']
del kwargs['stair_reward']
super().__init__(*args, **kwargs)
self.current_levels = [1] * self.num_workers

def step(
self,
action: Union[Iterable[int], str]
) -> Tuple[List[PlayerState], List[float], List[bool], List[dict]]:
state, reward, end, info = super().step(action)
for i in range(self.num_workers):
level = state[i].status['dungeon_level']
if self.current_levels[i] < level:
reward[i] += self.stair_reward
self.current_levels[i] = level
return state, reward, end, info
4 changes: 2 additions & 2 deletions python/rogue_gym/rainy_impls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def action_dim(self) -> int:
def state_dim(self) -> Tuple[int, ...]:
return self._env.unwrapped.observation_space.shape

def state_to_array(self, state: PlayerState) -> ndarray:
def extract(self, state: PlayerState) -> ndarray:
return self._env.unwrapped.image_setting.expand(state)

def save_history(self, file_name: str) -> None:
Expand Down Expand Up @@ -61,5 +61,5 @@ def num_envs(self) -> int:
def spec(self) -> EnvSpec:
return self._spec

def states_to_array(self, states: Iterable[PlayerState]) -> Array:
def extract(self, states: Iterable[PlayerState]) -> Array:
return np.stack([self._env.image_setting.expand(state) for state in states])
Loading

0 comments on commit dff4658

Please sign in to comment.