<commit_before># Copyright 2017-2018 TensorHub, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division

import logging
import os
import subprocess
import sys

from guild import cli

from . import runs_impl

log = logging.getLogger("guild")

def main(args, ctx):
    if args.path and os.path.isabs(args.path):
        cli.error(
            "PATH must be relative\n"
            "Try 'guild open --help' for more information.")
    run = runs_impl.one_run(args, ctx)
    _open(run, args)
    _flush_streams_and_exit()

def _open(run, args):
    path = os.path.join(run.path, args.path or "")
    open_f = _open_f(args)
    try:
        open_f(path)
    except Exception as e:
        if log.getEffectiveLevel() <= logging.DEBUG:
            log.exception("opening %s", path)
        cli.error(e)

def _open_f(args):
    if args.cmd:
        return _subproc(args.cmd)
    elif os.name == "nt":
        return os.startfile
    elif os.name == "posix":
        return _subproc("xdg-open")
    elif sys.platform.startswith("darwin"):
        return _subproc("open")
    else:
        cli.error(
            "unsupported platform: %s %s\n"<commit_msg>Fix open on OSX<commit_after># Copyright 2017-2018 TensorHub, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division

import logging
import os
import subprocess
import sys

from guild import cli

from . import runs_impl

log = logging.getLogger("guild")

def main(args, ctx):
    if args.path and os.path.isabs(args.path):
        cli.error(
            "PATH must be relative\n"
            "Try 'guild open --help' for more information.")
    run = runs_impl.one_run(args, ctx)
    _open(run, args)
    _flush_streams_and_exit()

def _open(run, args):
    path = os.path.join(run.path, args.path or "")
    open_f = _open_f(args)
    try:
        open_f(path)
    except Exception as e:
        if log.getEffectiveLevel() <= logging.DEBUG:
            log.exception("opening %s", path)
        cli.error(e)

def _open_f(args):
    if args.cmd:
        return _subproc(args.cmd)
    elif os.name == "nt":
        return os.startfile
    elif sys.platform.startswith("darwin"):
        return _subproc("open")
    elif os.name == "posix":
        return _subproc("xdg-open")
    else:
        cli.error(
            "unsupported platform: %s %s\n"
{'fraction_non_alphanumeric': 0.09824561403508772, 'fraction_numerical': 0.007017543859649123, 'mean_word_length': 3.0058548009367683, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '212691', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1030, 'n_words': 364}