gurudesh/pytracebugs huggingface dataset:
# Buggy code
def dec(f):
    ref = f.__module__ + "." + f.__qualname__
    if ref in _FUNCS:
        raise ConfigError(f'duplicate validator function "{ref}"')
    _FUNCS.add(ref)
    f_cls = classmethod(f)
    f_cls.__validator_config = fields, Validator(f, pre, whole, always, check_fields)
    return f_cls


# Traceback (ConfigError)
Config ip=IPv4Address('123.0.0.200') name='asdf' port=2392
when the cell is called first and raises

ConfigError Traceback (most recent call last)
in ()
3 from ipaddress import ip_address
4
----> 5 class Config(BaseModel):
6 ip: str
7 name: str

in Config()
8 port: int
9
---> 10 @validator("ip")
11 def check_ip(cls, value):
12 return ip_address(value)

~/anaconda3/lib/python3.7/site-packages/pydantic/main.py in dec(f)
449 ref = f.module + '.' + f.qualname
450 if ref in _FUNCS:
--> 451 raise ConfigError(f'duplicate validator function "{ref}"')
452 _FUNCS.add(ref)
453 f_cls = classmethod(f)

ConfigError: duplicate validator function "main.Config.check_ip"

# Fixed code
def dec(f):
    # avoid validators with duplicated names since without this validators can be overwritten silently
    # which generally isn't the intended behaviour, don't run in ipython - see #312
    if not in_ipython():  # pragma: no branch
        ref = f.__module__ + "." + f.__qualname__
        if ref in _FUNCS:
            raise ConfigError(f'duplicate validator function "{ref}"')
        _FUNCS.add(ref)
    f_cls = classmethod(f)
    f_cls.__validator_config = fields, Validator(f, pre, whole, always, check_fields)
    return f_cls
# Buggy code
def _substitute_environ(self):
    """
    Substitute environment variables into values.
    """
    d = {}
    for field in self.__fields__.values():
        if field.alt_alias:
            env_name = field.alias
        else:
            env_name = self.__config__.env_prefix + field.name.upper()
        env_var = os.getenv(env_name, None)
        if env_var:
            if _complex_field(field):
                try:
                    env_var = json.loads(env_var)
                except ValueError as e:
                    raise SettingsError(f'error parsing JSON for "{env_name}"') from e
            d[field.alias] = env_var
    return d


# Traceback (pydantic.error_wrappers.ValidationError)
❯ export test=foobar; pipenv run python
Python 3.6.1 (default, Aug  1 2018, 10:30:03)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import os
import pydantic
class S(pydantic.BaseSettings):
...   test:str
...   class Config:
...     fields = dict(test=dict(alias="test"))
...
S()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jasonkuhrt/.local/share/virtualenvs/waldo-QOik3jd4/lib/python3.6/site-packages/pydantic/env_settings.py", line 35, in __init__
super().__init__(**values)
File "/Users/jasonkuhrt/.local/share/virtualenvs/waldo-QOik3jd4/lib/python3.6/site-packages/pydantic/main.py", line 166, in __init__
self.__setstate__(self._process_values(data))
File "/Users/jasonkuhrt/.local/share/virtualenvs/waldo-QOik3jd4/lib/python3.6/site-packages/pydantic/main.py", line 331, in _process_values
return validate_model(self, input_data)
File "/Users/jasonkuhrt/.local/share/virtualenvs/waldo-QOik3jd4/lib/python3.6/site-packages/pydantic/main.py", line 507, in validate_model
raise ValidationError(errors)
pydantic.error_wrappers.ValidationError: 1 validation error
test
none is not an allow value (type=type_error.none.not_allowed)
os.getenv('test')
'foobar'

# Fixed code
def _substitute_environ(self):
    """
    Substitute environment variables into values.
    """
    d = {}
    for field in self.__fields__.values():
        if field.has_alias:
            env_name = field.alias
        else:
            env_name = self.__config__.env_prefix + field.name.upper()
        env_var = os.getenv(env_name, None)
        if env_var:
            if _complex_field(field):
                try:
                    env_var = json.loads(env_var)
                except ValueError as e:
                    raise SettingsError(f'error parsing JSON for "{env_name}"') from e
            d[field.alias] = env_var
    return d
