xgboost/tests/ci_build/test_r_package.py
Jiaming Yuan 8bdea72688
[Python] Require black and isort for new Python files. (#8096)
* [Python] Require black and isort for new Python files.

- Require black and isort for spark and dask module.

These files are relatively new and are more conform to the black formatter. We will
convert the rest of the library as we move forward.

Other libraries including dask/distributed and optuna use the same formatting style and
have a more strict standard. The black formatter is indeed quite nice, automating it can
help us unify the code style.

- Gather Python checks into a single script.
2022-07-20 10:25:24 +08:00

92 lines
3.0 KiB
Python

import argparse
import os
import subprocess
from test_utils import DirectoryExcursion
ROOT = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.pardir,
os.path.pardir))
r_package = os.path.join(ROOT, 'R-package')
def get_mingw_bin():
return os.path.join('c:/rtools40/mingw64/', 'bin')
def test_with_autotools(args):
with DirectoryExcursion(r_package):
mingw_bin = get_mingw_bin()
CXX = os.path.join(mingw_bin, 'g++.exe')
CC = os.path.join(mingw_bin, 'gcc.exe')
cmd = ['R.exe', 'CMD', 'INSTALL', str(os.path.curdir)]
env = os.environ.copy()
env.update({'CC': CC, 'CXX': CXX})
subprocess.check_call(cmd, env=env)
subprocess.check_call([
'R.exe', '-q', '-e',
"library(testthat); setwd('tests'); source('testthat.R')"
])
subprocess.check_call([
'R.exe', '-q', '-e',
"demo(runall, package = 'xgboost')"
])
def test_with_cmake(args):
os.mkdir('build')
with DirectoryExcursion('build'):
if args.compiler == 'mingw':
mingw_bin = get_mingw_bin()
CXX = os.path.join(mingw_bin, 'g++.exe')
CC = os.path.join(mingw_bin, 'gcc.exe')
env = os.environ.copy()
env.update({'CC': CC, 'CXX': CXX})
subprocess.check_call([
'cmake', os.path.pardir, '-DUSE_OPENMP=ON', '-DR_LIB=ON',
'-DCMAKE_CONFIGURATION_TYPES=Release', '-G', 'Unix Makefiles',
],
env=env)
subprocess.check_call(['make', '-j', 'install'])
elif args.compiler == 'msvc':
subprocess.check_call([
'cmake', os.path.pardir, '-DUSE_OPENMP=ON', '-DR_LIB=ON',
'-DCMAKE_CONFIGURATION_TYPES=Release', '-A', 'x64'
])
subprocess.check_call([
'cmake', '--build', os.path.curdir, '--target', 'install',
'--config', 'Release'
])
else:
raise ValueError('Wrong compiler')
with DirectoryExcursion(r_package):
subprocess.check_call([
'R.exe', '-q', '-e',
"library(testthat); setwd('tests'); source('testthat.R')"
])
subprocess.check_call([
'R.exe', '-q', '-e',
"demo(runall, package = 'xgboost')"
])
def main(args):
if args.build_tool == 'autotools':
test_with_autotools(args)
else:
test_with_cmake(args)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--compiler',
type=str,
choices=['mingw', 'msvc'],
help='Compiler used for compiling CXX code.')
parser.add_argument(
'--build-tool',
type=str,
choices=['cmake', 'autotools'],
help='Build tool for compiling CXX code and install R package.')
args = parser.parse_args()
main(args)