Skip to content
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

switch black -> ruff format #373

Merged
merged 3 commits into from
Nov 10, 2023
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
44 changes: 0 additions & 44 deletions .github/workflows/lint.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint (Ruff, MyPy)
on:
push:
workflow_dispatch:
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
run: |
sudo apt-get install build-essential libpoppler-cpp-dev pkg-config python3-dev -y
pip install -r requirements/dev_requirements.txt
- name: Run pre-commit
run: pre-commit run --all-files
14 changes: 5 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
args: ["--check", "--target-version", "py38"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.239"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
hooks:
- id: ruff
- id: ruff-format
args: ["--check"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.0.0"
rev: "v1.6.1"
hooks:
- id: mypy
additional_dependencies:
Expand Down
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ Note on single-sourcing the package version: More can be read [here](https://pac
All commits shall pass the lint pipeline of the following tools:

- Mypy (see [pyproject.toml](https://github.com/crocs-muni/sec-certs/blob/main/pyproject.toml) for settings)
- Black (see [pyproject.toml](https://github.com/crocs-muni/sec-certs/blob/main/pyproject.toml) for settings)
- Ruff (see [pyproject.toml](https://github.com/crocs-muni/sec-certs/blob/main/pyproject.toml) for settings)
- PyUpgrade

These tools can be installed via [dev_requirements.txt](https://github.com/crocs-muni/sec-certs/blob/main/dev_requirements.txt) You can use [pre-commit](https://pre-commit.com/) tool to register git hook that will evalute these checks prior to any commit and abort the commit for you. Note that the pre-commit is not meant to automatically fix the issues, just warn you.

Expand All @@ -60,8 +58,8 @@ pre-commit run --all-files

To ivoke the tools manually, you can, in the repository root, use:
- Mypy: `mypy .`
- Black: `black --check .` (without the flag to reformat)
- Ruff: `ruff ." (or with `--fix` flag to apply fixes)
- Ruff formatL `ruff format --check .`

## Documentation

Expand Down
48 changes: 24 additions & 24 deletions notebooks/cc/cert_id_eval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"from sec_certs.dataset import CCDataset\n",
"from sec_certs.cert_rules import cc_rules\n",
"import csv\n",
"import pandas as pd"
"import pandas as pd\n"
]
},
{
Expand All @@ -51,7 +51,7 @@
"num_schemes = len(cc_rules[\"cc_cert_id\"])\n",
"num_scheme_rules = sum(len(rules) for rules in cc_rules[\"cc_cert_id\"].values())\n",
"print(f\"\\\\newcommand{{\\\\numccschemes}}{{{num_schemes}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numccschemeidrules}}{{{num_scheme_rules}}}\")"
"print(f\"\\\\newcommand{{\\\\numccschemeidrules}}{{{num_scheme_rules}}}\")\n"
]
},
{
Expand All @@ -64,7 +64,7 @@
},
"outputs": [],
"source": [
"dset = CCDataset.from_web_latest()"
"dset = CCDataset.from_web_latest()\n"
]
},
{
Expand All @@ -75,7 +75,7 @@
"source": [
"num_ids = len(list(filter(lambda cert: cert.heuristics.cert_id, dset)))\n",
"print(f\"\\\\newcommand{{\\\\numcccerts}}{{{len(dset)}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numccids}}{{{num_ids}}}\")"
"print(f\"\\\\newcommand{{\\\\numccids}}{{{num_ids}}}\")\n"
]
},
{
Expand Down Expand Up @@ -107,7 +107,7 @@
" if not cert.heuristics.cert_id:\n",
" missing_id_dgsts.add(cert.dgst)\n",
" missing_id.append((cert.dgst, cert.scheme))\n",
"pd.DataFrame(missing_id, columns=[\"id\", \"scheme\"])"
"pd.DataFrame(missing_id, columns=[\"id\", \"scheme\"])\n"
]
},
{
Expand All @@ -126,7 +126,7 @@
"missing_manual = pd.read_csv(\"../../data/cert_id_eval/missing_ids.csv\")\n",
"print(set(missing_manual.id) == missing_id_dgsts)\n",
"print(set(missing_manual.id).difference(missing_id_dgsts))\n",
"print(set(missing_id_dgsts).difference(missing_manual.id))"
"print(set(missing_id_dgsts).difference(missing_manual.id))\n"
]
},
{
Expand All @@ -144,7 +144,7 @@
"num_missing_manual_unfixable = num_missing_manual - num_missing_manual_fixable\n",
"print(f\"\\\\newcommand{{\\\\numccmissingid}}{{{num_missing_manual}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numccmissingidfixable}}{{{num_missing_manual_fixable}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numccmissingidunfixable}}{{{num_missing_manual_unfixable}}}\")"
"print(f\"\\\\newcommand{{\\\\numccmissingidunfixable}}{{{num_missing_manual_unfixable}}}\")\n"
]
},
{
Expand All @@ -153,7 +153,7 @@
"metadata": {},
"outputs": [],
"source": [
"missing_manual.loc[missing_manual.cert_id.isnull()].reason.value_counts()"
"missing_manual.loc[missing_manual.cert_id.isnull()].reason.value_counts()\n"
]
},
{
Expand All @@ -162,7 +162,7 @@
"metadata": {},
"outputs": [],
"source": [
"missing_manual.loc[missing_manual.cert_id.notnull()].reason.value_counts()"
"missing_manual.loc[missing_manual.cert_id.notnull()].reason.value_counts()\n"
]
},
{
Expand Down Expand Up @@ -195,7 +195,7 @@
"for idd, entries in id_mapping.items():\n",
" if len(entries) > 1 and idd:\n",
" print(idd, entries)\n",
" duplicate_id_dgsts.update(entries)"
" duplicate_id_dgsts.update(entries)\n"
]
},
{
Expand Down Expand Up @@ -235,9 +235,9 @@
" print(hash, entries)\n",
" for entry in entries:\n",
" duplicate_doc_dgsts.add(entry)\n",
" \n",
"\n",
"duplicate_ids_due_doc = duplicate_doc_dgsts.intersection(duplicate_id_dgsts)\n",
"duplicate_ids_issue = duplicate_id_dgsts.difference(duplicate_doc_dgsts)"
"duplicate_ids_issue = duplicate_id_dgsts.difference(duplicate_doc_dgsts)\n"
]
},
{
Expand All @@ -262,7 +262,7 @@
"outputs": [],
"source": [
"for id in duplicate_ids_issue:\n",
" print(id, dset[id].heuristics.cert_id)"
" print(id, dset[id].heuristics.cert_id)\n"
]
},
{
Expand All @@ -273,7 +273,7 @@
"source": [
"print(f\"\\\\newcommand{{\\\\numccduplicateid}}{{{len(duplicate_id_dgsts)}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numccduplicateidcolission}}{{{len(duplicate_ids_due_doc)}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numccduplicateidissue}}{{{len(duplicate_ids_issue)}}}\")"
"print(f\"\\\\newcommand{{\\\\numccduplicateidissue}}{{{len(duplicate_ids_issue)}}}\")\n"
]
},
{
Expand All @@ -300,7 +300,7 @@
"duplicate_manual = pd.read_csv(\"../../data/cert_id_eval/duplicate_ids.csv\")\n",
"print(set(duplicate_manual.id) == duplicate_id_dgsts)\n",
"print(set(duplicate_manual.id).difference(duplicate_id_dgsts))\n",
"print(set(duplicate_id_dgsts).difference(duplicate_manual.id))"
"print(set(duplicate_id_dgsts).difference(duplicate_manual.id))\n"
]
},
{
Expand All @@ -309,7 +309,7 @@
"metadata": {},
"outputs": [],
"source": [
"duplicate_manual[duplicate_manual.result == \"tp\"].reason.value_counts()"
"duplicate_manual[duplicate_manual.result == \"tp\"].reason.value_counts()\n"
]
},
{
Expand All @@ -318,7 +318,7 @@
"metadata": {},
"outputs": [],
"source": [
"duplicate_manual[duplicate_manual.result == \"fp\"].reason.value_counts()"
"duplicate_manual[duplicate_manual.result == \"fp\"].reason.value_counts()\n"
]
},
{
Expand Down Expand Up @@ -371,7 +371,7 @@
" impossible.add(line[\"id\"])\n",
" else:\n",
" correct.add(line[\"id\"])\n",
"print(len(correct), len(possible), len(impossible))"
"print(len(correct), len(possible), len(impossible))\n"
]
},
{
Expand All @@ -395,7 +395,7 @@
" incorrect.add(line[\"id\"])\n",
" else:\n",
" correct.add(line[\"id\"])\n",
"print(len(correct), len(incorrect))"
"print(len(correct), len(incorrect))\n"
]
},
{
Expand All @@ -410,7 +410,7 @@
"source": [
"print(f\"\\\\newcommand{{\\\\numccideval}}{{{len(correct) + len(incorrect)}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numccidevalcorrect}}{{{len(correct)}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numccidevalincorrect}}{{{len(incorrect)}}}\")"
"print(f\"\\\\newcommand{{\\\\numccidevalincorrect}}{{{len(incorrect)}}}\")\n"
]
},
{
Expand All @@ -426,7 +426,7 @@
"metadata": {},
"outputs": [],
"source": [
"manual_references = pd.read_csv(\"../../data/cert_id_eval/random_references.csv\")"
"manual_references = pd.read_csv(\"../../data/cert_id_eval/random_references.csv\")\n"
]
},
{
Expand All @@ -438,7 +438,7 @@
"print(\"The referenced cert is a...\")\n",
"print(manual_references[manual_references.reason != \"self\"].reason.value_counts())\n",
"print(\"... in the current cert.\")\n",
"print(\"Total refs:\", sum(manual_references.reason != \"self\"))"
"print(\"Total refs:\", sum(manual_references.reason != \"self\"))\n"
]
},
{
Expand All @@ -456,7 +456,7 @@
"print(f\"\\\\newcommand{{\\\\numCcRefEvalPrevVersion}}{{{sum(manual_references.reason == 'previous version')}}}\")\n",
"\n",
"print(f\"\\\\newcommand{{\\\\numCcRefEvalInReport}}{{{sum((manual_references.location == 'report') & (manual_references.reason != 'self'))}}}\")\n",
"print(f\"\\\\newcommand{{\\\\numCcRefEvalInTarget}}{{{sum((manual_references.location == 'target') & (manual_references.reason != 'self'))}}}\")"
"print(f\"\\\\newcommand{{\\\\numCcRefEvalInTarget}}{{{sum((manual_references.location == 'target') & (manual_references.reason != 'self'))}}}\")\n"
]
}
],
Expand All @@ -476,7 +476,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.13"
},
"vscode": {
"interpreter": {
Expand Down
26 changes: 3 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@

[project.optional-dependencies]
dev = [
"black==23.1.0",
"ruff==0.0.239",
"mypy==1.0.0",
"ruff==0.1.5",
"mypy==1.6.1",
"types-PyYAML",
"types-python-dateutil",
"types-requests",
Expand Down Expand Up @@ -107,7 +106,7 @@
"SIM",
]
ignore = [
"E501", # line-length, should be handled by black
"E501", # line-length, should be handled by ruff format
]
src = ["src", "tests"]
line-length = 120
Expand All @@ -124,25 +123,6 @@
write_to = "src/sec_certs/_version.py"
version_scheme = "no-guess-dev"

[tool.black]
line-length = 120
force-exclude = '''
/(
\.git
| \.mypy_cache
| \.tox
| venv
| \.venv
| _build
| buck-out
| build
| dist
| src/sec_certs/_version.py
| docs
| .ipynb_checkpoints
| .eggs
)/
'''

[tool.mypy]
plugins = ["numpy.typing.mypy_plugin"]
Expand Down
Loading