diff --git a/pyproject.toml b/pyproject.toml index 91f1dfe..c9856c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ license = "MIT" packages = [ {include = "scope"}, ] -include = ["config.defaults.yaml"] +include = ["config.defaults.yaml", "tools/golden_dataset_mapper.json"] [tool.poetry.dependencies] python = "^3.9, <3.12" @@ -56,6 +56,7 @@ tables = ">=3.7,<3.9.2" pre-commit = ">=3.5.0" [tool.poetry.scripts] +scope-initialize = "scope.scope_class:Scope.initialize" scope-develop = "scope._instantiate:develop" scope-lint = "scope.scope_class:Scope.lint" scope-doc = "scope._instantiate:doc" diff --git a/scope/scope_class.py b/scope/scope_class.py index e2f9cbf..317b95c 100755 --- a/scope/scope_class.py +++ b/scope/scope_class.py @@ -26,6 +26,7 @@ import json import shutil import argparse +import site @contextmanager @@ -563,6 +564,41 @@ def fetch_datasets(gcs_path: str = "gs://ztf-scope/datasets"): if p.returncode != 0: raise RuntimeError("Failed to fetch SCoPe datasets") + @staticmethod + def initialize(): + main_dir = "scope-ml" + scope_dirs = ["tools"] + os.makedirs(main_dir, exist_ok=True) + for directory in scope_dirs: + os.makedirs(f"{main_dir}/{directory}", exist_ok=True) + + site_packages_path = site.getsitepackages()[0] + default_config_name = "config.defaults.yaml" + copied_config_name = "config.yaml" + tools_dir = "tools" + mappers = ["golden_dataset_mapper.json"] + + # Copy config defaults to new directory strucutre if needed + if not os.path.exists(f"{main_dir}/{copied_config_name}"): + shutil.copy( + f"{site_packages_path}/{default_config_name}", + f"{main_dir}/{copied_config_name}", + ) + print( + f"Created new '{copied_config_name}' config file. Please customize/add tokens there before running scope." + ) + else: + print(f"{copied_config_name} already exists in the '{main_dir}' directory.") + + for mapper in mappers: + print(f"Copying dataset mapper '{mapper}'") + shutil.copy( + f"{site_packages_path}/{tools_dir}/{mapper}", + {main_dir} / {tools_dir} / {mapper}, + ) + + print(f"scope-ml initialized. Run scripts from '{main_dir}' directory.") + def parse_run_train(self): parser = argparse.ArgumentParser() parser.add_argument(