snakemake / snakemake-github-action

A Github action for running a Snakemake workflow
MIT License
51 stars 12 forks source link

Containerize Fails with Conda Envs #17

Closed mfansler closed 2 years ago

mfansler commented 2 years ago

The containerize task does not work when Conda environments are specified. I put together a demonstration repository. Error has to do with os.fspath not recognizing the type (LocalSourceFile) of the Conda environment file.

My local Snakemake v6.8 (Python 3.9.7, CentOS 7) works just fine.


Reproducible Example

Snakefile

rule all:
  input: "python-version.txt"

rule py_emit_version:
  output: "python-version.txt"
  conda: "envs/py39.yaml"
  shell:
    """
    python -VV > {output}
    """

envs/py39.yaml

name: py39
channels:
  - conda-forge
  - nodefaults
dependencies:
  - python=3.9

.github/workflows/snakemake-containerize.yaml

name: Snakemake Containerize

on:
  workflow_dispatch:

jobs:
  Snakemake:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Snakemake dry run
        uses: snakemake/snakemake-github-action@v1.23.0
        with:
          directory: '.'
          args: '-np'

      - name: Create container file
        uses: snakemake/snakemake-github-action@v1.23.0
        with:
          directory: '.'
          task: 'containerize'

      - name: Print Dockerfile
        run: |
          cat Dockerfile

Error

Traceback (most recent call last):
  File "/opt/conda/envs/snakemake/lib/python3.9/site-packages/snakemake/__init__.py", line 602, in snakemake
    workflow.containerize()
  File "/opt/conda/envs/snakemake/lib/python3.9/site-packages/snakemake/workflow.py", line 1142, in containerize
    containerize(self)
  File "/opt/conda/envs/snakemake/lib/python3.9/site-packages/snakemake/deployment/containerize.py", line 27, in containerize
    envs = sorted(
  File "/opt/conda/envs/snakemake/lib/python3.9/site-packages/snakemake/deployment/containerize.py", line 25, in <lambda>
    relfile = lambda env: os.path.relpath(env.file, os.getcwd())
  File "/opt/conda/envs/snakemake/lib/python3.9/posixpath.py", line 456, in relpath
    path = os.fspath(path)

TypeError: expected str, bytes or os.PathLike object, not LocalSourceFile
mfansler commented 2 years ago

This is fixed with Snakemake release v6.11.0.