Skip to content

Commit

Permalink
Merge 66e8cb8 into 594ee2b
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi committed Jan 7, 2020
2 parents 594ee2b + 66e8cb8 commit a8b20ec
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
@@ -1,5 +1,6 @@
[run]
branch = True
relative_files = True
cover_pylib = False
concurrency = multiprocessing,gevent
parallel = True
Expand All @@ -18,6 +19,7 @@ omit =
mars/lib/uhashring/*
mars/serialize/protos/*
mars/learn/contrib/xgboost/tracker.py
*.html
*.pxd
*/tests/*

Expand Down
2 changes: 2 additions & 0 deletions .coveragerc-threaded
Expand Up @@ -4,6 +4,7 @@

[run]
branch = True
relative_files = True
cover_pylib = False
parallel = True
plugins = Cython.Coverage
Expand All @@ -21,6 +22,7 @@ omit =
mars/lib/uhashring/*
mars/serialize/protos/*
mars/learn/contrib/xgboost/tracker.py
*.html
*.pxd
*/tests/*

Expand Down
24 changes: 14 additions & 10 deletions .github/workflows/ci.yml
Expand Up @@ -92,6 +92,15 @@ jobs:
fi
conda list
- name: Lint with flake8
shell: bash
run: |
source ./.github/workflows/reload-env.sh
# stop the build if there are Python syntax errors or undefined names
flake8 mars --count --select=E9,F63,E111,E901,E999,F7,F82,F401,F821,F822,F823,F841 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 mars --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Build cython extensions
env:
CYTHON_TRACE: ${{ matrix.cython-trace }}
Expand All @@ -108,15 +117,6 @@ jobs:
fi
python setup.py build_ext --force --inplace
- name: Lint with flake8
shell: bash
run: |
source ./.github/workflows/reload-env.sh
# stop the build if there are Python syntax errors or undefined names
flake8 mars --count --select=E9,F63,E111,E901,E999,F7,F82,F401,F821,F822,F823,F841 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 mars --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
env:
WITH_HDFS: ${{ matrix.with-hdfs }}
Expand Down Expand Up @@ -177,4 +177,8 @@ jobs:
export DEFAULT_VENV=$VIRTUAL_ENV
python .github/workflows/unify_coverage.py covdata/ "$(pwd)"
coverage combine covdata/
for i in $(seq 1 3); do coveralls && break || sleep 5; done;
for i in $(seq 1 3); do
ECODE=0; coveralls && break || sleep 5
ECODE=1
done
if [ "$ECODE" -ne "0" ]; then exit $ECODE; fi
14 changes: 8 additions & 6 deletions .github/workflows/run-tests.sh
Expand Up @@ -11,16 +11,18 @@ if [ -n "$WITH_KUBERNETES" ]; then
fi
if [ -z "$NO_COMMON_TESTS" ]; then
if [[ "$UNAME" == "mingw"* ]]; then
python -m pytest $PYTEST_CONFIG --ignore=mars/scheduler --ignore=mars/worker --timeout=1500
# python -m pytest $PYTEST_CONFIG --ignore=mars/scheduler --ignore=mars/worker --timeout=1500
pytest $PYTEST_CONFIG --cov-config .coveragerc mars/tests
coverage report
else
mkdir -p build
pytest $PYTEST_CONFIG --cov-config .coveragerc-threaded mars/tensor mars/dataframe mars/web mars/learn
mv .coverage build/.coverage.tensor.file
pytest $PYTEST_CONFIG --cov-config .coveragerc --forked --ignore mars/tensor --ignore mars/dataframe \
--ignore mars/learn mars
#pytest $PYTEST_CONFIG --cov-config .coveragerc-threaded mars/tensor mars/dataframe mars/web mars/learn
#mv .coverage build/.coverage.tensor.file
#pytest $PYTEST_CONFIG --cov-config .coveragerc --forked --ignore mars/tensor --ignore mars/dataframe \
pytest $PYTEST_CONFIG --cov-config .coveragerc mars/tests
# --ignore mars/learn mars
mv .coverage build/.coverage.main.file
coverage combine build/ && coverage report --fail-under=85
coverage combine build/ && coverage report # --fail-under=85

export DEFAULT_VENV=$VIRTUAL_ENV
source testenv/bin/activate
Expand Down
52 changes: 45 additions & 7 deletions .github/workflows/unify_coverage.py
Expand Up @@ -2,9 +2,47 @@
import glob
import os
import re
import sqlite3
import sys


def rewrite_path(txt, old_path, new_path):
txt = txt.replace('\\\\', '/').replace('\\', '/')
txt = re.sub('"([A-Za-z]):/', lambda m: '"/' + m.group(1).lower() + '/', txt)
txt = re.sub('^([A-Za-z]):/', lambda m: '/' + m.group(1).lower() + '/', txt)
txt = txt.replace(old_path, new_path)
return txt


def rewrite_json_coverage(file_name, old_path, new_path):
with open(file_name, 'r') as f:
cov_data = rewrite_path(f.read(), old_path, new_path)
with open(file_name, 'w') as f:
f.write(cov_data)


def rewrite_sqlite_coverage(file_name, old_path, new_path):
conn = None
try:
conn = sqlite3.connect(file_name)
cursor = conn.cursor()
cursor.execute('SELECT id, path FROM file')

updates = []
for file_id, file_path in cursor:
new_file_path = rewrite_path(file_path, old_path, new_path)
if file_path != new_file_path:
updates.append((new_file_path, file_id))

if updates:
cursor = conn.cursor()
cursor.executemany('UPDATE file SET path=? WHERE id=?', updates)
conn.commit()
finally:
if conn is not None:
conn.close()


def main(source_dir):
for fn in glob.glob('.pwd.*'):
cov_fn = fn.replace('.pwd', '.coverage')
Expand All @@ -14,15 +52,15 @@ def main(source_dir):
sys.stderr.write('Rewriting coverage file %s\n' % cov_fn)
with open(fn, 'r') as f:
env_pwd = f.read().strip()
with open(cov_fn, 'r') as f:
cov_data = f.read().replace(r'\\', '/')
env_pwd = re.sub('^/([A-Z])/', lambda m: '/' + m.group(1).lower() + '/', env_pwd)

env_pwd = re.sub('^/([A-Z])/', lambda m: '/' + m.group(1).lower() + '/', env_pwd)
cov_data = re.sub('"([A-Za-z]):/', lambda m: '"/' + m.group(1).lower() + '/', cov_data)
cov_data = cov_data.replace(env_pwd, source_dir)
with open(cov_fn, 'rb') as f:
header = f.read(6)

with open(cov_fn, 'w') as f:
f.write(cov_data)
if header == b'SQLite':
rewrite_sqlite_coverage(cov_fn, env_pwd, source_dir)
else:
rewrite_json_coverage(cov_fn, env_pwd, source_dir)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion mars/deploy/kubernetes/tests/Dockerfile.test
Expand Up @@ -2,7 +2,7 @@ ARG BASE_CONTAINER=marsproject/mars-base
FROM ${BASE_CONTAINER}

RUN /srv/retry.sh 3 /opt/conda/bin/conda install -c pkgs/main \
coverage \
coverage\>=5.0 cloudpickle \
&& conda clean --all -f -y

RUN apt-get -yq update \
Expand Down
5 changes: 1 addition & 4 deletions mars/deploy/kubernetes/tests/test_kubernetes.py
Expand Up @@ -55,15 +55,12 @@ def tearDown(self):

# rewrite paths in coverage result files
for fn in glob.glob(os.path.join(kube_coverage_path, '.coverage.*')):
with open(fn, 'rb') as f:
content = f.read()
if 'COVERAGE_FILE' in os.environ:
new_cov_file = os.environ['COVERAGE_FILE'] \
+ os.path.basename(fn).replace('.coverage', '')
else:
new_cov_file = fn.replace('.kube-coverage' + os.sep, '')
with open(new_cov_file, 'wb') as f:
f.write(content.replace(b'/mnt/mars', MARS_ROOT.encode()))
shutil.copyfile(fn, new_cov_file)
shutil.rmtree(kube_coverage_path)

@classmethod
Expand Down

0 comments on commit a8b20ec

Please sign in to comment.