# Buggy code
def __init__(
    self,
    *,
    name: str,
    type_: Type,
    class_validators: List[Validator],
    default: Any,
    required: bool,
    model_config: Any,
    alias: str = None,
    allow_none: bool = False,
    schema: Schema = None,
):
    self.name: str = name
    self.alias: str = alias or name
    self.type_: type = type_
    self.class_validators = class_validators or []
    self.validate_always: bool = False
    self.sub_fields: List[Field] = None
    self.key_field: Field = None
    self.validators = []
    self.whole_pre_validators = None
    self.whole_post_validators = None
    self.default: Any = default
    self.required: bool = required
    self.model_config = model_config
    self.allow_none: bool = allow_none
    self.parse_json: bool = False
    self.shape: Shape = Shape.SINGLETON
    self._schema: Schema = schema
    self.prepare()


# Traceback (pydantic.error_wrappers.ValidationError)
❯ export test=foobar; pipenv run python
Python 3.6.1 (default, Aug  1 2018, 10:30:03)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import os
import pydantic
class S(pydantic.BaseSettings):
...   test:str
...   class Config:
...     fields = dict(test=dict(alias="test"))
...
S()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jasonkuhrt/.local/share/virtualenvs/waldo-QOik3jd4/lib/python3.6/site-packages/pydantic/env_settings.py", line 35, in __init__
super().__init__(**values)
File "/Users/jasonkuhrt/.local/share/virtualenvs/waldo-QOik3jd4/lib/python3.6/site-packages/pydantic/main.py", line 166, in __init__
self.__setstate__(self._process_values(data))
File "/Users/jasonkuhrt/.local/share/virtualenvs/waldo-QOik3jd4/lib/python3.6/site-packages/pydantic/main.py", line 331, in _process_values
return validate_model(self, input_data)
File "/Users/jasonkuhrt/.local/share/virtualenvs/waldo-QOik3jd4/lib/python3.6/site-packages/pydantic/main.py", line 507, in validate_model
raise ValidationError(errors)
pydantic.error_wrappers.ValidationError: 1 validation error
test
none is not an allow value (type=type_error.none.not_allowed)
os.getenv('test')
'foobar'

# Fixed code
def __init__(
    self,
    *,
    name: str,
    type_: Type,
    class_validators: List[Validator],
    default: Any,
    required: bool,
    model_config: Any,
    alias: str = None,
    allow_none: bool = False,
    schema: Schema = None,
):
    self.name: str = name
    self.has_alias: bool = bool(alias)
    self.alias: str = alias or name
    self.type_: type = type_
    self.class_validators = class_validators or []
    self.validate_always: bool = False
    self.sub_fields: List[Field] = None
    self.key_field: Field = None
    self.validators = []
    self.whole_pre_validators = None
    self.whole_post_validators = None
    self.default: Any = default
    self.required: bool = required
    self.model_config = model_config
    self.allow_none: bool = allow_none
    self.parse_json: bool = False
    self.shape: Shape = Shape.SINGLETON
    self._schema: Schema = schema
    self.prepare()
# Buggy code
def schema(self, by_alias=True):
    s = self.type_.schema(by_alias) if hasattr(self.type_, "schema") else {}
    s.update(
        type=s.get("type") or display_as_type(self.type_),
        title=self._schema.title or s.get("title") or self.alias.title(),
        required=self.required,
    )

    if not self.required and self.default is not None:
        s["default"] = self.default
    if issubclass(self.type_, Enum):
        choice_names = self._schema.choice_names or {}
        s["choices"] = [
            (v.value, choice_names.get(v.value) or k.title())
            for k, v in self.type_.__members__.items()
        ]
    s.update(self._schema.extra)
    return s


