Skip to content

Commit

Permalink
fixed test case and broken imports
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester committed Jul 23, 2023
1 parent ea01eb8 commit df72b36
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 18 deletions.
2 changes: 2 additions & 0 deletions snakemake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
__copyright__ = "Copyright 2023, Johannes Köster"
__email__ = "johannes.koester@protonmail.com"
__license__ = "MIT"

from snakemake.common import __version__
2 changes: 1 addition & 1 deletion snakemake/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This script makes it possible to invoke snakemake with 'python3 -m snakemake'
from snakemake import main
from snakemake.cli import main

main()
5 changes: 3 additions & 2 deletions snakemake/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@

import sys

from snakemake.common import MIN_PY_VERSION

if sys.version_info < MIN_PY_VERSION:
raise ValueError(f"Snakemake requires at least Python {'.'.join(MIN_PY_VERSION)}.")

import os
from functools import partial
import importlib

from snakemake_interface_executor_plugins.utils import url_can_parse, ExecMode
from snakemake_interface_executor_plugins.utils import ExecMode

from snakemake.target_jobs import parse_target_jobs_cli_args
from snakemake.workflow import Workflow
from snakemake.exceptions import (
print_exception,
Expand Down
5 changes: 4 additions & 1 deletion snakemake/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from snakemake.logging import logger
from inspect import isfunction, ismethod
from snakemake.common import DYNAMIC_FILL, ON_WINDOWS, async_run
from snakemake_interface_executor_plugins.utils import not_iterable


class Mtime:
Expand Down Expand Up @@ -1005,6 +1004,8 @@ def new_from(self, new_value):


def flag(value, flag_type, flag_value=True):
from snakemake_interface_executor_plugins.utils import not_iterable

if isinstance(value, AnnotatedString):
value.flags[flag_type] = flag_value
return value
Expand Down Expand Up @@ -1099,6 +1100,8 @@ def dynamic(value):
A flag for a file that shall be dynamic, i.e. the multiplicity
(and wildcard values) will be expanded after a certain
rule has been run"""
from snakemake_interface_executor_plugins.utils import not_iterable

annotated = flag(value, "dynamic", True)
tocheck = [annotated] if not_iterable(annotated) else annotated
for file in tocheck:
Expand Down
19 changes: 11 additions & 8 deletions snakemake/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,33 +543,36 @@ def generate_preamble(
# Obtain search path for current snakemake module.
# The module is needed for unpickling in the script.
# We append it at the end (as a fallback).
searchpath = SNAKEMAKE_SEARCHPATH
snakemake_searchpath = SNAKEMAKE_SEARCHPATH
if container_img is not None:
searchpath = singularity.SNAKEMAKE_MOUNTPOINT
searchpath = repr(searchpath)
snakemake_searchpath = singularity.SNAKEMAKE_MOUNTPOINT
searchpaths = [snakemake_searchpath] + [
path for path in sys.path if path.endswith("site-packages")
]

# Add the cache path to the search path so that other cached source files in the same dir
# can be imported.
if cache_path:
cache_searchpath = os.path.dirname(cache_path)
if cache_searchpath:
searchpath += ", " + repr(cache_searchpath)
searchpaths.append(cache_searchpath)
# For local scripts, add their location to the path in case they use path-based imports
if is_local:
searchpath += ", " + repr(path.get_basedir().get_path_or_uri())
searchpaths.append(path.get_basedir().get_path_or_uri())

return textwrap.dedent(
preamble = textwrap.dedent(
"""
######## snakemake preamble start (automatically inserted, do not edit) ########
import sys; sys.path.extend([{searchpath}]); import pickle; snakemake = pickle.loads({snakemake}); from snakemake.logging import logger; logger.printshellcmds = {printshellcmds}; {preamble_addendum}
import sys; sys.path.extend({searchpaths}); import pickle; snakemake = pickle.loads({snakemake}); from snakemake.logging import logger; logger.printshellcmds = {printshellcmds}; {preamble_addendum}
######## snakemake preamble end #########
"""
).format(
searchpath=searchpath,
searchpaths=repr(searchpaths),
snakemake=snakemake,
printshellcmds=logger.printshellcmds,
preamble_addendum=preamble_addendum,
)
return preamble

def get_preamble(self):
if isinstance(self.path, LocalSourceFile):
Expand Down
6 changes: 5 additions & 1 deletion snakemake/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
NoRulesException,
WorkflowError,
)
from snakemake.shell import shell
from snakemake.dag import DAG
from snakemake.scheduler import JobScheduler
from snakemake.parser import parse
Expand Down Expand Up @@ -249,6 +248,9 @@ def __init__(
self._quiet = quiet

_globals = globals()
from snakemake.shell import shell

_globals["shell"] = shell
_globals["workflow"] = self
_globals["rules"] = Rules()
_globals["checkpoints"] = Checkpoints()
Expand Down Expand Up @@ -1164,6 +1166,8 @@ def files(items):

if not dryrun:
if len(dag):
from snakemake.shell import shell

shell_exec = shell.get_executable()
if shell_exec is not None:
logger.info(f"Using shell: {shell_exec}")
Expand Down
2 changes: 1 addition & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import subprocess
import tarfile

from snakemake import snakemake
from snakemake.api import snakemake
from snakemake.shell import shell
from snakemake.common import ON_WINDOWS
from snakemake.resources import DefaultResources, GroupResources, ResourceScopes
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from snakemake.common import ON_WINDOWS
from snakemake.utils import find_bash_on_windows
from snakemake import shell
from snakemake.shell import shell

skip_on_windows = pytest.mark.skipif(ON_WINDOWS, reason="Unix stuff")
only_on_windows = pytest.mark.skipif(not ON_WINDOWS, reason="Windows stuff")
Expand Down
2 changes: 1 addition & 1 deletion tests/test14/Snakefile.nonstandard
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from snakemake import shell
from snakemake.shell import shell

chromosomes = [1, 2, 3, 4, 5]

Expand Down
2 changes: 1 addition & 1 deletion tests/testapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Tests for Snakemake’s API
"""
from snakemake import snakemake
from snakemake.api import snakemake
import asyncio
import sys
import tempfile
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import subprocess as sp
from pathlib import Path

from snakemake import parse_cores_jobs
from snakemake.cli import parse_cores_jobs
from snakemake.exceptions import CliException
from snakemake.utils import available_cpu_count

Expand Down

0 comments on commit df72b36

Please sign in to comment.