gurudesh/pytracebugs huggingface dataset:
# Buggy code
def __init__(self, transform, image_crs, map_crs="epsg:4326"):
    """Construct transformer.

    Args:
        image_dataset: Rasterio DatasetReader
        map_crs: CRS code
    """
    self.transform = transform
    self.map_proj = pyproj.Proj(init=map_crs)
    self.image_proj = pyproj.Proj(init=image_crs)

    super().__init__(image_crs, map_crs)


# Traceback (AttributeError)
root@122d4f0150f4:/opt/data/mar5# rastervision predict spacenet.zip example.jpg out.tif
/usr/local/lib/python3.5/dist-packages/pluginbase.py:439: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
fromlist, level)
2019-03-06 16:59:56.502396: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
/usr/local/lib/python3.5/dist-packages/rasterio/__init__.py:217: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
s = DatasetReader(path, driver=driver, **kwargs)
[0, 1, 2]
2019-03-06 16:59:56:rastervision.task.semantic_segmentation: INFO - Making predictions for scene
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/src/rastervision/__main__.py", line 17, in <module>
rv.main()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/opt/src/rastervision/cli/main.py", line 241, in predict
predictor.predict(image_uri, output_uri, export_config)
File "/opt/src/rastervision/predictor.py", line 144, in predict
scene.prediction_label_store.save(labels)
File "/opt/src/rastervision/data/label_store/semantic_segmentation_raster_store.py", line 90, in save
transform = self.crs_transformer.transform
AttributeError: 'IdentityCRSTransformer' object has no attribute 'transform'

# Fixed code
def __init__(self, transform, image_crs, map_crs="epsg:4326"):
    """Construct transformer.

    Args:
        image_dataset: Rasterio DatasetReader
        map_crs: CRS code
    """
    self.map_proj = pyproj.Proj(init=map_crs)
    self.image_proj = pyproj.Proj(init=image_crs)

    super().__init__(image_crs, map_crs, transform)
# Buggy code
def get_service_scale(self, service_dict):
    # service.scale for v2 and deploy.replicas for v3
    scale = service_dict.get("scale", None)
    deploy_dict = service_dict.get("deploy", None)
    if not deploy_dict:
        return 1 if scale is None else scale

    if deploy_dict.get("mode", "replicated") != "replicated":
        return 1 if scale is None else scale

    replicas = deploy_dict.get("replicas", None)
    if scale and replicas:
        raise ConfigurationError(
            "Both service.scale and service.deploy.replicas are set."
            " Only one of them must be set."
        )
    if replicas:
        scale = replicas
    # deploy may contain placement constraints introduced in v3.8
    max_replicas = deploy_dict.get("placement", {}).get("max_replicas_per_node", scale)

    scale = min(scale, max_replicas)
    if max_replicas < scale:
        log.warning(
            "Scale is limited to {} ('max_replicas_per_node' field).".format(
                max_replicas
            )
        )
    return scale


# Traceback (TypeError)
WARNING: Some services (minecraft) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose/cli/main.py", line 67, in main
File "compose/cli/main.py", line 120, in perform_command
File "compose/cli/command.py", line 70, in project_from_options
File "compose/cli/command.py", line 144, in get_project
File "compose/project.py", line 130, in from_config
File "compose/project.py", line 326, in get_service_scale
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
[11029] Failed to execute script docker-compose

# Fixed code
def get_service_scale(self, service_dict):
    # service.scale for v2 and deploy.replicas for v3
    scale = service_dict.get("scale", None)
    deploy_dict = service_dict.get("deploy", None)
    if not deploy_dict:
        return 1 if scale is None else scale

    if deploy_dict.get("mode", "replicated") != "replicated":
        return 1 if scale is None else scale

    replicas = deploy_dict.get("replicas", None)
    if scale and replicas:
        raise ConfigurationError(
            "Both service.scale and service.deploy.replicas are set."
            " Only one of them must be set."
        )
    if replicas:
        scale = replicas
    if scale is None:
        return 1
    # deploy may contain placement constraints introduced in v3.8
    max_replicas = deploy_dict.get("placement", {}).get("max_replicas_per_node", scale)

    scale = min(scale, max_replicas)
    if max_replicas < scale:
        log.warning(
            "Scale is limited to {} ('max_replicas_per_node' field).".format(
                max_replicas
            )
        )
    return scale
# Buggy code
def call_docker(args, dockeropts, environment):
    executable_path = find_executable("docker")
    if not executable_path:
        raise UserError(errors.docker_not_found_msg("Couldn't find `docker` binary."))

    tls = dockeropts.get("--tls", False)
    ca_cert = dockeropts.get("--tlscacert")
    cert = dockeropts.get("--tlscert")
    key = dockeropts.get("--tlskey")
    verify = dockeropts.get("--tlsverify")
    host = dockeropts.get("--host")
    tls_options = []
    if tls:
        tls_options.append("--tls")
    if ca_cert:
        tls_options.extend(["--tlscacert", ca_cert])
    if cert:
        tls_options.extend(["--tlscert", cert])
    if key:
        tls_options.extend(["--tlskey", key])
    if verify:
        tls_options.append("--tlsverify")
    if host:
        tls_options.extend(
            ["--host", re.sub(r"^https?://", "tcp://", host.lstrip("="))]
        )

    args = [executable_path] + tls_options + args
    log.debug(" ".join(map(pipes.quote, args)))

    return subprocess.call(args, env=environment)