# Traceback (TypeError)
Traceback (most recent call last):
File "test_pydantic_schema.py", line 9, in <module>
print(TestModel.schema_json(indent=2))
File "/pydantic/pydantic/main.py", line 288, in schema_json
return json.dumps(cls.schema(by_alias=by_alias), default=pydantic_encoder, **dumps_kwargs)
File "/pydantic/pydantic/main.py", line 278, in schema
s['properties'] = {f.alias: f.schema(by_alias) for f in cls.__fields__.values()}
File "/pydantic/pydantic/main.py", line 278, in <dictcomp>
s['properties'] = {f.alias: f.schema(by_alias) for f in cls.__fields__.values()}
File "/pydantic/pydantic/fields.py", line 146, in schema
if issubclass(self.type_, Enum):
TypeError: issubclass() arg 1 must be a class

# Fixed code
def schema(self, by_alias=True):
    s = dict(
        title=self._schema.title or self.alias.title(),
        required=self.required,
    )

    if not self.required and self.default is not None:
        s["default"] = self.default
    s.update(self._schema.extra)

    ts = self.type_schema(by_alias)
    s.update(ts if isinstance(ts, dict) else {"type": ts})
    return s
# Buggy code
def schema(cls, by_alias=True) -> Dict[str, Any]:
    cached = cls._schema_cache.get(by_alias)
    if cached is not None:
        return cached

    s = {
        "type": "object",
        "title": cls.__config__.title or cls.__name__,
    }
    if cls.__doc__:
        s["description"] = clean_docstring(cls.__doc__)

    if by_alias:
        s["properties"] = {f.alias: f.schema(by_alias) for f in cls.__fields__.values()}
    else:
        s["properties"] = {k: f.schema(by_alias) for k, f in cls.__fields__.items()}

    cls._schema_cache[by_alias] = s
    return s


# Traceback (TypeError)
Traceback (most recent call last):
File "test_pydantic_schema.py", line 9, in <module>
print(TestModel.schema_json(indent=2))
File "/pydantic/pydantic/main.py", line 288, in schema_json
return json.dumps(cls.schema(by_alias=by_alias), default=pydantic_encoder, **dumps_kwargs)
File "/pydantic/pydantic/main.py", line 278, in schema
s['properties'] = {f.alias: f.schema(by_alias) for f in cls.__fields__.values()}
File "/pydantic/pydantic/main.py", line 278, in <dictcomp>
s['properties'] = {f.alias: f.schema(by_alias) for f in cls.__fields__.values()}
File "/pydantic/pydantic/fields.py", line 146, in schema
if issubclass(self.type_, Enum):
TypeError: issubclass() arg 1 must be a class

# Fixed code
def schema(cls, by_alias=True) -> Dict[str, Any]:
    cached = cls._schema_cache.get(by_alias)
    if cached is not None:
        return cached
    s = {"title": cls.__config__.title or cls.__name__}
    if cls.__doc__:
        s["description"] = clean_docstring(cls.__doc__)

    s.update(cls.type_schema(by_alias))
    cls._schema_cache[by_alias] = s
    return s
# Buggy code
def api_retrieve(self, api_key=settings.STRIPE_SECRET_KEY):
    # OVERRIDING the parent version of this function
    # Cards must be manipulated through a customer or account.
    # TODO: When managed accounts are supported, this method needs to check if either a customer or
    #       account is supplied to determine the correct object to use.

    return self.customer.api_retrieve(api_key=api_key).sources.retrieve(
        self.stripe_id, expand=self.expand_fields
    )


# Traceback (AttributeError)
customer = Customer.retrieve(id="cus_ACOAhvtRVLJTDT", api_key=settings.STRIPE_SECRET_KEY)
customer
<Customer id=cus_ACOAhvtRVLJTDT at 0x7fd435fffae8> JSON: {
"deleted": true,
"id": "cus_ACOAhvtRVLJTDT"
}
"sources" in customer
False
customer.sources.retrieve(...)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/vagrant/env/lib/python3.4/site-packages/stripe/resource.py", line 135, in __getattr__
raise AttributeError(*err.args)
AttributeError: sources

