Skip to content

Add black to the auto directory #2514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/2514.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add black checks to ``web3/auto``
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ basepython=python
extras=linter
commands=
flake8 {toxinidir}/web3 {toxinidir}/ens {toxinidir}/ethpm {toxinidir}/tests --exclude {toxinidir}/ethpm/ethpm-spec
black {toxinidir}/ethpm {toxinidir}/web3/utils --exclude {toxinidir}/ethpm/ethpm-spec --check
black {toxinidir}/ethpm {toxinidir}/web3/auto {toxinidir}/web3/utils --exclude {toxinidir}/ethpm/ethpm-spec --check
isort --recursive --check-only --diff {toxinidir}/web3/ {toxinidir}/ens/ {toxinidir}/ethpm/ {toxinidir}/tests/
mypy -p web3 -p ethpm -p ens --config-file {toxinidir}/mypy.ini

Expand Down
31 changes: 16 additions & 15 deletions web3/auto/infura/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@
InfuraKeyNotFound,
)

INFURA_MAINNET_DOMAIN = 'mainnet.infura.io'
INFURA_ROPSTEN_DOMAIN = 'ropsten.infura.io'
INFURA_GOERLI_DOMAIN = 'goerli.infura.io'
INFURA_RINKEBY_DOMAIN = 'rinkeby.infura.io'
INFURA_KOVAN_DOMAIN = 'kovan.infura.io'
INFURA_MAINNET_DOMAIN = "mainnet.infura.io"
INFURA_ROPSTEN_DOMAIN = "ropsten.infura.io"
INFURA_GOERLI_DOMAIN = "goerli.infura.io"
INFURA_RINKEBY_DOMAIN = "rinkeby.infura.io"
INFURA_KOVAN_DOMAIN = "kovan.infura.io"

WEBSOCKET_SCHEME = 'wss'
HTTP_SCHEME = 'https'
WEBSOCKET_SCHEME = "wss"
HTTP_SCHEME = "https"


def load_api_key() -> str:
# in web3py v6 remove outdated WEB3_INFURA_API_KEY
key = os.environ.get('WEB3_INFURA_PROJECT_ID',
os.environ.get('WEB3_INFURA_API_KEY', ''))
if key == '':
key = os.environ.get(
"WEB3_INFURA_PROJECT_ID", os.environ.get("WEB3_INFURA_API_KEY", "")
)
if key == "":
raise InfuraKeyNotFound(
"No Infura Project ID found. Please ensure "
"that the environment variable WEB3_INFURA_PROJECT_ID is set."
Expand All @@ -39,25 +40,25 @@ def load_api_key() -> str:


def load_secret() -> str:
return os.environ.get('WEB3_INFURA_API_SECRET', '')
return os.environ.get("WEB3_INFURA_API_SECRET", "")


def build_http_headers() -> Optional[Dict[str, Tuple[str, str]]]:
secret = load_secret()
if secret:
headers = {'auth': ('', secret)}
headers = {"auth": ("", secret)}
return headers
return None


def build_infura_url(domain: str) -> URI:
scheme = os.environ.get('WEB3_INFURA_SCHEME', WEBSOCKET_SCHEME)
scheme = os.environ.get("WEB3_INFURA_SCHEME", WEBSOCKET_SCHEME)
key = load_api_key()
secret = load_secret()

if scheme == WEBSOCKET_SCHEME and secret != '':
if scheme == WEBSOCKET_SCHEME and secret != "":
return URI(f"{scheme}://:{secret}@{domain}/ws/v3/{key}")
elif scheme == WEBSOCKET_SCHEME and secret == '':
elif scheme == WEBSOCKET_SCHEME and secret == "":
return URI(f"{scheme}://{domain}/ws/v3/{key}")
elif scheme == HTTP_SCHEME:
return URI(f"{scheme}://{domain}/v3/{key}")
Expand Down