Skip to content

Commit

Permalink
Add multiple scheduler support & process restart support (#36)
Browse files Browse the repository at this point in the history
* add multiple scheduler support & process restart support

* refine cases

* remove redundant code

* fix issues
  • Loading branch information
wjsi authored and qinxuye committed Dec 24, 2018
1 parent a3af2f4 commit d3eca58
Show file tree
Hide file tree
Showing 45 changed files with 982 additions and 321 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parallel = True
include =
mars/*
omit =
mars/compat/*
mars/lib/functools32/*
mars/lib/futures/*
mars/lib/enum.py
Expand Down
1 change: 1 addition & 0 deletions .coveragerc-tensor
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parallel = True
include =
mars/*
omit =
mars/compat/*
mars/lib/functools32/*
mars/lib/futures/*
mars/lib/enum.py
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ matrix:

before_install:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then source ./bin/travis-prepare-osx.sh; fi
- pip install --upgrade pip setuptools wheel
- pip install --upgrade pip setuptools wheel coverage

# command to install dependencies
install:
Expand Down
10 changes: 10 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXINTL = sphinx-intl
SPHINXPROJ = mars
SOURCEDIR = source
BUILDDIR = build

# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(SOURCEDIR)
I18NSPHINXLANGS = -l zh_CN

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
$(SPHINXINTL) update -p $(BUILDDIR)/locale $(I18NSPHINXLANGS)
$(SOURCEDIR)/norm_zh.py

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
Expand Down
Empty file modified docs/build.sh
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
if "%SPHINXINTL%" == "" (
set SPHINXINTL=sphinx-intl
)
set SOURCEDIR=source
set BUILDDIR=build
set SPHINXPROJ=mars
set I18NSPHINXOPTS=%SPHINXOPTS% %SOURCEDIR%
set I18NSPHINXLANGS=-l zh_CN

if "%1" == "" goto help
if "%1" == "gettext" goto gettext

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
Expand All @@ -29,6 +35,15 @@ if errorlevel 9009 (
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end

:gettext
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
if errorlevel 1 exit /b 1
%SPHINXINTL% update -p %BUILDDIR%/locale %I18NSPHINXLANGS%
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%

Expand Down
136 changes: 136 additions & 0 deletions docs/source/norm_zh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 1999-2018 Alibaba Group Holding Ltd.
#
# 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.

"""
This file folds Chinese po files by hacking babel.messages.pofile.normalize
using jieba text segment library instead of regex
"""

import os

from babel.messages import pofile
from babel.messages.pofile import escape


def _zh_len(s):
"""
Calculate text length in Chinese
"""
try:
return len(s.encode('gb2312'))
except ValueError:
return len(s)


def _zh_split(s):
"""
Split text length in Chinese
"""
import jieba
try:
s.encode('ascii')
has_zh = False
except ValueError:
has_zh = True

if has_zh:
return list(jieba.cut(s))
else:
return pofile.WORD_SEP.split(s)


# code modified from babel.messages.pofile (hash 359ecffca479dfe032d0f7210d5cd8160599c816)
def _normalize(string, prefix='', width=76):
r"""Convert a string into a format that is appropriate for .po files.
>>> print(normalize('''Say:
... "hello, world!"
... ''', width=None))
""
"Say:\n"
" \"hello, world!\"\n"
>>> print(normalize('''Say:
... "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
... ''', width=32))
""
"Say:\n"
" \"Lorem ipsum dolor sit "
"amet, consectetur adipisicing"
" elit, \"\n"
:param string: the string to normalize
:param prefix: a string that should be prepended to every line
:param width: the maximum line width; use `None`, 0, or a negative number
to completely disable line wrapping
"""

if width and width > 0:
prefixlen = _zh_len(prefix)
lines = []
for line in string.splitlines(True):
if _zh_len(escape(line)) + prefixlen > width:
chunks = _zh_split(line)
chunks.reverse()
while chunks:
buf = []
size = 2
while chunks:
l = _zh_len(escape(chunks[-1])) - 2 + prefixlen
if size + l < width:
buf.append(chunks.pop())
size += l
else:
if not buf:
# handle long chunks by putting them on a
# separate line
buf.append(chunks.pop())
break
lines.append(u''.join(buf))
else:
lines.append(line)
else:
lines = string.splitlines(True)

if len(lines) <= 1:
return escape(string)

# Remove empty trailing line
if lines and not lines[-1]:
del lines[-1]
lines[-1] += '\n'
return u'""\n' + u'\n'.join([(prefix + escape(line)) for line in lines])


def main():
try:
import jieba
except ImportError:
return

pofile.normalize = _normalize
for root, dirs, files in os.walk('.'):
if 'zh' not in root:
continue
for f in files:
if not f.endswith('.po'):
continue
path = os.path.join(root, f)
with open(path, 'rb') as inpf:
catalog = pofile.read_po(inpf)
with open(path, 'wb') as outf:
pofile.write_po(outf, catalog)


if __name__ == '__main__':
main()

0 comments on commit d3eca58

Please sign in to comment.