# Fixed code
def api_retrieve(self, api_key=settings.STRIPE_SECRET_KEY):
    # OVERRIDING the parent version of this function
    # Cards must be manipulated through a customer or account.
    # TODO: When managed accounts are supported, this method needs to check if
    # either a customer or account is supplied to determine the correct object to use.
    customer = self.customer.api_retrieve(api_key=api_key)

    # If the customer is deleted, the sources attribute will be absent.
    # eg. {"id": "cus_XXXXXXXX", "deleted": True}
    if "sources" not in customer:
        # We fake a native stripe InvalidRequestError so that it's caught like an invalid ID error.
        raise InvalidRequestError("No such source: %s" % (self.stripe_id), "id")

    return customer.sources.retrieve(self.stripe_id, expand=self.expand_fields)
# Buggy code
def process_split_ratio(ratio):
    """Generate split ratio lists.

    Args:
        ratio (float or list): a float number that indicates split ratio or a list of float
        numbers that indicate split ratios (if it is a multi-split).

    Returns:
        tuple: a tuple containing
            bool: A boolean variable multi that indicates if the splitting is multi or single.
            list: A list of normalized split ratios.
    """
    if isinstance(ratio, float):
        if ratio <= 0 or ratio >= 1:
            raise ValueError("Split ratio has to be between 0 and 1")

        multi = False
    elif isinstance(ratio, list):
        if any([x <= 0 for x in ratio]):
            raise ValueError(
                "All split ratios in the ratio list should be larger than 0."
            )

        # normalize split ratios if they are not summed to 1
        if sum(ratio) != 1.0:
            ratio = [x / sum(ratio) for x in ratio]

        multi = True
    else:
        raise TypeError("Split ratio should be either float or a list of floats.")

    return multi, ratio


# Traceback (ValueError)
Traceback (most recent call last):
File "C:\Users\scgraham\AppData\Local\Continuum\anaconda3\envs\reco_base\lib\site-packages\IPython\core\interactiveshell.py", line 3325, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-49ca4e7e6410>", line 1, in <module>
x, y, z = python_random_split(df, ratio=[.7, .2, .1])
File "C:\Users\scgraham\repos\Recommenders\reco_utils\dataset\python_splitters.py", line 38, in python_random_split
splits = split_pandas_data_with_ratios(data, ratio, shuffle=True, seed=seed)
File "C:\Users\scgraham\repos\Recommenders\reco_utils\dataset\split_utils.py", line 155, in split_pandas_data_with_ratios
raise ValueError("The ratios have to sum to 1")
ValueError: The ratios have to sum to 1

# Fixed code
def process_split_ratio(ratio):
    """Generate split ratio lists.

    Args:
        ratio (float or list): a float number that indicates split ratio or a list of float
        numbers that indicate split ratios (if it is a multi-split).

    Returns:
        tuple: a tuple containing
            bool: A boolean variable multi that indicates if the splitting is multi or single.
            list: A list of normalized split ratios.
    """
    if isinstance(ratio, float):
        if ratio <= 0 or ratio >= 1:
            raise ValueError("Split ratio has to be between 0 and 1")

        multi = False
    elif isinstance(ratio, list):
        if any([x <= 0 for x in ratio]):
            raise ValueError(
                "All split ratios in the ratio list should be larger than 0."
            )

        # normalize split ratios if they are not summed to 1
        if math.fsum(ratio) != 1.0:
            ratio = [x / math.fsum(ratio) for x in ratio]

        multi = True
    else:
        raise TypeError("Split ratio should be either float or a list of floats.")

    return multi, ratio