# Traceback (TypeError)
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose/cli/main.py", line 72, in main
File "compose/cli/main.py", line 128, in perform_command
File "compose/cli/main.py", line 491, in exec_command
File "compose/cli/main.py", line 1469, in call_docker
File "subprocess.py", line 339, in call
File "subprocess.py", line 800, in __init__
File "subprocess.py", line 1462, in _execute_child
File "os.py", line 810, in fsencode
TypeError: expected str, bytes or os.PathLike object, not NoneType
[24719] Failed to execute script docker-compose

# Fixed code
def call_docker(args, dockeropts, environment):
    executable_path = find_executable("docker")
    if not executable_path:
        raise UserError(errors.docker_not_found_msg("Couldn't find `docker` binary."))

    tls = dockeropts.get("--tls", False)
    ca_cert = dockeropts.get("--tlscacert")
    cert = dockeropts.get("--tlscert")
    key = dockeropts.get("--tlskey")
    verify = dockeropts.get("--tlsverify")
    host = dockeropts.get("--host")
    tls_options = []
    if tls:
        tls_options.append("--tls")
    if ca_cert:
        tls_options.extend(["--tlscacert", ca_cert])
    if cert:
        tls_options.extend(["--tlscert", cert])
    if key:
        tls_options.extend(["--tlskey", key])
    if verify:
        tls_options.append("--tlsverify")
    if host:
        tls_options.extend(
            ["--host", re.sub(r"^https?://", "tcp://", host.lstrip("="))]
        )

    args = [executable_path] + tls_options + args
    log.debug(" ".join(map(pipes.quote, args)))

    filtered_env = {}
    for k, v in environment.items():
        if v is not None:
            filtered_env[k] = environment[k]

    return subprocess.call(args, env=filtered_env)
# Buggy code
def version(self):
    if "version" not in self.config:
        return V1

    version = self.config["version"]

    if isinstance(version, dict):
        log.warning(
            'Unexpected type for "version" key in "{}". Assuming '
            '"version" is the name of a service, and defaulting to '
            "Compose file version 1.".format(self.filename)
        )
        return V1

    if not isinstance(version, six.string_types):
        raise ConfigurationError(
            'Version in "{}" is invalid - it should be a string.'.format(self.filename)
        )

    if version == "1":
        raise ConfigurationError(
            'Version in "{}" is invalid. {}'.format(self.filename, VERSION_EXPLANATION)
        )

    if version == "2":
        return const.COMPOSEFILE_V2_0

    if version == "3":
        return const.COMPOSEFILE_V3_0

    return ComposeVersion(version)


# Traceback (TypeError)
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 121, in perform_command
File "compose/cli/main.py", line 332, in config
File "compose/cli/command.py", line 68, in get_config_from_options
File "compose/config/config.py", line 385, in load
File "compose/config/config.py", line 385, in <listcomp>
File "compose/config/config.py", line 535, in process_config_file
File "distutils/version.py", line 70, in __ge__
File "distutils/version.py", line 337, in _cmp
TypeError: '<' not supported between instances of 'str' and 'int'
[4431] Failed to execute script docker-compose

# Fixed code
def version(self):
    if "version" not in self.config:
        return V1

    version = self.config["version"]

    if isinstance(version, dict):
        log.warning(
            'Unexpected type for "version" key in "{}". Assuming '
            '"version" is the name of a service, and defaulting to '
            "Compose file version 1.".format(self.filename)
        )
        return V1

    if not isinstance(version, six.string_types):
        raise ConfigurationError(
            'Version in "{}" is invalid - it should be a string.'.format(self.filename)
        )

    if version == "1":
        raise ConfigurationError(
            'Version in "{}" is invalid. {}'.format(self.filename, VERSION_EXPLANATION)
        )

    version_pattern = re.compile(r"^[2-9]+(\.\d+)?$")
    if not version_pattern.match(version):
        raise ConfigurationError(
            'Version "{}" in "{}" is invalid.'.format(version, self.filename)
        )

    if version == "2":
        return const.COMPOSEFILE_V2_0

    if version == "3":
        return const.COMPOSEFILE_V3_0

    return ComposeVersion(version)
