From 6d9d2b320a94d81d79b6d4899b5287cd2e0c90aa Mon Sep 17 00:00:00 2001 From: Julius Frost <33183774+juliusfrost@users.noreply.github.com> Date: Thu, 13 Aug 2020 05:57:54 -0400 Subject: [PATCH] [RLlib] Support windows drives other than C drive for the offline json API (#9909) --- rllib/offline/json_reader.py | 6 ++++-- rllib/offline/json_writer.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rllib/offline/json_reader.py b/rllib/offline/json_reader.py index 40ba37bd5..54ef3d504 100644 --- a/rllib/offline/json_reader.py +++ b/rllib/offline/json_reader.py @@ -21,6 +21,8 @@ from typing import List logger = logging.getLogger(__name__) +WINDOWS_DRIVES = [chr(i) for i in range(ord("c"), ord("z") + 1)] + @PublicAPI class JsonReader(InputReader): @@ -47,7 +49,7 @@ class JsonReader(InputReader): logger.warning( "Treating input directory as glob pattern: {}".format( inputs)) - if urlparse(inputs).scheme not in ["", "c"]: + if urlparse(inputs).scheme not in [""] + WINDOWS_DRIVES: raise ValueError( "Don't know how to glob over `{}`, ".format(inputs) + "please specify a list of files to read instead.") @@ -126,7 +128,7 @@ class JsonReader(InputReader): def _next_file(self) -> FileType: path = random.choice(self.files) - if urlparse(path).scheme not in ["", "c"]: + if urlparse(path).scheme not in [""] + WINDOWS_DRIVES: if smart_open is None: raise ValueError( "You must install the `smart_open` module to read " diff --git a/rllib/offline/json_writer.py b/rllib/offline/json_writer.py index c2e3cd942..3b5f4e895 100644 --- a/rllib/offline/json_writer.py +++ b/rllib/offline/json_writer.py @@ -21,6 +21,8 @@ from typing import Any, List logger = logging.getLogger(__name__) +WINDOWS_DRIVES = [chr(i) for i in range(ord("c"), ord("z") + 1)] + @PublicAPI class JsonWriter(OutputWriter): @@ -44,7 +46,7 @@ class JsonWriter(OutputWriter): self.ioctx = ioctx or IOContext() self.max_file_size = max_file_size self.compress_columns = compress_columns - if urlparse(path).scheme not in ["", "c"]: + if urlparse(path).scheme not in [""] + WINDOWS_DRIVES: self.path_is_uri = True else: path = os.path.abspath(os.path.expanduser(path))