# Buggy code
def split_pandas_data_with_ratios(data, ratios, seed=42, shuffle=False):
    """Helper function to split pandas DataFrame with given ratios

    .. note::

        Implementation referenced from `this source <https://stackoverflow.com/questions/38250710/how-to-split-data-into-3-sets-train-validation-and-test>`_.

    Args:
        data (pd.DataFrame): Pandas data frame to be split.
        ratios (list of floats): list of ratios for split. The ratios have to sum to 1.
        seed (int): random seed.
        shuffle (bool): whether data will be shuffled when being split.

    Returns:
        list: List of pd.DataFrame split by the given specifications.
    """
    if sum(ratios) != 1.0:
        raise ValueError("The ratios have to sum to 1")

    split_index = np.cumsum(ratios).tolist()[:-1]

    if shuffle:
        data = data.sample(frac=1, random_state=seed)

    splits = np.split(data, [round(x * len(data)) for x in split_index])

    # Add split index (this makes splitting by group more efficient).
    for i in range(len(ratios)):
        splits[i]["split_index"] = i

    return splits


# Traceback (ValueError)
Traceback (most recent call last):
File "C:\Users\scgraham\AppData\Local\Continuum\anaconda3\envs\reco_base\lib\site-packages\IPython\core\interactiveshell.py", line 3325, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-49ca4e7e6410>", line 1, in <module>
x, y, z = python_random_split(df, ratio=[.7, .2, .1])
File "C:\Users\scgraham\repos\Recommenders\reco_utils\dataset\python_splitters.py", line 38, in python_random_split
splits = split_pandas_data_with_ratios(data, ratio, shuffle=True, seed=seed)
File "C:\Users\scgraham\repos\Recommenders\reco_utils\dataset\split_utils.py", line 155, in split_pandas_data_with_ratios
raise ValueError("The ratios have to sum to 1")
ValueError: The ratios have to sum to 1

# Fixed code
def split_pandas_data_with_ratios(data, ratios, seed=42, shuffle=False):
    """Helper function to split pandas DataFrame with given ratios

    .. note::

        Implementation referenced from `this source <https://stackoverflow.com/questions/38250710/how-to-split-data-into-3-sets-train-validation-and-test>`_.

    Args:
        data (pd.DataFrame): Pandas data frame to be split.
        ratios (list of floats): list of ratios for split. The ratios have to sum to 1.
        seed (int): random seed.
        shuffle (bool): whether data will be shuffled when being split.

    Returns:
        list: List of pd.DataFrame split by the given specifications.
    """
    if math.fsum(ratios) != 1.0:
        raise ValueError("The ratios have to sum to 1")

    split_index = np.cumsum(ratios).tolist()[:-1]

    if shuffle:
        data = data.sample(frac=1, random_state=seed)

    splits = np.split(data, [round(x * len(data)) for x in split_index])

    # Add split index (this makes splitting by group more efficient).
    for i in range(len(ratios)):
        splits[i]["split_index"] = i

    return splits
# Buggy code
def update_checkpoint_dependencies(self, jobs=None):
    """Update dependencies of checkpoints."""
    updated = False
    self.update_checkpoint_outputs()
    if jobs is None:
        jobs = [job for job in self.jobs if not self.needrun(job)]
    for job in jobs:
        if job.is_checkpoint:
            depending = list(self.depending[job])
            # re-evaluate depending jobs, replace and update DAG
            for j in depending:
                logger.info("Updating job {} ({}).".format(self.jobid(j), j))
                newjob = j.updated()
                self.replace_job(j, newjob, recursive=False)
                updated = True
    if updated:
        self.postprocess()
    return updated


