Skip to content

Commit

Permalink
Transition to Ruff (tianocore#324)
Browse files Browse the repository at this point in the history
Transitions project maintenance, building, and distribution to
the pyproject.toml file. This also allows many of the python
configuration files to be moved into the pyproject.toml file themselves.

Updates CI yaml steps (azure pipelines and github action) to download
pip requirements via the pyproject.toml rather then a requirements file.
  • Loading branch information
Javagedes authored May 11, 2023
1 parent 430bff4 commit bb1e428
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 33 deletions.
8 changes: 4 additions & 4 deletions .githooks/advanced-pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ repos:
hooks:
- id: cspell
types_or: [markdown, python]
- repo: https://github.com/PyCQA/flake8
rev: 3.8.4
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.265"
hooks:
- id: flake8
entry: flake8 edk2toollib
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.12.0
hooks:
Expand Down
8 changes: 4 additions & 4 deletions .githooks/basic-pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ repos:
hooks:
- id: cspell
types_or: [markdown, python]
- repo: https://github.com/PyCQA/flake8
rev: 3.8.4
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.265"
hooks:
- id: flake8
entry: flake8 edk2toollib
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.12.0
hooks:
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/CIRunner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ jobs:
npm install -g [email protected]
npm install -g [email protected]
- name: Run flake8
- name: Run ruff
if: success() || failure()
run: flake8 ${{ inputs.package-src }}
run: ruff check ${{ inputs.package-src }} --format=github

- name: Run markdownlint
if: success() || failure()
Expand All @@ -64,10 +64,6 @@ jobs:
if: success() || failure()
run: cspell -c .cspell.json "**/*.py" "**/*.md"

- name: Run pydocstyle
if: success() || failure()
run: pydocstyle ${{ inputs.package-src }}

- name: Run mkdocs build
if: success() || failure()
run: mkdocs build --strict
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ build.
flake8.err.log
/.eggs
/htmlcov
/.ruff_cache
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["charliermarsh.ruff"]
}
9 changes: 6 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"${workspaceRoot}/edk2toollib/tests",
],
"python.testing.unittestEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.linting.pydocstyleEnabled": true
"[python]": {
"editor.defaultFormatter": null,
"editor.codeActionsOnSave": {
"source.fixAll.ruff": true,
}
}
}
12 changes: 6 additions & 6 deletions edk2toollib/uefi/authenticated_variables_structure_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,12 @@ def GetCanonicalAndDupes(self):
Returns:
(Tuple[EfiSignatureDatabase, EfiSignatureDatabase]): (canonical, duplicates)
NOTE:
canonical is an EfiSignatureDatabase where EfiSignatureLists are merged (where possible),
deduplicated, & sorted, and the EfiSignatureData elements are also deduplicated & sorted
duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated
EfiSignatureData entries (only the data contents are checked for effective equality,
signature owner is ignored)
!!! note
canonical is an EfiSignatureDatabase where EfiSignatureLists are merged (where possible),
deduplicated, & sorted, and the EfiSignatureData elements are also deduplicated & sorted
duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated
EfiSignatureData entries (only the data contents are checked for effective equality,
signature owner is ignored)
"""
# First group EFI_SIGNATURE_LISTS by type, merging them where possible

Expand Down
4 changes: 2 additions & 2 deletions edk2toollib/uefi/edk2/guid_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def parse_guids_from_dec(stream, filename: str) -> list:

try:
results.append(GuidListEntry(dec.Dict["PACKAGE_NAME"], dec.Dict["PACKAGE_GUID"], filename))
except:
except Exception:
logging.warning("Failed to find Package Guid from dec file: " + filename)
return results

Expand All @@ -131,6 +131,6 @@ def parse_guids_from_inf(filename: str) -> list:
inf.ParseFile(filename)
try:
return [GuidListEntry(inf.Dict["BASE_NAME"], inf.Dict["FILE_GUID"].upper(), filename)]
except:
except Exception:
logging.warning("Failed to find info from INF file: " + filename)
return []
2 changes: 1 addition & 1 deletion edk2toollib/uefi/edk2/parsers/guid_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def reg_guid_from_c_format(cls, guidstring: str) -> str:
int(guidValueList[9], 16),
int(guidValueList[10], 16)
)
except:
except Exception:
return ''

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions edk2toollib/utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ def hexdump(byte_list, offset_start=0, out_fs=sys.stdout, **kwargs) -> None:
byte_list (bytearray): byte array to print
offset_start (int): offset to print to the side of the hexdump
out_fs (io.BytesIO): output file stream to print to
kwargs (any): keyword arguments expanded below.
Keyword Arguments:
include_ascii (bool): Option (Default: True) to include ascii
Expand Down Expand Up @@ -496,6 +497,7 @@ def export_c_type_array(buffer_fs, variable_name, out_fs, **kwargs) -> None:
buffer_fs (io.BytesIO): buffer file stream to turn into a C style array
variable_name (str): variable name to use for the C style array
out_fs (io.StringIO): output filestream to write to
kwargs (any): keyword arguments expanded below.
Keyword Arguments:
data_type (str): The datatype of the array (Default: UINT8)
Expand All @@ -507,6 +509,7 @@ def export_c_type_array(buffer_fs, variable_name, out_fs, **kwargs) -> None:
include_ascii (bool): includes a ascii comment to side of hex
include_length (bool): includes length in the decleration of array
(ex. "UINT8 TestVariable[13] = {")
Return:
None
Expand Down
17 changes: 10 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ issues = "https://github.com/tianocore/edk2-pytool-library/issues/"

[project.optional-dependencies]
dev = [
"flake8 == 6.0.0",
"flake8-pyproject == 1.2.3",
"ruff == 0.0.265",
"pytest == 7.3.1",
"coverage == 7.2.5",
"pydocstyle == 6.3.0",
]
publish = [
"setuptools == 67.7.2",
Expand All @@ -56,11 +54,16 @@ docs = [
[tool.coverage.run]
include = ["edk2toollib/*"]

[tool.flake8]
ignore = "E266,E722,W503"
max_line_length = 120
[tool.ruff]
src = ["edk2toollib"]
select = [
"E", # pycodestyle errors
"F", # PyFlakes
"D", # pydocstyle
]
line-length = 120

[tool.pydocstyle]
[tool.ruff.pydocstyle]
convention = "google"

[tool.pytest.ini_options]
Expand Down

0 comments on commit bb1e428

Please sign in to comment.