# Buggy code
def execution_context_labels(config_details, environment_file):
    extra_labels = [
        "{0}={1}".format(
            LABEL_WORKING_DIR, os.path.abspath(config_details.working_dir)
        ),
        "{0}={1}".format(LABEL_CONFIG_FILES, config_files_label(config_details)),
    ]
    if environment_file is not None:
        extra_labels.append(
            "{0}={1}".format(LABEL_ENVIRONMENT_FILE, os.path.normpath(environment_file))
        )
    return extra_labels


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 11, in <module>
load_entry_point('docker-compose==1.25.0', 'console_scripts', 'docker-compose')()
File "/usr/lib/python3.8/site-packages/compose/cli/main.py", line 72, in main
command()
File "/usr/lib/python3.8/site-packages/compose/cli/main.py", line 125, in perform_command
project = project_from_options('.', options)
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 53, in project_from_options
return get_project(
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 156, in get_project
execution_context_labels(config_details, environment_file),
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 163, in execution_context_labels
'{0}={1}'.format(LABEL_CONFIG_FILES, config_files_label(config_details)),
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 172, in config_files_label
return ",".join(
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 173, in <genexpr>
map(str, (os.path.normpath(c.filename) for c in config_details.config_files)))
File "/usr/lib/python3.8/posixpath.py", line 336, in normpath
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

# Fixed code
def execution_context_labels(config_details, environment_file):
    extra_labels = [
        "{0}={1}".format(LABEL_WORKING_DIR, os.path.abspath(config_details.working_dir))
    ]

    if not use_config_from_stdin(config_details):
        extra_labels.append(
            "{0}={1}".format(LABEL_CONFIG_FILES, config_files_label(config_details))
        )

    if environment_file is not None:
        extra_labels.append(
            "{0}={1}".format(LABEL_ENVIRONMENT_FILE, os.path.normpath(environment_file))
        )
    return extra_labels
# Buggy code
def config_files_label(config_details):
    return ",".join(
        map(str, (os.path.normpath(c.filename) for c in config_details.config_files))
    )


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 11, in <module>
load_entry_point('docker-compose==1.25.0', 'console_scripts', 'docker-compose')()
File "/usr/lib/python3.8/site-packages/compose/cli/main.py", line 72, in main
command()
File "/usr/lib/python3.8/site-packages/compose/cli/main.py", line 125, in perform_command
project = project_from_options('.', options)
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 53, in project_from_options
return get_project(
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 156, in get_project
execution_context_labels(config_details, environment_file),
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 163, in execution_context_labels
'{0}={1}'.format(LABEL_CONFIG_FILES, config_files_label(config_details)),
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 172, in config_files_label
return ",".join(
File "/usr/lib/python3.8/site-packages/compose/cli/command.py", line 173, in <genexpr>
map(str, (os.path.normpath(c.filename) for c in config_details.config_files)))
File "/usr/lib/python3.8/posixpath.py", line 336, in normpath
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

# Fixed code
def config_files_label(config_details):
    return ",".join(
        map(str, (config_file_path(c.filename) for c in config_details.config_files))
    )
# Buggy code
def merge_networks(base, override):
    merged_networks = {}
    all_network_names = set(base) | set(override)
    base = {k: {} for k in base} if isinstance(base, list) else base
    override = {k: {} for k in override} if isinstance(override, list) else override
    for network_name in all_network_names:
        md = MergeDict(base.get(network_name, {}), override.get(network_name, {}))
        md.merge_field("aliases", merge_unique_items_lists, [])
        md.merge_field("link_local_ips", merge_unique_items_lists, [])
        md.merge_scalar("priority")
        md.merge_scalar("ipv4_address")
        md.merge_scalar("ipv6_address")
        merged_networks[network_name] = dict(md)
    return merged_networks


# Traceback (TypeError)
docker-compose config
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 121, in perform_command
File "compose/cli/main.py", line 339, in config
File "compose/cli/command.py", line 70, in get_config_from_options
File "compose/config/config.py", line 404, in load
File "compose/config/config.py", line 502, in load_services
File "compose/config/config.py", line 493, in merge_services
File "compose/config/config.py", line 493, in <dictcomp>
File "compose/config/config.py", line 996, in merge_service_dicts_from_files
File "compose/config/config.py", line 1064, in merge_service_dicts
File "compose/config/config.py", line 1020, in merge_field
File "compose/config/config.py", line 1176, in merge_networks
File "compose/config/config.py", line 1015, in merge_field
File "compose/config/config.py", line 1012, in needs_merge
TypeError: argument of type 'NoneType' is not iterable
[1981] Failed to execute script docker-compose

# Fixed code
def merge_networks(base, override):
    merged_networks = {}
    all_network_names = set(base) | set(override)
    base = {k: {} for k in base} if isinstance(base, list) else base
    override = {k: {} for k in override} if isinstance(override, list) else override
    for network_name in all_network_names:
        md = MergeDict(base.get(network_name) or {}, override.get(network_name) or {})
        md.merge_field("aliases", merge_unique_items_lists, [])
        md.merge_field("link_local_ips", merge_unique_items_lists, [])
        md.merge_scalar("priority")
        md.merge_scalar("ipv4_address")
        md.merge_scalar("ipv6_address")
        merged_networks[network_name] = dict(md)
    return merged_networks
# Buggy code
def write_initial(self, msg, obj_index):
    if msg is None:
        return
    self.stream.write(
        "{:<{width}} ... \r\n".format(msg + " " + obj_index, width=self.width)
    )
    self.stream.flush()


# Traceback (TypeError)
Traceback (most recent call last):
File "bin/docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 716, in pull
File "compose/project.py", line 558, in pull
TypeError: sequence item 0: expected a bytes-like object, str found

# Fixed code
def write_initial(self, msg, obj_index):
    if msg is None:
        return
    return self._write_noansi(msg, obj_index, "")
# Buggy code
def pull(
    self,
    service_names=None,
    ignore_pull_failures=False,
    parallel_pull=False,
    silent=False,
    include_deps=False,
):
    services = self.get_services(service_names, include_deps)

    if parallel_pull:

        def pull_service(service):
            service.pull(ignore_pull_failures, True)

        _, errors = parallel.parallel_execute(
            services,
            pull_service,
            operator.attrgetter("name"),
            not silent and "Pulling" or None,
            limit=5,
        )
        if len(errors):
            raise ProjectError(b"\n".join(errors.values()))
    else:
        for service in services:
            service.pull(ignore_pull_failures, silent=silent)


# Traceback (TypeError)
Traceback (most recent call last):
File "bin/docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 716, in pull
File "compose/project.py", line 558, in pull
TypeError: sequence item 0: expected a bytes-like object, str found

# Fixed code
def pull(
    self,
    service_names=None,
    ignore_pull_failures=False,
    parallel_pull=False,
    silent=False,
    include_deps=False,
):
    services = self.get_services(service_names, include_deps)

    if parallel_pull:

        def pull_service(service):
            service.pull(ignore_pull_failures, True)

        _, errors = parallel.parallel_execute(
            services,
            pull_service,
            operator.attrgetter("name"),
            not silent and "Pulling" or None,
            limit=5,
        )
        if len(errors):
            combined_errors = "\n".join(
                [
                    e.decode("utf-8") if isinstance(e, six.binary_type) else e
                    for e in errors.values()
                ]
            )
            raise ProjectError(combined_errors)

    else:
        for service in services:
            service.pull(ignore_pull_failures, silent=silent)
# Buggy code
def load_yaml(filename):
    try:
        with open(filename, "r") as fh:
            return yaml.safe_load(fh)
    except (IOError, yaml.YAMLError) as e:
        error_name = getattr(e, "__module__", "") + "." + e.__class__.__name__
        raise ConfigurationError("{}: {}".format(error_name, e))


# Traceback (UnicodeDecodeError)
Output of "docker-compose config"
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose\cli\main.py", line 71, in main
File "compose\cli\main.py", line 121, in perform_command
File "compose\cli\main.py", line 329, in config
File "compose\cli\command.py", line 67, in get_config_from_options
File "compose\config\config.py", line 283, in find
File "compose\config\config.py", line 283, in <listcomp>
File "compose\config\config.py", line 183, in from_filename
File "compose\config\config.py", line 1434, in load_yaml
File "site-packages\yaml\__init__.py", line 94, in safe_load
File "site-packages\yaml\__init__.py", line 70, in load
File "site-packages\yaml\loader.py", line 24, in __init__
File "site-packages\yaml\reader.py", line 85, in __init__
File "site-packages\yaml\reader.py", line 124, in determine_encoding
File "site-packages\yaml\reader.py", line 178, in update_raw
UnicodeDecodeError: 'cp932' codec can't decode byte 0x83 in position 19: illegal multibyte sequence
[11180] Failed to execute script docker-compose

# Fixed code
def load_yaml(filename, encoding=None):
    try:
        with io.open(filename, "r", encoding=encoding) as fh:
            return yaml.safe_load(fh)
    except (IOError, yaml.YAMLError, UnicodeDecodeError) as e:
        if encoding is None:
            # Sometimes the user's locale sets an encoding that doesn't match
            # the YAML files. Im such cases, retry once with the "default"
            # UTF-8 encoding
            return load_yaml(filename, encoding="utf-8")
        error_name = getattr(e, "__module__", "") + "." + e.__class__.__name__
        raise ConfigurationError("{}: {}".format(error_name, e))
# Buggy code
def stream_output(output, stream):
    is_terminal = hasattr(stream, "isatty") and stream.isatty()
    stream = utils.get_output_stream(stream)
    all_events = []
    lines = {}
    diff = 0

    for event in utils.json_stream(output):
        all_events.append(event)
        is_progress_event = "progress" in event or "progressDetail" in event

        if not is_progress_event:
            print_output_event(event, stream, is_terminal)
            stream.flush()
            continue

        if not is_terminal:
            continue

        # if it's a progress event and we have a terminal, then display the progress bars
        image_id = event.get("id")
        if not image_id:
            continue

        if image_id not in lines:
            lines[image_id] = len(lines)
            stream.write("\n")

        diff = len(lines) - lines[image_id]

        # move cursor up `diff` rows
        stream.write("%c[%dA" % (27, diff))

        print_output_event(event, stream, is_terminal)

        if "id" in event:
            # move cursor back down
            stream.write("%c[%dB" % (27, diff))

        stream.flush()

    return all_events


# Traceback (UnicodeEncodeError)
Traceback (most recent call last):
File "bin/docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 280, in build
File "compose/project.py", line 372, in build
File "compose/service.py", line 1003, in build
File "compose/progress_stream.py", line 23, in stream_output
File "compose/progress_stream.py", line 90, in print_output_event
UnicodeEncodeError: 'ascii' codec can't encode character '\u2013' in position 151: ordinal not in range(128)
[96] Failed to execute script docker-compose
Exited with code 255

# Fixed code
def stream_output(output, stream):
    is_terminal = hasattr(stream, "isatty") and stream.isatty()
    stream = utils.get_output_stream(stream)
    all_events = []
    lines = {}
    diff = 0

    for event in utils.json_stream(output):
        all_events.append(event)
        is_progress_event = "progress" in event or "progressDetail" in event

        if not is_progress_event:
            print_output_event(event, stream, is_terminal)
            stream.flush()
            continue

        if not is_terminal:
            continue

        # if it's a progress event and we have a terminal, then display the progress bars
        image_id = event.get("id")
        if not image_id:
            continue

        if image_id not in lines:
            lines[image_id] = len(lines)
            write_to_stream("\n", stream)

        diff = len(lines) - lines[image_id]

        # move cursor up `diff` rows
        write_to_stream("%c[%dA" % (27, diff), stream)

        print_output_event(event, stream, is_terminal)

        if "id" in event:
            # move cursor back down
            write_to_stream("%c[%dB" % (27, diff), stream)

        stream.flush()

    return all_events
# Buggy code
def producer(obj, func, results, limiter):
    """
    The entry point for a producer thread which runs func on a single object.
    Places a tuple on the results queue once func has either returned or raised.
    """
    with limiter:
        try:
            result = func(obj)
            results.put((obj, result, None))
        except Exception as e:
            results.put((obj, None, e))


# Traceback (IOError)
Exception in thread Thread-5:
Traceback (most recent call last):
File "/compose/build/docker-compose/out00-PYZ.pyz/threading", line 810, in __bootstrap_inner
File "/compose/build/docker-compose/out00-PYZ.pyz/threading", line 763, in run
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.utils", line 31, in inner_execute_function
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 220, in <lambda>
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 173, in create_and_start
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 268, in create_container
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 579, in _get_container_create_options
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 464, in config_hash
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 469, in config_dict
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 295, in image
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.utils.decorators", line 20, in wrapped
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.client", line 489, in inspect_image
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.clientbase", line 86, in _get
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 477, in get
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 465, in request
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 573, in send
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.adapters", line 370, in send
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 544, in urlopen
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 341, in _make_request
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 761, in _validate_conn
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connection", line 238, in connect
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.util.ssl_", line 277, in ssl_wrap_socket
IOError: [Errno 24] Too many open files

# Fixed code
def producer(obj, func, results, limiter):
    """
    The entry point for a producer thread which runs func on a single object.
    Places a tuple on the results queue once func has either returned or raised.
    """
    with limiter, GlobalLimit.global_limiter:
        try:
            result = func(obj)
            results.put((obj, result, None))
        except Exception as e:
            results.put((obj, None, e))
# Buggy code
def producer(obj, func, results, limiter):
    """
    The entry point for a producer thread which runs func on a single object.
    Places a tuple on the results queue once func has either returned or raised.
    """
    with limiter, global_limiter:
        try:
            result = func(obj)
            results.put((obj, result, None))
        except Exception as e:
            results.put((obj, None, e))


# Traceback (IOError)
Exception in thread Thread-5:
Traceback (most recent call last):
File "/compose/build/docker-compose/out00-PYZ.pyz/threading", line 810, in __bootstrap_inner
File "/compose/build/docker-compose/out00-PYZ.pyz/threading", line 763, in run
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.utils", line 31, in inner_execute_function
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 220, in <lambda>
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 173, in create_and_start
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 268, in create_container
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 579, in _get_container_create_options
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 464, in config_hash
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 469, in config_dict
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 295, in image
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.utils.decorators", line 20, in wrapped
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.client", line 489, in inspect_image
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.clientbase", line 86, in _get
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 477, in get
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 465, in request
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 573, in send
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.adapters", line 370, in send
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 544, in urlopen
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 341, in _make_request
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 761, in _validate_conn
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connection", line 238, in connect
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.util.ssl_", line 277, in ssl_wrap_socket
IOError: [Errno 24] Too many open files

# Fixed code
def producer(obj, func, results, limiter):
    """
    The entry point for a producer thread which runs func on a single object.
    Places a tuple on the results queue once func has either returned or raised.
    """
    with limiter, GlobalLimit.global_limiter:
        try:
            result = func(obj)
            results.put((obj, result, None))
        except Exception as e:
            results.put((obj, None, e))
# Buggy code
def __init__(
    self, name, services, client, networks=None, volumes=None, config_version=None
):
    self.name = name
    self.services = services
    self.client = client
    self.volumes = volumes or ProjectVolumes({})
    self.networks = networks or ProjectNetworks({}, False)
    self.config_version = config_version


# Traceback (IOError)
Exception in thread Thread-5:
Traceback (most recent call last):
File "/compose/build/docker-compose/out00-PYZ.pyz/threading", line 810, in __bootstrap_inner
File "/compose/build/docker-compose/out00-PYZ.pyz/threading", line 763, in run
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.utils", line 31, in inner_execute_function
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 220, in <lambda>
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 173, in create_and_start
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 268, in create_container
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 579, in _get_container_create_options
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 464, in config_hash
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 469, in config_dict
File "/compose/build/docker-compose/out00-PYZ.pyz/compose.service", line 295, in image
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.utils.decorators", line 20, in wrapped
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.client", line 489, in inspect_image
File "/compose/build/docker-compose/out00-PYZ.pyz/docker.clientbase", line 86, in _get
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 477, in get
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 465, in request
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 573, in send
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.adapters", line 370, in send
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 544, in urlopen
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 341, in _make_request
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connectionpool", line 761, in _validate_conn
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.connection", line 238, in connect
File "/compose/build/docker-compose/out00-PYZ.pyz/requests.packages.urllib3.util.ssl_", line 277, in ssl_wrap_socket
IOError: [Errno 24] Too many open files

# Fixed code
def __init__(
    self,
    name,
    services,
    client,
    networks=None,
    volumes=None,
    config_version=None,
    parallel_limit=None,
):
    self.name = name
    self.services = services
    self.client = client
    self.volumes = volumes or ProjectVolumes({})
    self.networks = networks or ProjectNetworks({}, False)
    self.config_version = config_version
    parallel.GlobalLimit.set_global_limit(value=parallel_limit)
# Buggy code
def merge_ports(md, base, override):
    def parse_sequence_func(seq):
        acc = []
        for item in seq:
            acc.extend(ServicePort.parse(item))
        return to_mapping(acc, "merge_field")

    field = "ports"

    if not md.needs_merge(field):
        return

    merged = parse_sequence_func(md.base.get(field, []))
    merged.update(parse_sequence_func(md.override.get(field, [])))
    md[field] = [item for item in sorted(merged.values())]


# Traceback (TypeError)
(master) hexlet$ make compose-bash
docker-compose run web bash
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/compose/cli/main.py", line 68, in main
command()
File "/usr/local/lib/python3.5/dist-packages/compose/cli/main.py", line 115, in perform_command
project = project_from_options('.', options)
File "/usr/local/lib/python3.5/dist-packages/compose/cli/command.py", line 37, in project_from_options
override_dir=options.get('--project-directory'),
File "/usr/local/lib/python3.5/dist-packages/compose/cli/command.py", line 91, in get_project
config_data = config.load(config_details)
File "/usr/local/lib/python3.5/dist-packages/compose/config/config.py", line 379, in load
service_dicts = load_services(config_details, main_file)
File "/usr/local/lib/python3.5/dist-packages/compose/config/config.py", line 475, in load_services
service_config = merge_services(service_config, next_config)
File "/usr/local/lib/python3.5/dist-packages/compose/config/config.py", line 466, in merge_services
for name in all_service_names
File "/usr/local/lib/python3.5/dist-packages/compose/config/config.py", line 466, in <dictcomp>
for name in all_service_names
File "/usr/local/lib/python3.5/dist-packages/compose/config/config.py", line 853, in merge_service_dicts_from_files
new_service = merge_service_dicts(base, override, version)
File "/usr/local/lib/python3.5/dist-packages/compose/config/config.py", line 929, in merge_service_dicts
merge_ports(md, base, override)
File "/usr/local/lib/python3.5/dist-packages/compose/config/config.py", line 962, in merge_ports
md[field] = [item for item in sorted(merged.values())]
TypeError: unorderable types: NoneType() < str()
Makefile:72: recipe for target 'compose-bash' failed
make: *** [compose-bash] Error 1
(master) hexlet$ cat ^C
(master) hexlet$ docker-compose --version
docker-compose version 1.14.0, build c7bdf9e

# Fixed code
def merge_ports(md, base, override):
    def parse_sequence_func(seq):
        acc = []
        for item in seq:
            acc.extend(ServicePort.parse(item))
        return to_mapping(acc, "merge_field")

    field = "ports"

    if not md.needs_merge(field):
        return

    merged = parse_sequence_func(md.base.get(field, []))
    merged.update(parse_sequence_func(md.override.get(field, [])))
    md[field] = [item for item in sorted(merged.values(), key=lambda x: x.target)]
# Buggy code
def get_config_path_from_options(base_dir, options, environment):
    file_option = options.get("--file")
    if file_option:
        return file_option

    config_files = environment.get("COMPOSE_FILE")
    if config_files:
        pathsep = environment.get("COMPOSE_PATH_SEPARATOR", os.pathsep)
        return config_files.split(pathsep)
    return None


# Traceback (UnicodeDecodeError)
$ docker-compose -f 就吃饭/docker-compose.yml config/home/joffrey/work/compose/compose/config/config.py:234: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if filenames == ['-']:
Traceback (most recent call last):
File "/home/joffrey/.envs/compose/bin/docker-compose", line 9, in <module>
load_entry_point('docker-compose==1.11.0.dev0', 'console_scripts', 'docker-compose')()
File "/home/joffrey/work/compose/compose/cli/main.py", line 64, in main
command()
File "/home/joffrey/work/compose/compose/cli/main.py", line 110, in perform_command
handler(command, options, command_options)
File "/home/joffrey/work/compose/compose/cli/main.py", line 305, in config
compose_config = get_config_from_options(self.project_dir, config_options)
File "/home/joffrey/work/compose/compose/cli/command.py", line 46, in get_config_from_options
config.find(base_dir, config_path, environment)
File "/home/joffrey/work/compose/compose/config/config.py", line 242, in find
filenames = [os.path.join(base_dir, f) for f in filenames]
File "/home/joffrey/.envs/compose/lib/python2.7/posixpath.py", line 73, in join
path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)

# Fixed code
def get_config_path_from_options(base_dir, options, environment):
    def unicode_paths(paths):
        return [
            p.decode("utf-8") if isinstance(p, six.binary_type) else p for p in paths
        ]

    file_option = options.get("--file")
    if file_option:
        return unicode_paths(file_option)

    config_files = environment.get("COMPOSE_FILE")
    if config_files:
        pathsep = environment.get("COMPOSE_PATH_SEPARATOR", os.pathsep)
        return unicode_paths(config_files.split(pathsep))
    return None
# Buggy code
def repr(self):
    return dict(
        source=self.source,
        target=self.target,
        uid=self.uid,
        gid=self.gid,
        mode=self.mode,
    )


# Traceback (AttributeError)
$ docker-compose config
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/site-packages/compose/cli/main.py", line 88, in main
command()
File "/usr/local/lib/python2.7/site-packages/compose/cli/main.py", line 134, in perform_command
handler(command, options, command_options)
File "/usr/local/lib/python2.7/site-packages/compose/cli/main.py", line 330, in config
compose_config = get_config_from_options(self.project_dir, config_options)
File "/usr/local/lib/python2.7/site-packages/compose/cli/command.py", line 46, in get_config_from_options
config.find(base_dir, config_path, environment)
File "/usr/local/lib/python2.7/site-packages/compose/config/config.py", line 333, in load
service_dicts = load_services(config_details, main_file)
File "/usr/local/lib/python2.7/site-packages/compose/config/config.py", line 455, in load_services
service_config = merge_services(service_config, next_config)
File "/usr/local/lib/python2.7/site-packages/compose/config/config.py", line 446, in merge_services
for name in all_service_names
File "/usr/local/lib/python2.7/site-packages/compose/config/config.py", line 446, in <dictcomp>
for name in all_service_names
File "/usr/local/lib/python2.7/site-packages/compose/config/config.py", line 797, in merge_service_dicts_from_files
new_service = merge_service_dicts(base, override, version)
File "/usr/local/lib/python2.7/site-packages/compose/config/config.py", line 856, in merge_service_dicts
md.merge_sequence('secrets', types.ServiceSecret.parse)
File "/usr/local/lib/python2.7/site-packages/compose/config/config.py", line 839, in merge_sequence
self[field] = [item.repr() for item in sorted(merged.values())]
AttributeError: 'ServiceSecret' object has no attribute 'repr'
$

# Fixed code
def repr(self):
    return dict([(k, v) for k, v in self._asdict().items() if v is not None])
# Buggy code
def repr(self):
    if self.target == self.alias:
        return self.target
    return "{s.target}:{s.alias}".format(s=self)


# Traceback (AttributeError)
$ docker-compose up
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose/cli/main.py", line 88, in main
File "compose/cli/main.py", line 137, in perform_command
File "compose/cli/command.py", line 36, in project_from_options
File "compose/cli/command.py", line 115, in get_project
File "compose/project.py", line 110, in from_config
File "compose/project.py", line 566, in get_secrets
AttributeError: 'str' object has no attribute 'source'
Failed to execute script docker-compose

# Fixed code
def repr(self):
    return dict(
        source=self.source,
        target=self.target,
        uid=self.uid,
        gid=self.gid,
        mode=self.mode,
    )
# Buggy code
def format_environment(environment):
    def format_env(key, value):
        if value is None:
            return key
        return "{key}={value}".format(key=key, value=value)

    return [format_env(*item) for item in environment.items()]


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "compose/cli/main.py", line 56, in main
File "compose/cli/docopt_command.py", line 23, in sys_dispatch
File "compose/cli/docopt_command.py", line 26, in dispatch
File "compose/cli/main.py", line 191, in perform_command
File "compose/cli/main.py", line 657, in up
File "compose/project.py", line 318, in up
File "compose/service.py", line 370, in execute_convergence_plan
File "compose/service.py", line 410, in recreate_container
File "compose/service.py", line 258, in create_container
File "compose/service.py", line 625, in _get_container_create_options
File "compose/service.py", line 1031, in format_environment
File "compose/service.py", line 1030, in format_env
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 7: ordinal not in range(128)
docker-compose returned -1
make: *** [run_compose_up] Error 255

# Fixed code
def format_environment(environment):
    def format_env(key, value):
        if value is None:
            return key
        if isinstance(value, six.binary_type):
            value = value.decode("utf-8")
        return "{key}={value}".format(key=key, value=value)

    return [format_env(*item) for item in environment.items()]
# Buggy code
def format_env(key, value):
    if value is None:
        return key
    return "{key}={value}".format(key=key, value=value)


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "compose/cli/main.py", line 56, in main
File "compose/cli/docopt_command.py", line 23, in sys_dispatch
File "compose/cli/docopt_command.py", line 26, in dispatch
File "compose/cli/main.py", line 191, in perform_command
File "compose/cli/main.py", line 657, in up
File "compose/project.py", line 318, in up
File "compose/service.py", line 370, in execute_convergence_plan
File "compose/service.py", line 410, in recreate_container
File "compose/service.py", line 258, in create_container
File "compose/service.py", line 625, in _get_container_create_options
File "compose/service.py", line 1031, in format_environment
File "compose/service.py", line 1030, in format_env
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 7: ordinal not in range(128)
docker-compose returned -1
make: *** [run_compose_up] Error 255

# Fixed code
def format_env(key, value):
    if value is None:
        return key
    if isinstance(value, six.binary_type):
        value = value.decode("utf-8")
    return "{key}={value}".format(key=key, value=value)
# Buggy code
def get_project(
    project_dir,
    config_path=None,
    project_name=None,
    verbose=False,
    host=None,
    tls_config=None,
    environment=None,
):
    if not environment:
        environment = Environment.from_env_file(project_dir)
    config_details = config.find(project_dir, config_path, environment)
    project_name = get_project_name(
        config_details.working_dir, project_name, environment
    )
    config_data = config.load(config_details)

    api_version = environment.get(
        "COMPOSE_API_VERSION", API_VERSIONS[config_data.version]
    )

    client = get_client(
        verbose=verbose,
        version=api_version,
        tls_config=tls_config,
        host=host,
        environment=environment,
    )

    return Project.from_config(project_name, config_data, client)


# Traceback (requests.exceptions.ConnectionError)
➜  ehnv git:(dev) docker-compose up
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "compose/cli/main.py", line 60, in main
File "compose/cli/main.py", line 108, in perform_command
File "compose/cli/command.py", line 35, in project_from_options
File "compose/cli/command.py", line 112, in get_project
File "compose/project.py", line 100, in from_config
File "compose/project.py", line 533, in get_volumes_from
File "compose/project.py", line 522, in build_volume_from
File "compose/container.py", line 42, in from_id
File "site-packages/docker/utils/decorators.py", line 21, in wrapped
File "site-packages/docker/api/container.py", line 182, in inspect_container
File "site-packages/docker/utils/decorators.py", line 47, in inner
File "site-packages/docker/client.py", line 138, in _get
File "site-packages/requests/sessions.py", line 477, in get
File "site-packages/requests/sessions.py", line 465, in request
File "site-packages/requests/sessions.py", line 573, in send
File "site-packages/requests/adapters.py", line 415, in send
requests.exceptions.ConnectionError: ('Connection aborted.', error(2, 'No such file or directory'))

# Fixed code
def get_project(
    project_dir,
    config_path=None,
    project_name=None,
    verbose=False,
    host=None,
    tls_config=None,
    environment=None,
):
    if not environment:
        environment = Environment.from_env_file(project_dir)
    config_details = config.find(project_dir, config_path, environment)
    project_name = get_project_name(
        config_details.working_dir, project_name, environment
    )
    config_data = config.load(config_details)

    api_version = environment.get(
        "COMPOSE_API_VERSION", API_VERSIONS[config_data.version]
    )

    client = get_client(
        verbose=verbose,
        version=api_version,
        tls_config=tls_config,
        host=host,
        environment=environment,
    )

    with errors.handle_connection_errors(client):
        return Project.from_config(project_name, config_data, client)