# Traceback (KeyError)
Traceback (most recent call last):
File "/mnt/data0/jmeppley/projects/snakemake_bugs/snakemake.272/DTR-phage-pipeline/snakemake/snakemake/__init__.py", line 687, in snakemake
success = workflow.execute(
File "/mnt/data0/jmeppley/projects/snakemake_bugs/snakemake.272/DTR-phage-pipeline/snakemake/snakemake/workflow.py", line 699, in execute
dag.update_checkpoint_dependencies()
File "/mnt/data0/jmeppley/projects/snakemake_bugs/snakemake.272/DTR-phage-pipeline/snakemake/snakemake/dag.py", line 1300, in update_checkpoint_dependencies
logger.info("Updating job {} ({}).".format(self.jobid(j), j))
File "/mnt/data0/jmeppley/projects/snakemake_bugs/snakemake.272/DTR-phage-pipeline/snakemake/snakemake/dag.py", line 704, in jobid
return self._jobid[job]
KeyError: align_dtr_seqs_to_polished_refs

# Fixed code
def update_checkpoint_dependencies(self, jobs=None):
    """Update dependencies of checkpoints."""
    updated = False
    self.update_checkpoint_outputs()
    if jobs is None:
        jobs = [job for job in self.jobs if not self.needrun(job)]
    for job in jobs:
        if job.is_checkpoint:
            depending = list(self.depending[job])
            # re-evaluate depending jobs, replace and update DAG
            for j in depending:
                logger.info("Updating job {}.".format(j))
                newjob = j.updated()
                self.replace_job(j, newjob, recursive=False)
                updated = True
    if updated:
        self.postprocess()
    return updated
# Buggy code
def outputs_older_than_script_or_notebook(self):
    """return output that's older than script, i.e. script has changed"""
    path = self.rule.script or self.rule.notebook
    if not path:
        return
    assert os.path.exists(path)  # to make sure lstat works
    script_mtime = os.lstat(path).st_mtime
    for f in self.expanded_output:
        if f.exists:
            if not f.is_newer(script_mtime):
                yield f


# Traceback (AssertionError)
$ snakemake --list-code-changes

Building DAG of jobs...
Traceback (most recent call last):
File "/Users/haje01/.pyenv/versions/3.7.2/envs/ml2/lib/python3.7/site-packages/snakemake/__init__.py", line 654, in snakemake
keepincomplete=keep_incomplete,
File "/Users/haje01/.pyenv/versions/3.7.2/envs/ml2/lib/python3.7/site-packages/snakemake/workflow.py", line 764, in execute
items.extend(list(j.outputs_older_than_script_or_notebook()))
File "/Users/haje01/.pyenv/versions/3.7.2/envs/ml2/lib/python3.7/site-packages/snakemake/jobs.py", line 208, in outputs_older_than_script_or_notebook
assert os.path.exists(path)  # to make sure lstat works
AssertionError

# Fixed code
def outputs_older_than_script_or_notebook(self):
    """return output that's older than script, i.e. script has changed"""
    path = self.rule.script or self.rule.notebook
    if not path:
        return
    if self.rule.basedir:
        # needed if rule is included from another subdirectory
        path = os.path.relpath(os.path.join(self.rule.basedir, path))
    assert os.path.exists(path), "cannot find {0}".format(path)
    script_mtime = os.lstat(path).st_mtime
    for f in self.expanded_output:
        if f.exists:
            if not f.is_newer(script_mtime):
                yield f
# Buggy code
def __init__(self, max_wait_time):
    self.mtime = dict()
    self.exists_local = ExistsDict(self)
    self.exists_remote = ExistsDict(self)
    self.size = dict()
    # Indicator whether an inventory has been created for the root of a given IOFile.
    # In case of remote objects the root is the bucket or server host.
    self.has_inventory = set()
    self.active = True
    self.remaining_wait_time = max_wait_time
    self.max_wait_time = max_wait_time


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def __init__(self, max_wait_time, nthreads=8):
    self.mtime = dict()
    self.mtime_target = PassthroughDict(
        self.mtime
    )  # filled in case of symlink with mtime of target
    self.exists_local = dict()
    self.exists_remote = dict()
    self.size = dict()
    # Indicator whether an inventory has been created for the root of a given IOFile.
    # In case of remote objects the root is the bucket or server host.
    self.has_inventory = set()
    self.remaining_wait_time = max_wait_time
    self.max_wait_time = max_wait_time
    self.queue = queue.Queue()
    self.threads = []
    self.active = False
    self.nthreads = nthreads

    self.activate()
# Buggy code
def needs_inventory(self, path):
    root = self.get_inventory_root(path)
    return root and root not in self.has_inventory


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def needs_inventory(self, path):
    return path and path not in self.has_inventory
# Buggy code
def in_inventory(self, path):
    root = self.get_inventory_root(path)
    return root and root in self.has_inventory


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def in_inventory(self, path):
    return path and path in self.has_inventory
# Buggy code
def clear(self):
    self.mtime.clear()
    self.size.clear()
    self.exists_local.clear()
    self.exists_remote.clear()
    self.has_inventory.clear()
    self.remaining_wait_time = self.max_wait_time


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def clear(self):
    self.mtime.clear()
    self.mtime_target.clear()
    self.size.clear()
    self.exists_local.clear()
    self.exists_remote.clear()
    self.has_inventory.clear()
    self.remaining_wait_time = self.max_wait_time
# Buggy code
def deactivate(self):
    self.clear()
    self.active = False


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def deactivate(self):
    self.active = False
    for t in self.threads:
        t.join()
    self.threads = []
    self.clear()
# Buggy code
def __new__(cls, file):
    # Remove trailing slashes.
    obj = str.__new__(cls, file)
    obj._is_function = isfunction(file) or ismethod(file)
    obj._is_function = obj._is_function or (
        isinstance(file, AnnotatedString) and bool(file.callable)
    )
    obj._file = file
    obj.rule = None
    obj._regex = None

    if obj.is_remote:
        obj.remote_object._iofile = obj

    return obj


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def __new__(cls, file):
    # Remove trailing slashes.
    obj = str.__new__(cls, file)
    obj._is_function = isfunction(file) or ismethod(file)
    obj._is_function = obj._is_function or (
        isinstance(file, AnnotatedString) and bool(file.callable)
    )
    obj._file = file
    obj.rule = None
    obj._regex = None

    if obj.is_remote:
        obj.remote_object._iofile = obj

    obj.set_inventory_paths()
    return obj
# Buggy code
def inventory(self):
    """Starting from the given file, try to cache as much existence and
    modification date information of this and other files as possible.
    """
    cache = self.rule.workflow.iocache
    if cache.active and cache.needs_inventory(self):
        if self.is_remote:
            # info not yet in inventory, let's discover as much as we can
            self.remote_object.inventory(cache)
        elif not ON_WINDOWS:
            # we don't want to mess with different path representations on windows
            self._local_inventory(cache)


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def inventory(self):
    """Starting from the given file, try to cache as much existence and
    modification date information of this and other files as possible.
    """
    cache = self.rule.workflow.iocache
    if (
        cache.active
        and not self.inventory_path is None
        and cache.needs_inventory(self.inventory_root)
    ):
        # info not yet in inventory, let's discover as much as we can
        if self.is_remote:
            self.remote_object.inventory(cache)
        else:
            self._local_inventory(cache)
# Buggy code
def update_remote_filepath(self):
    # if the file string is different in the iofile, update the remote object
    # (as in the case of wildcard expansion)
    remote_object = self.remote_object
    if remote_object._file != self._file:
        remote_object._iofile = self


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def update_remote_filepath(self):
    # if the file string is different in the iofile, update the remote object
    # (as in the case of wildcard expansion)
    remote_object = self.remote_object
    if remote_object._file != self._file:
        remote_object._iofile = self
    self.set_inventory_paths()
# Buggy code
def mtime_local(self):
    # do not follow symlinks for modification time
    if os.path.isdir(self.file) and os.path.exists(
        os.path.join(self.file, ".snakemake_timestamp")
    ):
        return os.lstat(os.path.join(self.file, ".snakemake_timestamp")).st_mtime
    else:
        return os.lstat(self.file).st_mtime


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def mtime_local(self):
    # do not follow symlinks for modification time
    lstat = os.lstat(self.file)
    if stat.S_ISDIR(lstat.st_mode) and os.path.exists(
        os.path.join(self.file, TIMESTAMP_FILENAME)
    ):
        return os.lstat(os.path.join(self.file, TIMESTAMP_FILENAME)).st_mtime
    else:
        return lstat.st_mtime
# Buggy code
def is_newer(self, time):
    """Returns true of the file is newer than time, or if it is
    a symlink that points to a file newer than time."""
    if self.is_ancient:
        return False
    elif self.is_remote:
        # If file is remote but provider does not override the implementation this
        # is the best we can do.
        return self.mtime > time
    else:
        if os.path.isdir(self.file) and os.path.exists(
            os.path.join(self.file, ".snakemake_timestamp")
        ):
            st_mtime_file = os.path.join(self.file, ".snakemake_timestamp")
        else:
            st_mtime_file = self.file
        try:
            return os.stat(st_mtime_file).st_mtime > time or self.mtime > time
        except FileNotFoundError:
            raise WorkflowError(
                "File {} not found although it existed before. Is there another active process that might have deleted it?".format(
                    self.file
                )
            )


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def is_newer(self, time):
    """Returns true of the file is newer than time, or if it is
    a symlink that points to a file newer than time."""
    if self.is_ancient:
        return False
    elif self.is_remote:
        return self.mtime > time
    else:
        return self.mtime > time or self.mtime_target > time
# Buggy code
def touch(self, times=None):
    """times must be 2-tuple: (atime, mtime)"""
    try:
        if self.is_directory:
            file = os.path.join(self.file, ".snakemake_timestamp")
            # Create the flag file if it doesn't exist
            if not os.path.exists(file):
                with open(file, "w") as f:
                    pass
            lutime(file, times)
        else:
            lutime(self.file, times)
    except OSError as e:
        if e.errno == 2:
            raise MissingOutputException(
                "Output file {} of rule {} shall be touched but does not exist.".format(
                    self.file, self.rule.name
                ),
                lineno=self.rule.lineno,
                snakefile=self.rule.snakefile,
            )
        else:
            raise e


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def touch(self, times=None):
    """times must be 2-tuple: (atime, mtime)"""
    try:
        if self.is_directory:
            file = os.path.join(self.file, TIMESTAMP_FILENAME)
            # Create the flag file if it doesn't exist
            if not os.path.exists(file):
                with open(file, "w") as f:
                    pass
            lutime(file, times)
        else:
            lutime(self.file, times)
    except OSError as e:
        if e.errno == 2:
            raise MissingOutputException(
                "Output file {} of rule {} shall be touched but does not exist.".format(
                    self.file, self.rule.name
                ),
                lineno=self.rule.lineno,
                snakefile=self.rule.snakefile,
            )
        else:
            raise e
# Buggy code
def touch_or_create(self):
    try:
        self.touch()
    except MissingOutputException:
        # first create directory if it does not yet exist
        dir = self.file if self.is_directory else os.path.dirname(self.file)
        if dir:
            os.makedirs(dir, exist_ok=True)
        # create empty file
        file = (
            os.path.join(self.file, ".snakemake_timestamp")
            if self.is_directory
            else self.file
        )
        with open(file, "w") as f:
            pass


# Traceback (FileNotFoundError)
Building DAG of jobs...
Traceback (most recent call last):
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/__init__.py", line 709, in snakemake
keepincomplete=keep_incomplete,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/workflow.py", line 670, in execute
dag.init()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 177, in init
job = self.update(self.file2jobs(file), file=file, progress=progress)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 715, in update
progress=progress,
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/dag.py", line 792, in update_
file.inventory()
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 210, in inventory
self._local_inventory(cache)
File "<base_path>/software/miniconda/envs/snakemake/lib/python3.7/site-packages/snakemake/io.py", line 224, in _local_inventory
with os.scandir(path) as scan:
FileNotFoundError: [Errno 2] No such file or directory: '<analysis_patch>/tmp_batch113/codons'

# Fixed code
def touch_or_create(self):
    try:
        self.touch()
    except MissingOutputException:
        # first create directory if it does not yet exist
        dir = self.file if self.is_directory else os.path.dirname(self.file)
        if dir:
            os.makedirs(dir, exist_ok=True)
        # create empty file
        file = (
            os.path.join(self.file, TIMESTAMP_FILENAME)
            if self.is_directory
            else self.file
        )
        with open(file, "w") as f:
            pass