Skip to content

Commit

Permalink
ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bmos committed Dec 30, 2023
1 parent f97a663 commit 1e6771d
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 23 deletions.
30 changes: 7 additions & 23 deletions license_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,15 @@ def license_details(ltr_license: str) -> dict:

def get_label(data: dict) -> str:
"""Find an return the most human-readable field name available"""
return (
data["Label"]
or data["FieldName"]
or data["CustomField"]
or str(data["Id"])
or ""
)
return data["Label"] or data["FieldName"] or data["CustomField"] or str(data["Id"]) or ""

def get_value(licensedata: dict) -> dict:
"""Find an return the value of each data field in a license"""
if licensedata["CustomFieldTableRows"] is None:
return licensedata["Value"]

return {
unit["Column0"]["Value"]: {
get_label(unit[column]): unit[column]["Value"]
for column in unit
if column.startswith("Column") and unit[column]
}
unit["Column0"]["Value"]: {get_label(unit[column]): unit[column]["Value"] for column in unit if column.startswith("Column") and unit[column]}
for unit in licensedata["CustomFieldTableRows"]
}

Expand All @@ -60,14 +50,10 @@ def get_value(licensedata: dict) -> dict:
}

# print(f"Getting ltr_license details for {ltr_license}.")
response_json = s.post(LICENSE_URL, headers=headers, json=payload).json()["Result"][
"CustomGroups"
][0]["CustomFields"]
response_json = s.post(LICENSE_URL, headers=headers, json=payload).json()["Result"]["CustomGroups"][0]["CustomFields"]

sleep(0.5)
return {
get_label(licensedata): get_value(licensedata) for licensedata in response_json
}
return {get_label(licensedata): get_value(licensedata) for licensedata in response_json}


def license_compiler() -> pd.DataFrame:
Expand Down Expand Up @@ -349,9 +335,7 @@ def license_query(licensetype: str, page_num: int) -> (int, list):
"SortBy": "relevance",
"SortAscending": True,
}
result = (
s.post(QUERY_URL, headers=headers, json=payload).json().get("Result", {})
)
result = s.post(QUERY_URL, headers=headers, json=payload).json().get("Result", {})
return result.get("TotalPages", 0), result.get("EntityResults", [])

licenses = []
Expand All @@ -365,7 +349,7 @@ def license_query(licensetype: str, page_num: int) -> (int, list):

print(f"Retrieving all {license_pages_total} pages of {licensetype}.")
pagenumbers = range(2, license_pages_total + 1)
for n in tqdm(pagenumbers, unit='page', initial=1, total=len(pagenumbers)+1):
for n in tqdm(pagenumbers, unit="page", initial=1, total=len(pagenumbers) + 1):
license_pages_total, licenses_found = license_query(licensetype, n)
licenses.extend(licenses_found)

Expand All @@ -378,7 +362,7 @@ def license_query(licensetype: str, page_num: int) -> (int, list):

# Create new `pandas` methods which use `tqdm` progress
# (can use tqdm_gui, optional kwargs, etc.)
tqdm.pandas(unit='licenses')
tqdm.pandas(unit="licenses")

# Add detail from individual license pages
print(f"Downloading license details for all {len(df['CaseId'])} licenses.")
Expand Down
78 changes: 78 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

# Same as Black.
line-length = 160
indent-width = 4

# Set Python 3.9 as minimum version
target-version = "py39"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F", "B"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = true

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"

0 comments on commit 1e6771d

Please sign in to comment.