Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optional deployment of schemas #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion snakedeploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ def deploy_config(self):
shutil.copytree(config_dir, self.config, dirs_exist_ok=self.force)
return no_config

def deploy_schemas(self):
"""
Deploy the schemas directory.
"""
schema_dir = Path(self.repo_clone) / "workflow" / "schemas"
dest_dir = self.dest_path / "workflow" / "schemas"
if not schema_dir.exists():
logger.warning("No schemas directory found...")
else:
logger.info("Writing schemas...")
shutil.copytree(
schema_dir,
dest_dir,
)

Comment on lines +73 to +87
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling and maintain consistency with other deploy methods

The deploy_schemas implementation needs improvements in error handling and consistency:

  1. Missing error handling for shutil.copytree
  2. Inconsistent with other deploy methods - missing dirs_exist_ok parameter
  3. Warning message could be more informative

Here's the suggested fix:

    def deploy_schemas(self):
        """
        Deploy the schemas directory.
        """
        schema_dir = Path(self.repo_clone) / "workflow" / "schemas"
        dest_dir = self.dest_path / "workflow" / "schemas"
        if not schema_dir.exists():
-           logger.warning("No schemas directory found...")
+           logger.warning(
+               "No schemas directory found in source repository. "
+               "This might be expected if the workflow doesn't use schema validation."
+           )
        else:
            logger.info("Writing schemas...")
+           try:
                shutil.copytree(
                    schema_dir,
                    dest_dir,
+                   dirs_exist_ok=self.force
                )
+           except OSError as e:
+               raise UserError(f"Failed to copy schemas: {e}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def deploy_schemas(self):
"""
Deploy the schemas directory.
"""
schema_dir = Path(self.repo_clone) / "workflow" / "schemas"
dest_dir = self.dest_path / "workflow" / "schemas"
if not schema_dir.exists():
logger.warning("No schemas directory found...")
else:
logger.info("Writing schemas...")
shutil.copytree(
schema_dir,
dest_dir,
)
def deploy_schemas(self):
"""
Deploy the schemas directory.
"""
schema_dir = Path(self.repo_clone) / "workflow" / "schemas"
dest_dir = self.dest_path / "workflow" / "schemas"
if not schema_dir.exists():
logger.warning(
"No schemas directory found in source repository. "
"This might be expected if the workflow doesn't use schema validation."
)
else:
logger.info("Writing schemas...")
try:
shutil.copytree(
schema_dir,
dest_dir,
dirs_exist_ok=self.force
)
except OSError as e:
raise UserError(f"Failed to copy schemas: {e}")

@property
def repo_clone(self):
if self._cloned is None:
Expand All @@ -83,7 +98,7 @@ def repo_clone(self):

return self._cloned.name

def deploy(self, name: str):
def deploy(self, name: str, schemas: bool = False):
"""
Deploy a source to a destination.
"""
Expand All @@ -95,6 +110,9 @@ def deploy(self, name: str):
# Inspect repository to find existing snakefile
self.deploy_snakefile(self.repo_clone, name)

if schemas:
self.deploy_schemas()

logger.info(
self.env.get_template("post-instructions.txt.jinja").render(
no_config=no_config, dest_path=self.dest_path
Expand Down