internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: encode/uvicorn

Issue:
Passing `reload_dirs` as a string instead of a list
@Roang-zero1 @euri10 @Kludex this PR introduced a regression and deleted the test for it (`test_reload_dir_is_set()`). Previously you could pass `reload_dirs` a string instead of a list. Now:
```python
Config('myapp:app', reload=True, reload_dirs='src')
```
prints:
```
WARNING:  Provided reload directories ['r', 'c', 's'] did not contain valid directories, watching current working directory.
```
https://github.com/encode/uvicorn/pull/820/files#diff-6982a5e270879281f9182303a9da9776148857b46325afb230e50ef8eb3264c9R294
(Of course, `set` expects an iterable... and strings are iterables of chars.)

_Originally posted by @HansBrende in https://github.com/encode/uvicorn/issues/820#issuecomment-977957988_


Discussion:
happy to take a PR on this @HansBrende 
Sure, why not.

Resolving patch:
diff --git a/uvicorn/config.py b/uvicorn/config.py
--- a/uvicorn/config.py
+++ b/uvicorn/config.py
@@ -180,7 +180,15 @@ def resolve_reload_patterns(
 
     directories = list(set(directories).difference(set(children)))
 
-    return (list(set(patterns)), directories)
+    return list(set(patterns)), directories
+
+
+def _normalize_dirs(dirs: Union[List[str], str, None]) -> List[str]:
+    if dirs is None:
+        return []
+    if isinstance(dirs, str):
+        return [dirs]
+    return list(set(dirs))
 
 
 class Config:
@@ -291,9 +299,9 @@ def __init__(
             )
 
         if self.should_reload:
-            reload_dirs = list(set(reload_dirs)) if reload_dirs else []
-            reload_includes = list(set(reload_includes)) if reload_includes else []
-            reload_excludes = list(set(reload_excludes)) if reload_excludes else []
+            reload_dirs = _normalize_dirs(reload_dirs)
+            reload_includes = _normalize_dirs(reload_includes)
+            reload_excludes = _normalize_dirs(reload_excludes)
 
             self.reload_includes, self.reload_dirs = resolve_reload_patterns(
                 reload_includes, reload_dirs


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -119,6 +119,10 @@ def test_reload_dir_is_set(
             == f"Will watch for changes in these directories: {[str(app_dir)]}"
         )
         assert config.reload_dirs == [app_dir]
+        config = Config(
+            app="tests.test_config:asgi_app", reload=True, reload_dirs=str(app_dir)
+        )
+        assert config.reload_dirs == [app_dir]
 
 
 def test_non_existant_reload_dir_is_not_set(
Repository: encode/uvicorn

Issue:
Include a environment variable to change arg commands
Hello,

I'm testing the FASTAPI (https://fastapi.tiangolo.com/) and there's a nice environment variable when running with gunicorn (https://docs.gunicorn.org/en/stable/settings.html#settings) `GUNICORN_CMD_ARGS`, it include command line args using enviroment variables

this is very usefull when using docker compose, or k8s. without rebuild the container i can change how it starts (more debug messages instead of only critical)

could be possible include a enviroment at uvicorn? `UVICORN_CMD_ARGS`

the gunicorn_cmd_args implementation can be saw here:

https://github.com/benoitc/gunicorn/blob/ee685e197b3f7cf899dc7d6e0688ff169e9d10df/gunicorn/app/base.py#L171

https://github.com/benoitc/gunicorn/blob/6aab4decde5735fc77daf4fecaf9ef3632189f62/gunicorn/config.py#L79


thanks!


Discussion:
reading click pypi, maybe something could be done here:

https://click.palletsprojects.com/en/7.x/options/#values-from-environment-variables
https://github.com/encode/uvicorn/blob/d9d7bc6b38d07a4187882a2d49d92f1640c2446c/uvicorn/__main__.py#L4


maybe instead of:

```
    uvicorn.main()
```

use 
```
    uvicorn.main(auto_envvar_prefix='UVICORN')
```

+1 to this! 

Resolving patch:
diff --git a/uvicorn/main.py b/uvicorn/main.py
--- a/uvicorn/main.py
+++ b/uvicorn/main.py
@@ -48,7 +48,7 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
     ctx.exit()
 
 
-@click.command()
+@click.command(context_settings={"auto_envvar_prefix": "UVICORN"})
 @click.argument("app")
 @click.option(
     "--host",


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1,4 +1,5 @@
 import importlib
+import os
 import platform
 import sys
 from pathlib import Path
@@ -17,6 +18,10 @@
 main = importlib.import_module("uvicorn.main")
 
 
+class App:
+    pass
+
+
 def test_cli_print_version() -> None:
     runner = CliRunner()
 
@@ -131,5 +136,26 @@ def test_cli_reloader_incomplete_app_parameter(
     ) in captured.err
 
 
-class App:
-    pass
+@pytest.fixture()
+def load_env_h11_protocol():
+    old_environ = dict(os.environ)
+    os.environ["UVICORN_HTTP"] = "h11"
+    yield
+    os.environ.clear()
+    os.environ.update(old_environ)
+
+
+def test_env_variables(load_env_h11_protocol: None):
+    runner = CliRunner(env=os.environ)
+    with mock.patch.object(main, "run") as mock_run:
+        runner.invoke(cli, ["tests.test_cli:App"])
+        _, kwargs = mock_run.call_args
+        assert kwargs["http"] == "h11"
+
+
+def test_mistmatch_env_variables(load_env_h11_protocol: None):
+    runner = CliRunner(env=os.environ)
+    with mock.patch.object(main, "run") as mock_run:
+        runner.invoke(cli, ["tests.test_cli:App", "--http=httptools"])
+        _, kwargs = mock_run.call_args
+        assert kwargs["http"] == "httptools"
Repository: encode/uvicorn

Issue:
No `python_requires` defined
### Checklist

- [X] The bug is reproducible against the latest release or `master`.
- [X] There are no similar issues or pull requests to fix it yet.

### Describe the bug

It seems that no `python_requires` is defined for the `uvicorn` package, which in turn results in the latest version being installed in a Python 3.6 (CI) environment (that subsequently fails).

If `python_requires` were defined to restrict the package to supported versions of the interpreter, I would have got an older version (that supported `py36`) instead.

### Steps to reproduce the bug

In a `py36` environment
```
pip install uvicorn
# Run uvicorn
# ...
```

### Expected behavior

An older version is installed that works.

### Actual behavior

`uvicorn` errors out, says `py36` is unsupported.

### Debugging material

_No response_

### Environment

CPython 3.6

### Additional context

_No response_


Discussion:
PR welcome to add `python_requires`.
Thanks @Kludex, I'll try to open one later today!
(Although it's obviously too late for the 3.6 case unless you are willing to yank the current version later.)
I don't have the power to yank the current version. We should ask @tomchristie for that, but I'm not sure if it's that necessary.

The recommendation on `zero version` is to pin the package version.

In any case, that line of code will be useful in the future.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -73,6 +73,7 @@ def get_packages(package):
     author="Tom Christie",
     author_email="tom@tomchristie.com",
     packages=get_packages("uvicorn"),
+    python_requires=">=3.7",
     install_requires=minimal_requirements,
     extras_require={"standard": extra_requirements},
     include_package_data=True,


Test patch:
Repository: encode/uvicorn

Issue:
Latest version breaks something in the h11 implementation
I'm using uvicorn to run a FastAPI application. I just download the latest uvicorn version 0.18.0 and got the following error when trying to run my app:
```
Fatal error: protocol.data_received() call failed.
protocol: <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x7fcbc87089a0>
transport: <_SelectorSocketTransport fd=11 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/.../python3.9/asyncio/selector_events.py", line 870, in _read_ready__data_received
    self._protocol.data_received(data)
  File "/.../venv/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 161, in data_received
    self.handle_events()
  File "/.../venv/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 166, in handle_events
    event = self.conn.next_event()
  File "/.../venv/lib/python3.9/site-packages/h11/_connection.py", line 471, in next_event
    if len(self._receive_buffer) > self._max_incomplete_event_size:
TypeError: '>' not supported between instances of 'int' and 'NoneType'
```
(I removed the full paths)

When going back to version 0.17.0, I don't encounter this error...

Please let me know if there is more details I can share.


Discussion:

Resolving patch:
diff --git a/uvicorn/main.py b/uvicorn/main.py
--- a/uvicorn/main.py
+++ b/uvicorn/main.py
@@ -346,7 +346,7 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
     "--h11-max-incomplete-event-size",
     "h11_max_incomplete_event_size",
     type=int,
-    default=None,
+    default=DEFAULT_MAX_INCOMPLETE_EVENT_SIZE,
     help="For h11, the maximum number of bytes to buffer of an incomplete event.",
 )
 @click.option(


Test patch:
Repository: encode/uvicorn

Issue:
Uvicorn assumes that `HTTPResponseStartEvent.headers` is a `List`
### Discussed in https://github.com/encode/uvicorn/discussions/1779

<div type='discussions-op-text'>

<sup>Originally posted by **rijenkii** November 27, 2022</sup>
According to the spec and asgiref, `HTTPResponseStartEvent.headers` is `Iterable[Tuple[bytes, bytes]]`.

But, if `http.response.start` is sent like this:
```python
headers: dict
await send({
  "type": "http.response.start",
  "status": status,
  "headers": headers.items(),
})
```

Uvicorn fails with
```
  File ".../uvicorn/protocols/http/h11_impl.py", line 474, in send
    headers = self.default_headers + message_headers
              ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
TypeError: can only concatenate list (not "dict_items") to list
```

Relevant Uvicorn code: https://github.com/encode/uvicorn/blob/782f17e3855d5f36ce69d55427e74ca7f9b998c5/uvicorn/protocols/http/h11_impl.py#L471-L474

---

Potential fix may just be this:
```python
message_headers = list(message.get("headers", [])) 
```


Discussion:

Resolving patch:
diff --git a/uvicorn/protocols/http/h11_impl.py b/uvicorn/protocols/http/h11_impl.py
--- a/uvicorn/protocols/http/h11_impl.py
+++ b/uvicorn/protocols/http/h11_impl.py
@@ -468,10 +468,7 @@ async def send(self, message: "ASGISendEvent") -> None:
             self.waiting_for_100_continue = False
 
             status_code = message["status"]
-            message_headers = cast(
-                List[Tuple[bytes, bytes]], message.get("headers", [])
-            )
-            headers = self.default_headers + message_headers
+            headers = self.default_headers + list(message.get("headers", []))
 
             if CLOSE_HEADER in self.scope["headers"] and CLOSE_HEADER not in headers:
                 headers = headers + [CLOSE_HEADER]


Test patch:
diff --git a/tests/protocols/test_http.py b/tests/protocols/test_http.py
--- a/tests/protocols/test_http.py
+++ b/tests/protocols/test_http.py
@@ -966,3 +966,17 @@ async def test_return_close_header(protocol_cls, close_header: bytes):
     assert b"content-type: text/plain" in protocol.transport.buffer
     assert b"content-length: 12" in protocol.transport.buffer
     assert close_header in protocol.transport.buffer
+
+
+@pytest.mark.anyio
+@pytest.mark.parametrize("protocol_cls", HTTP_PROTOCOLS)
+async def test_iterator_headers(protocol_cls):
+    async def app(scope, receive, send):
+        headers = iter([(b"x-test-header", b"test value")])
+        await send({"type": "http.response.start", "status": 200, "headers": headers})
+        await send({"type": "http.response.body", "body": b""})
+
+    protocol = get_connected_protocol(app, protocol_cls)
+    protocol.data_received(SIMPLE_GET_REQUEST)
+    await protocol.loop.run_one()
+    assert b"x-test-header: test value" in protocol.transport.buffer
Repository: facebookresearch/Mephisto

Issue:
Path changes in cleanup scripts
In `mephisto/scripts/mturk/cleanup.py`:  broken imports line 11-15 with the change from `core` and `providers` into `abstraction` - can also submit a PR if that's easier!


Discussion:

Resolving patch:
diff --git a/mephisto/scripts/mturk/cleanup.py b/mephisto/scripts/mturk/cleanup.py
--- a/mephisto/scripts/mturk/cleanup.py
+++ b/mephisto/scripts/mturk/cleanup.py
@@ -8,11 +8,11 @@
 Utility script that finds, expires, and disposes HITs that may not
 have been taking down during a run that exited improperly.
 """
-from mephisto.providers.mturk.mturk_utils import (
+from mephisto.abstractions.providers.mturk.mturk_utils import (
     get_outstanding_hits,
     expire_and_dispose_hits,
 )
-from mephisto.core.local_database import LocalMephistoDB
+from mephisto.abstractions.databases.local_database import LocalMephistoDB
 
 db = LocalMephistoDB()
 


Test patch:
Repository: facebookresearch/Mephisto

Issue:
NameError: name 'Blueprint' is not defined
Hi!

I wanted to try the project from the "quickstart" but I hit

>NameError: name 'Blueprint' is not defined

After running these steps:

```bash
pip install -e .
mkdir ~/data
mephisto config core.main_data_directory ~/data
mephisto check
# OK
cd examples/simple_static_task
python static_test_script.py
```

Any idea? Seems to be related to Flask.


Discussion:
Hi @louis030195 - can you provide the full error traceback? Flask installation shouldn't be necessary to run Mephisto, so I'd like to wrap any flask mention in a conditional import. (Though in the meantime, pip installing flask should resolve).
+1

pip install flask does not resolve

looks like requirements might be checked in the wrong order?

here is the trace

python3 static_test_script.py
/opt/homebrew/lib/python3.8/site-packages/hydra/_internal/defaults_list.py:251: UserWarning: In 'scriptconfig': Defaults list is missing `_self_`. See https://hydra.cc/docs/upgrades/1.0_to_1.1/default_composition_order for more information
  warnings.warn(msg, UserWarning)
[2021-11-01 12:50:33,586][mephisto.operations.operator][ERROR] - Ran into error while launching run: 
Traceback (most recent call last):
  File "/Users/.../Mephisto/mephisto/operations/operator.py", line 429, in validate_and_run_config
    return self.validate_and_run_config_or_die(
  File "/Users/.../Mephisto/mephisto/operations/operator.py", line 169, in validate_and_run_config_or_die
    BlueprintClass.assert_task_args(run_config, shared_state)
  File "/Users/.../Mephisto/mephisto/abstractions/blueprints/static_html_task/static_html_blueprint.py", line 110, in assert_task_args
    Blueprint.assert_task_args(args, shared_state)
NameError: name 'Blueprint' is not defined
[2021-11-01 12:50:33,587][mephisto.operations.operator][INFO] - operator shutting down
Thanks - reproduced, fix coming out shortly. Sorry for the inconvenience!

Resolving patch:
diff --git a/mephisto/abstractions/blueprints/static_html_task/static_html_blueprint.py b/mephisto/abstractions/blueprints/static_html_task/static_html_blueprint.py
--- a/mephisto/abstractions/blueprints/static_html_task/static_html_blueprint.py
+++ b/mephisto/abstractions/blueprints/static_html_task/static_html_blueprint.py
@@ -10,6 +10,7 @@
 )
 from dataclasses import dataclass, field
 from omegaconf import MISSING, DictConfig
+from mephisto.abstractions.blueprint import Blueprint
 from mephisto.abstractions.blueprints.static_html_task.static_html_task_builder import (
     StaticHTMLTaskBuilder,
 )


Test patch:
Repository: facebookresearch/Mephisto

Issue:
Mephisto register doesn't work properly when registering for both MTurk and MTurk Sandbox
This issue is regarding an issue with `mephisto register`. When registering for both MTurk sandbox and MTurk

Here are steps to reproduce the issue:

The original `~/.aws/credentials file` looks like this

```
[default]
aws_access_key_id=<ACCESS KEY>
aws_secret_access_key=<SECRET KEY>
```

Then I register on MTurk sandbox:
```
$ mephisto register mturk_sandbox name=my_mturk_user_sandbox access_key_id=<ACCESS KEY> secret_access_key=<SECRET KEY>
AWS credentials successfully saved in ~/.aws/credentials file
```

After this the `~/.aws/credentials file` file looks like the following:
```
[default]
aws_access_key_id=<ACCESS KEY>
aws_secret_access_key=<SECRET KEY>

[my_mturk_user]
aws_access_key_id=<ACCESS KEY>
aws_secret_access_key=<SECRET KEY>
```

Next, I register for MTurk:
```
$ mephisto register mturk name=my_mturk_user access_key_id=<ACCESS KEY> secret_access_key=<SECRET KEY>
We found an existing entry for my_mturk_user. As new credentials have been provided, we're updating the credentials, overwriting ones that already existed for the profile
Registered successfully.
```

Although the message says `Registered successfully`, the `~/.aws/credentials file` now looks like this:
```
[default]
aws_access_key_id=<ACCESS KEY>
aws_secret_access_key=<SECRET KEY>

[my_mturk_user]
aws_access_key_id=<ACCESS KEY>

aws_access_key_id=<ACCESS KEY>
```

`aws_secret_access_key` is no longer there for `my_mturk_user`, which causes the launch to fail


Python version: 3.8.9
OS Version: macOS Big Sur version 11.6.4


Discussion:

Resolving patch:
diff --git a/mephisto/abstractions/providers/mturk/mturk_utils.py b/mephisto/abstractions/providers/mturk/mturk_utils.py
--- a/mephisto/abstractions/providers/mturk/mturk_utils.py
+++ b/mephisto/abstractions/providers/mturk/mturk_utils.py
@@ -81,10 +81,12 @@ def setup_aws_credentials(
                 ):
                     aws_credentials[
                         credentialIndex + 1
-                    ] = "aws_access_key_id={}\n".format(register_args.access_key_id)
+                    ] = "aws_access_key_id={}".format(register_args.access_key_id)
                     aws_credentials[
                         credentialIndex + 2
-                    ] = "aws_access_key_id={}\n".format(register_args.access_key_id)
+                    ] = "aws_secret_access_key={}".format(
+                        register_args.secret_access_key
+                    )
                     break
 
             with open(expanded_aws_file_path, "w") as aws_credentials_file:


Test patch:
Repository: facebookresearch/Mephisto

Issue:
Errors when installing new dependencies
## Overview
Adding a new dependency into requirements.txt causes errors to occur in the github actions workflow.

For example, 
When I added the `rich` dependency to the requirements.txt file I got this output for the test:
https://github.com/facebookresearch/Mephisto/runs/7237323897?check_suite_focus=true

The issue is not exclusive to `rich` as I also got this error when trying to add the `detoxify` dependency.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
deleted file mode 100644
--- a/setup.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright (c) Facebook, Inc. and its affiliates.
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
-
-from setuptools import setup, find_packages
-import os
-
-here = os.path.abspath(os.path.dirname(__file__))
-
-with open("README.md", encoding="utf8") as f:
-    # strip the header and badges etc
-    readme = f.read()
-
-with open("requirements.txt") as f:
-    reqs = f.readlines()
-    reqs = [r for r in reqs if "--hash" not in r]
-    reqs = [r.split("\\")[0].split(";")[0].strip() for r in reqs]
-
-with open(os.path.join(here, "mephisto", "VERSION")) as version_file:
-    version = version_file.read().strip()
-
-setup(
-    name="mephisto",
-    version=version,
-    description="Crowdsourcing made simpler.",
-    author="Jack Urbanek, Pratik Ringshia",
-    author_email="jju@fb.com",
-    long_description=readme,
-    long_description_content_type="text/markdown",
-    url="https://github.com/facebookresearch/Mephisto",
-    python_requires=">=3.7",
-    packages=find_packages(include=["mephisto.*", "hydra_plugins.*"]),
-    license="MIT",
-    install_requires=reqs,
-    include_package_data=True,
-    package_data={"mephisto": ["*.yaml", "abstractions/**/*"]},
-    zip_safe=False,
-    entry_points={"console_scripts": "mephisto=mephisto.client.cli:cli"},
-    classifiers=[
-        "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.7",
-        "Programming Language :: Python :: 3.8",
-        "License :: OSI Approved :: MIT License",
-        "Topic :: Scientific/Engineering :: Artificial Intelligence",
-        "Natural Language :: English",
-    ],
-)


Test patch:
Repository: facebookresearch/Mephisto

Issue:
Make URLs in terminal output clickable on launch
<img width="1028" alt="CleanShot 2022-07-15 at 10 43 57@2x" src="https://user-images.githubusercontent.com/425059/179247049-927a78f7-d6fd-414c-8d60-5732cc6393a3.png">

It's annoying to have to copy and paste the URLs from the terminal output into a browesr on task launch.

```
# change:

localhost:3000/?worker_id=x&assignment_id=1

# to:

http://localhost:3000/?worker_id=x&assignment_id=1
```

Adding a protocol (http: / https://) before the URL will make it easy to simply click on them to open (in some terminals). We should add this.

---

Note: I'm not sure if we need to decide between http or https based on certain scenarios


Discussion:

Resolving patch:
diff --git a/mephisto/abstractions/providers/mock/mock_unit.py b/mephisto/abstractions/providers/mock/mock_unit.py
--- a/mephisto/abstractions/providers/mock/mock_unit.py
+++ b/mephisto/abstractions/providers/mock/mock_unit.py
@@ -49,12 +49,12 @@ def launch(self, task_url: str) -> None:
         port = task_url.split(":")[1].split("/")[0]
         print(task_url)
         print(
-            f"Mock task launched: localhost:{port} for preview, "
-            f"localhost:{port}/?worker_id=x&assignment_id={self.db_id}"
+            f"Mock task launched: http://localhost:{port} for preview, "
+            f"http://localhost:{port}/?worker_id=x&assignment_id={self.db_id}"
         )
         logger.info(
-            f"Mock task launched: localhost:{port} for preview, "
-            f"localhost:{port}/?worker_id=x&assignment_id={self.db_id} for assignment {self.assignment_id}"
+            f"Mock task launched: http://localhost:{port} for preview, "
+            f"http://localhost:{port}/?worker_id=x&assignment_id={self.db_id} for assignment {self.assignment_id}"
         )
 
         return None


Test patch: