Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
41 changes: 26 additions & 15 deletions nf_core/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def render_template(self):
loader=jinja2.PackageLoader("nf_core", "pipeline-template"), keep_trailing_newline=True
)
template_dir = os.path.join(os.path.dirname(__file__), "pipeline-template")
binary_ftypes = ["image", "application/java-archive"]
binary_ftypes = ["image", "application/java-archive", "application/x-java-archive"]
binary_extensions = [".jpeg", ".jpg", ".png", ".zip", ".gz", ".jar", ".tar"]
object_attrs = vars(self)
object_attrs["nf_core_version"] = nf_core.__version__

Expand All @@ -106,23 +107,33 @@ def render_template(self):
output_path = os.path.join(self.outdir, template_fn)
os.makedirs(os.path.dirname(output_path), exist_ok=True)

# Just copy binary files
(ftype, encoding) = mimetypes.guess_type(template_fn_path)
if encoding is not None or (ftype is not None and any([ftype.startswith(ft) for ft in binary_ftypes])):
log.debug(f"Copying binary file: '{output_path}'")
try:
# Just copy certain file extensions
filename, file_extension = os.path.splitext(template_fn_path)
if file_extension in binary_extensions:
raise AttributeError(f"File extension: {file_extension}")

# Try to detect binary files
(ftype, encoding) = mimetypes.guess_type(template_fn_path, strict=False)
if encoding is not None or (ftype is not None and any([ftype.startswith(ft) for ft in binary_ftypes])):
raise AttributeError(f"Encoding: {encoding}")

# Got this far - render the template
log.debug(f"Rendering template file: '{template_fn}'")
j_template = env.get_template(template_fn)
rendered_output = j_template.render(object_attrs)

# Write to the pipeline output file
with open(output_path, "w") as fh:
log.debug(f"Writing to output file: '{output_path}'")
fh.write(rendered_output)

# Copy the file directly instead of using Jinja
except (AttributeError, UnicodeDecodeError) as e:
log.debug(f"Copying file without Jinja: '{output_path}' - {e}")
shutil.copy(template_fn_path, output_path)
continue

# Render the template
log.debug(f"Rendering template file: '{template_fn}'")
j_template = env.get_template(template_fn)
rendered_output = j_template.render(object_attrs)

# Write to the pipeline output file
with open(output_path, "w") as fh:
log.debug(f"Writing to output file: '{output_path}'")
fh.write(rendered_output)

# Make a logo and save it
self.make_pipeline_logo()

Expand Down