Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
snakedeploy.egg-info/
_build
build
.eggs/
__pycache__
dist
Expand Down
66 changes: 66 additions & 0 deletions snakedeploy/deploy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
import tempfile
from pathlib import Path
import os
Expand Down Expand Up @@ -42,6 +43,10 @@ def snakefile(self):
@property
def config(self):
return self.dest_path / "config"

@property
def profile(self):
return self.dest_path / "profile"

def deploy_config(self):
"""
Expand Down Expand Up @@ -70,6 +75,56 @@ def deploy_config(self):
shutil.copytree(config_dir, self.config, dirs_exist_ok=self.force)
return no_config

def deploy_profile(self):
"""
Deploy the profile directory if it exists

returns a boolean "no_profile" to indicate if there is not a profile (True)
"""
# Handle the profile/
profile_dir = Path(self.repo_clone) / "profile"
no_profile = not profile_dir.exists()
if no_profile:
logger.warning(
"No profile directory found in source repository. "
"Please check whether the source repository really does not "
"need or provide any profiles."
)
else:
logger.info("Writing template profiles")
shutil.copytree(profile_dir, self.profile, dirs_exist_ok=self.force)
return no_profile

def deploy_license(self):
"""
Deploy the license file if it exists

returns a boolean "no_license" to indicate if there is no license (True)
"""
# List possible license file names and extensions
license_variants = ["license*", "License*", "LICENSE*", "licence*", "Licence*", "LICENCE*"]
licenses = [] # licenses found

# Iterate over the variants and check if a license file exists in the directory
for variant in license_variants:
# Use glob to match files with any extension
matching_files = glob.glob(os.path.join(self.repo_clone, variant))
if matching_files:
licenses.extend(matching_files)

license_file = Path(licenses[0]) if len(licenses) != 0 else None
if license_file is None:
no_license = True
else:
no_license = not license_file.exists()

if no_license:
pass
else:
logger.info("Writing license")
shutil.copy(license_file, self.dest_path)
return no_license

@property
def repo_clone(self):
if self._cloned is None:
Expand All @@ -92,6 +147,12 @@ def deploy(self, name: str):
# Either copy existing config or create a dummy config
no_config = self.deploy_config()

# Copy profile directory if it exists, see issue #64
no_profile = self.deploy_profile()

# Copy license if it exists
no_license = self.deploy_license()

# Inspect repository to find existing snakefile
self.deploy_snakefile(self.repo_clone, name)

Expand All @@ -114,6 +175,11 @@ def check(self):
raise UserError(
f"{self.config} already exists, aborting (use --force to overwrite)"
)

if self.profile.exists() and not self.force:
raise UserError(
f"{self.profile} already exists, aborting (use --force to overwrite)"
)

def deploy_snakefile(self, tmpdir: str, name: str):
"""
Expand Down
Loading