diff --git a/nf_core/create.py b/nf_core/create.py index 6f23c99478..2492169486 100644 --- a/nf_core/create.py +++ b/nf_core/create.py @@ -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__ @@ -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()