diff --git a/python/setup.py b/python/setup.py index 524ecf3..7e999e6 100644 --- a/python/setup.py +++ b/python/setup.py @@ -68,6 +68,7 @@ def clean_all_cmdstan(verbose: bool = False) -> None: msgs.append(stderr.decode("utf-8").strip()) raise RuntimeError("\n".join(msgs)) + # TODO: Remove when upgrading to cmdstanpy 1.0, use cmdstanpy internals instead def build_cmdstan(verbose: bool = False) -> None: """Run `make build` in the current directory (must be a cmdstan library). @@ -103,6 +104,7 @@ def build_cmdstan(verbose: bool = False) -> None: list(OrderedDict.fromkeys([libtbb] + os.environ.get("PATH", "").split(";"))) ) + def prune_cmdstan(cmdstan_dir: str) -> None: """ Keep only the cmdstan executables and tbb files (minimum required to run a cmdstanpy commands on a pre-compiled model). @@ -126,19 +128,24 @@ def prune_cmdstan(cmdstan_dir: str) -> None: rmtree(original_dir) temp_dir.rename(original_dir) + def get_cmdstan_cache() -> str: """Default directory for an existing cmdstan library. Prevents unnecessary re-downloads of cmdstan.""" return Path.home().resolve() / ".cmdstan" / f"cmdstan-{CMDSTAN_VERSION}" + def download_cmdstan(cache_dir: Path) -> None: """Ensure the cmdstan library exists in the cache directory.""" import cmdstanpy - if os.path.isdir(cache_dir): + + if cache_dir.is_dir(): print(f"Found existing cmdstan library at {cache_dir}") else: + cache_dir.parent.mkdir(parents=True, exist_ok=True) with cmdstanpy.utils.pushd(cache_dir.parent): cmdstanpy.utils.retrieve_version(version=CMDSTAN_VERSION, progress=False) + def build_cmdstan_model(target_dir): """ Rebuild cmdstan in the build environment, then use this installation to compile the stan model. @@ -173,6 +180,7 @@ def build_cmdstan_model(target_dir): os.remove(f) prune_cmdstan(cmdstan_dir) + def build_pystan_model(target_dir): """ Compile the stan model using pystan and pickle it. The pickle is copied to {target_dir}/prophet_model.pkl. @@ -187,9 +195,11 @@ def build_pystan_model(target_dir): with open(os.path.join(target_dir, target_name), "wb") as f: pickle.dump(sm, f, protocol=pickle.HIGHEST_PROTOCOL) + def get_backends_from_env() -> List[str]: return os.environ.get("STAN_BACKEND", "PYSTAN").split(",") + def build_models(target_dir): for backend in get_backends_from_env(): print(f"Compiling {backend} model") @@ -314,10 +324,10 @@ setup( }, test_suite="prophet.tests", classifiers=[ - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", ], long_description=long_description, long_description_content_type="text/markdown",