def test_validate_dir(self): path = os.path.join(_TMPDIR, 'cmdstan-M.m.p') self.assertFalse(os.path.exists(path)) validate_dir(path) self.assertTrue(os.path.exists(path)) _, file = tempfile.mkstemp(dir=_TMPDIR) with self.assertRaisesRegex(Exception, 'File exists'): validate_dir(file) if platform.system() != 'Windows': with self.assertRaisesRegex(Exception, 'Cannot create directory'): dir = tempfile.mkdtemp(dir=_TMPDIR) os.chmod(dir, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) validate_dir(os.path.join(dir, 'cmdstan-M.m.p'))
def main(args: Dict[str, Any]) -> None: """Main.""" if platform.system() not in {'Windows'}: raise NotImplementedError('Download for the C++ toolchain ' 'on the current platform has not ' f'been implemented: {platform.system()}') toolchain = get_toolchain_name() version = args['version'] if version is None: version = latest_version() version = normalize_version(version) print("C++ toolchain '{}' version: {}".format(toolchain, version)) url = get_url(version) if 'verbose' in args: verbose = args['verbose'] install_dir = args['dir'] if install_dir is None: install_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN)) validate_dir(install_dir) print('Install directory: {}'.format(install_dir)) if 'progress' in args: progress = args['progress'] else: progress = False if platform.system() == 'Windows': silent = 'silent' in args # force silent == False for 4.0 version if 'silent' not in args and version in ('4.0', '4', '40'): silent = False else: silent = False toolchain_folder = get_toolchain_version(toolchain, version) with pushd(install_dir): if is_installed(toolchain_folder, version): print( 'C++ toolchain {} already installed'.format(toolchain_folder)) else: if os.path.exists(toolchain_folder): shutil.rmtree(toolchain_folder, ignore_errors=False) retrieve_toolchain(toolchain_folder + EXTENSION, url, progress=progress) install_version( toolchain_folder, toolchain_folder + EXTENSION, version, silent, verbose, ) if ('no-make' not in args and (platform.system() == 'Windows') and (version in ('4.0', '4', '40'))): if os.path.exists( os.path.join(toolchain_folder, 'mingw64', 'bin', 'mingw32-make.exe')): print('mingw32-make.exe already installed') else: install_mingw32_make(toolchain_folder, verbose)
def main(args: Dict[str, Any]) -> None: """Main.""" version = latest_version() if args['version']: version = args['version'] if is_version_available(version): print('Installing CmdStan version: {}'.format(version)) else: raise ValueError( 'Invalid version requested: {}, cannot install.'.format(version)) cmdstan_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN)) install_dir = cmdstan_dir if args['dir']: install_dir = args['dir'] validate_dir(install_dir) print('Install directory: {}'.format(install_dir)) if args['progress']: progress = args['progress'] else: progress = False if platform.system() == 'Windows' and args['compiler']: from .install_cxx_toolchain import is_installed as _is_installed_cxx from .install_cxx_toolchain import main as _main_cxx from .utils import cxx_toolchain_path cxx_loc = cmdstan_dir compiler_found = False rtools40_home = os.environ.get('RTOOLS40_HOME') for cxx_loc in ([rtools40_home] if rtools40_home is not None else []) + [ cmdstan_dir, os.path.join(os.path.abspath("/"), "RTools40"), os.path.join(os.path.abspath("/"), "RTools"), os.path.join(os.path.abspath("/"), "RTools35"), os.path.join(os.path.abspath("/"), "RBuildTools"), ]: for cxx_version in ['40', '35']: if _is_installed_cxx(cxx_loc, cxx_version): compiler_found = True break if compiler_found: break if not compiler_found: print('Installing RTools40') # copy argv and clear sys.argv cxx_args = {k: v for k, v in args.items() if k != 'compiler'} _main_cxx(cxx_args) cxx_version = '40' # Add toolchain to $PATH cxx_toolchain_path(cxx_version, args['dir']) cmdstan_version = f'cmdstan-{version}' with pushd(install_dir): if args['overwrite'] or not (os.path.exists(cmdstan_version) and os.path.exists( os.path.join( cmdstan_version, 'examples', 'bernoulli', 'bernoulli' + EXTENSION, ))): try: retrieve_version(version, progress) install_version( cmdstan_version=cmdstan_version, overwrite=args['overwrite'], verbose=args['verbose'], progress=progress, cores=args['cores'], ) except RuntimeError as e: print(e) sys.exit(3) else: print('CmdStan version {} already installed'.format(version))
def main(): """Main.""" if platform.system() not in {'Windows'}: msg = ('Download for the C++ toolchain' ' on the current platform has not been implemented: %s') raise NotImplementedError(msg % platform.system()) parser = argparse.ArgumentParser() parser.add_argument('--version', '-v') parser.add_argument('--dir', '-d') parser.add_argument('--silent', '-s', action='store_true') parser.add_argument('--no-make', '-m', action='store_false') args = parser.parse_args(sys.argv[1:]) toolchain = get_toolchain_name() version = vars(args)['version'] if version is None: version = latest_version() version = normalize_version(version) print("C++ toolchain '{}' version: {}".format(toolchain, version)) url = get_url(version) install_dir = vars(args)['dir'] if install_dir is None: cmdstan_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN)) if not os.path.exists(cmdstan_dir): cmdstanpy_dir = os.path.expanduser( os.path.join('~', _DOT_CMDSTANPY)) if os.path.exists(cmdstanpy_dir): cmdstan_dir = cmdstanpy_dir install_dir = cmdstan_dir validate_dir(install_dir) print('Install directory: {}'.format(install_dir)) if platform.system() == 'Windows': silent = 'silent' in vars(args) # force silent == False for 4.0 version if 'silent' not in vars(args) and version in ('4.0', '4', '40'): silent = False else: silent = False toolchain_folder = get_toolchain_version(toolchain, version) with pushd(install_dir): if is_installed(toolchain_folder, version): print( 'C++ toolchain {} already installed'.format(toolchain_folder)) else: if os.path.exists(toolchain_folder): shutil.rmtree(toolchain_folder, ignore_errors=False) retrieve_toolchain(toolchain_folder + EXTENSION, url) install_version(toolchain_folder, toolchain_folder + EXTENSION, version, silent) if ('no-make' not in vars(args) and (platform.system() == 'Windows') and (version in ('4.0', '4', '40'))): if os.path.exists( os.path.join(toolchain_folder, 'mingw64', 'bin', 'mingw32-make.exe')): print('mingw32-make.exe already installed') else: install_mingw32_make(toolchain_folder)
def main(): """Main.""" if platform.system() not in {'Windows'}: msg = ('Download for the C++ toolchain' ' on the current platform has not been implemented: %s') raise NotImplementedError(msg % platform.system()) parser = argparse.ArgumentParser() parser.add_argument('--version', '-v', help="version, defaults to latest") parser.add_argument('--dir', '-d', help="install directory, defaults to '~/.cmdstan(py)") parser.add_argument( '--silent', '-s', action='store_true', help="install with /VERYSILENT instead of /SILENT for RTools", ) parser.add_argument( '--no-make', '-m', action='store_false', help="don't install mingw32-make (Windows RTools 4.0 only)", ) parser.add_argument( '--verbose', action='store_true', help="flag, when specified prints output from RTools build process", ) parser.add_argument( '--progress', action='store_true', help="flag, when specified show progress bar for CmdStan download", ) args = parser.parse_args(sys.argv[1:]) toolchain = get_toolchain_name() version = vars(args)['version'] if version is None: version = latest_version() version = normalize_version(version) print("C++ toolchain '{}' version: {}".format(toolchain, version)) url = get_url(version) if 'verbose' in vars(args): verbose = vars(args)['verbose'] install_dir = vars(args)['dir'] if install_dir is None: cmdstan_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN)) if not os.path.exists(cmdstan_dir): cmdstanpy_dir = os.path.expanduser( os.path.join('~', _DOT_CMDSTANPY)) if os.path.exists(cmdstanpy_dir): cmdstan_dir = cmdstanpy_dir install_dir = cmdstan_dir validate_dir(install_dir) print('Install directory: {}'.format(install_dir)) if 'progress' in vars(args): progress = vars(args)['progress'] try: # pylint: disable=unused-import from tqdm import tqdm # noqa: F401 except (ImportError, ModuleNotFoundError): progress = False else: progress = False if platform.system() == 'Windows': silent = 'silent' in vars(args) # force silent == False for 4.0 version if 'silent' not in vars(args) and version in ('4.0', '4', '40'): silent = False else: silent = False toolchain_folder = get_toolchain_version(toolchain, version) with pushd(install_dir): if is_installed(toolchain_folder, version): print( 'C++ toolchain {} already installed'.format(toolchain_folder)) else: if os.path.exists(toolchain_folder): shutil.rmtree(toolchain_folder, ignore_errors=False) retrieve_toolchain(toolchain_folder + EXTENSION, url, progress=progress) install_version( toolchain_folder, toolchain_folder + EXTENSION, version, silent, verbose, ) if ('no-make' not in vars(args) and (platform.system() == 'Windows') and (version in ('4.0', '4', '40'))): if os.path.exists( os.path.join(toolchain_folder, 'mingw64', 'bin', 'mingw32-make.exe')): print('mingw32-make.exe already installed') else: install_mingw32_make(toolchain_folder, verbose)
def main(): """Main.""" parser = argparse.ArgumentParser() parser.add_argument('--version', '-v', help="version, defaults to latest release version") parser.add_argument( '--dir', '-d', help="install directory, defaults to '$HOME/.cmdstan(py)") parser.add_argument( '--overwrite', action='store_true', help="flag, when specified re-installs existing version", ) parser.add_argument( '--verbose', action='store_true', help="flag, when specified prints output from CmdStan build process", ) parser.add_argument( '--progress', action='store_true', help="flag, when specified show progress bar for CmdStan download", ) if platform.system() == 'Windows': # use compiler installed with install_cxx_toolchain # Install a new compiler if compiler not found # Search order is RTools40, RTools35 parser.add_argument( '--compiler', '-c', dest='compiler', action='store_true', help="flag, add C++ compiler to path (Windows only)", ) args = parser.parse_args(sys.argv[1:]) version = latest_version() if vars(args)['version']: version = vars(args)['version'] if is_version_available(version): print('Installing CmdStan version: {}'.format(version)) else: raise ValueError( 'Invalid version requested: {}, cannot install.'.format(version)) cmdstan_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN)) if not os.path.exists(cmdstan_dir): cmdstanpy_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTANPY)) if os.path.exists(cmdstanpy_dir): cmdstan_dir = cmdstanpy_dir install_dir = cmdstan_dir if vars(args)['dir']: install_dir = vars(args)['dir'] validate_dir(install_dir) print('Install directory: {}'.format(install_dir)) if vars(args)['progress']: progress = vars(args)['progress'] try: # pylint: disable=unused-import from tqdm import tqdm # noqa: F401 except (ImportError, ModuleNotFoundError): progress = False else: progress = False if platform.system() == 'Windows' and vars(args)['compiler']: from .install_cxx_toolchain import is_installed as _is_installed_cxx from .install_cxx_toolchain import main as _main_cxx from .utils import cxx_toolchain_path cxx_loc = cmdstan_dir compiler_found = False rtools40_home = os.environ.get('RTOOLS40_HOME') for cxx_loc in ([rtools40_home] if rtools40_home is not None else []) + [ cmdstan_dir, os.path.join(os.path.abspath("/"), "RTools40"), os.path.join(os.path.abspath("/"), "RTools"), os.path.join(os.path.abspath("/"), "RTools35"), os.path.join(os.path.abspath("/"), "RBuildTools"), ]: for cxx_version in ['40', '35']: if _is_installed_cxx(cxx_loc, cxx_version): compiler_found = True break if compiler_found: break if not compiler_found: print('Installing RTools40') # copy argv and clear sys.argv original_argv = sys.argv[:] sys.argv = [ item for item in sys.argv if item not in ("--compiler", "-c") ] _main_cxx() sys.argv = original_argv cxx_version = '40' # Add toolchain to $PATH cxx_toolchain_path(cxx_version) cmdstan_version = 'cmdstan-{}'.format(version) with pushd(install_dir): if vars(args)['overwrite'] or not (os.path.exists(cmdstan_version) and os.path.exists( os.path.join( cmdstan_version, 'examples', 'bernoulli', 'bernoulli' + EXTENSION, ))): try: retrieve_version(version, progress) install_version( cmdstan_version=cmdstan_version, overwrite=vars(args)['overwrite'], verbose=vars(args)['verbose'], ) except RuntimeError as e: print(e) sys.exit(3) else: print('CmdStan version {} already installed'.format(version))
def main(): """Main.""" parser = argparse.ArgumentParser() parser.add_argument('--version', '-v') parser.add_argument('--dir', '-d') parser.add_argument('--overwrite', action='store_true') parser.add_argument('--verbose', action='store_true') if platform.system() == 'Windows': # use compiler installed with install_cxx_toolchain # Install a new compiler if compiler not found # Search order is RTools40, RTools35 parser.add_argument('--compiler', '-c', dest='compiler', action='store_true') args = parser.parse_args(sys.argv[1:]) version = latest_version() if vars(args)['version']: version = vars(args)['version'] if is_version_available(version): print('Installing CmdStan version: {}'.format(version)) else: raise ValueError( 'Invalid version requested: {}, cannot install.'.format(version)) cmdstan_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN)) if not os.path.exists(cmdstan_dir): cmdstanpy_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTANPY)) if os.path.exists(cmdstanpy_dir): cmdstan_dir = cmdstanpy_dir install_dir = cmdstan_dir if vars(args)['dir']: install_dir = vars(args)['dir'] validate_dir(install_dir) print('Install directory: {}'.format(install_dir)) if platform.system() == 'Windows' and vars(args)['compiler']: from .install_cxx_toolchain import ( main as _main_cxx, is_installed as _is_installed_cxx, ) from .utils import cxx_toolchain_path cxx_loc = cmdstan_dir compiler_found = False for cxx_version in ['40', '35']: if _is_installed_cxx(cxx_loc, cxx_version): compiler_found = True break if not compiler_found: print('Installing RTools40') # copy argv and clear sys.argv original_argv = sys.argv[:] sys.argv = sys.argv[:1] _main_cxx() sys.argv = original_argv cxx_version = '40' # Add toolchain to $PATH cxx_toolchain_path(cxx_version) cmdstan_version = 'cmdstan-{}'.format(version) with pushd(install_dir): if vars(args)['overwrite'] or not (os.path.exists(cmdstan_version) and os.path.exists( os.path.join( cmdstan_version, 'examples', 'bernoulli', 'bernoulli' + EXTENSION, ))): try: retrieve_version(version) install_version( cmdstan_version=cmdstan_version, overwrite=vars(args)['overwrite'], verbose=vars(args)['verbose'], ) except RuntimeError as e: print(e) sys.exit(3) else: print('CmdStan version {} already installed'.format(version))