Skip to content

Commit 24fa45b

Browse files
authored
Merge pull request #95 from scanoss/chore/mdaloia/add-ruff-config-and-pre-commit
chore: add ruff as formater and linter, add pre commit hooks, add lint workflow
2 parents 1906c42 + 261a39f commit 24fa45b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3385
-2408
lines changed

.github/workflows/lint.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout Code
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: "3.8"
21+
22+
- name: Install Dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install ruff
26+
27+
- name: Get changed Python files
28+
id: changed_files
29+
run: |
30+
# Find the merge base between the main branch and the current HEAD.
31+
merge_base=$(git merge-base origin/main HEAD)
32+
# List all changed Python files since the merge base.
33+
files=$(git diff --name-only "$merge_base" HEAD | grep '\.py$' || true)
34+
35+
# Use the multi-line syntax for outputs.
36+
echo "files<<EOF" >> "$GITHUB_OUTPUT"
37+
echo "${files}" >> "$GITHUB_OUTPUT"
38+
echo "EOF" >> "$GITHUB_OUTPUT"
39+
40+
echo "Changed files: ${files}"
41+
42+
- name: Run Ruff on changed files
43+
run: |
44+
if [ -z "${{ steps.changed_files.outputs.files }}" ]; then
45+
echo "No Python files changed. Exiting."
46+
exit 0
47+
else
48+
echo "Linting the following files:"
49+
echo "${{ steps.changed_files.outputs.files }}"
50+
# Pass the list of changed files to Ruff.
51+
echo "${{ steps.changed_files.outputs.files }}" | xargs ruff check
52+
fi

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.4
4+
hooks:
5+
- id: ruff
6+
- id: ruff-format

date_time.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
#!/usr/bin/env python3
22
"""
3-
SPDX-License-Identifier: MIT
3+
SPDX-License-Identifier: MIT
44
5-
Copyright (c) 2022, SCANOSS
5+
Copyright (c) 2022, SCANOSS
66
7-
Permission is hereby granted, free of charge, to any person obtaining a copy
8-
of this software and associated documentation files (the "Software"), to deal
9-
in the Software without restriction, including without limitation the rights
10-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
copies of the Software, and to permit persons to whom the Software is
12-
furnished to do so, subject to the following conditions:
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
1313
14-
The above copyright notice and this permission notice shall be included in
15-
all copies or substantial portions of the Software.
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
1616
17-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23-
THE SOFTWARE.
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
2424
"""
25+
2526
import datetime
2627

2728
"""
2829
Store the current date/time into a data field for processing
2930
"""
30-
if __name__ == "__main__":
31+
if __name__ == '__main__':
3132
now = datetime.datetime.now()
3233
data = f'date: {now.strftime("%Y%m%d%H%M%S")}, utime: {int(now.timestamp())}'
3334
with open('src/scanoss/data/build_date.txt', 'w') as f:

docs/source/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
extensions = ['sphinx_rtd_theme']
1818

19-
templates_path = ["_templates"]
19+
templates_path = ['_templates']
2020
exclude_patterns = []
2121

2222

@@ -27,4 +27,3 @@
2727
html_theme = 'sphinx_rtd_theme'
2828
html_logo = 'scanosslogo.jpg'
2929
html_static_path = ['_static']
30-

pyproject.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
[build-system]
22
requires = ["setuptools", "wheel", "twine"]
3-
build-backend = "setuptools.build_meta"
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.ruff]
6+
# Enable pycodestyle (E), pyflakes (F), isort (I), pylint (PL)
7+
select = ["E", "F", "I", "PL"]
8+
line-length = 120
9+
# Assume Python 3.7+
10+
target-version = "py37"
11+
exclude = ["tests/*", "test_*.py"]
12+
13+
[tool.ruff.format]
14+
quote-style = "single"
15+
indent-style = "space"
16+
line-ending = "auto"
17+
18+
[tool.ruff.lint.isort]
19+
known-first-party = ["scanoss"]

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ wheel
33
twine
44
build
55
grpcio-tools
6+
ruff
7+
pre-commit

src/protoc_gen_swagger/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"""
2-
SPDX-License-Identifier: BSD-3-Clause
2+
SPDX-License-Identifier: BSD-3-Clause
33
4-
Copyright (c) 2015, Gengo, Inc.
5-
All rights reserved.
4+
Copyright (c) 2015, Gengo, Inc.
5+
All rights reserved.
66
7-
Redistribution and use in source and binary forms, with or without modification,
8-
are permitted provided that the following conditions are met:
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
99
10-
* Redistributions of source code must retain the above copyright notice,
11-
this list of conditions and the following disclaimer.
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
1212
13-
* Redistributions in binary form must reproduce the above copyright notice,
14-
this list of conditions and the following disclaimer in the documentation
15-
and/or other materials provided with the distribution.
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
1616
17-
* Neither the name of Gengo, Inc. nor the names of its
18-
contributors may be used to endorse or promote products derived from this
19-
software without specific prior written permission.
17+
* Neither the name of Gengo, Inc. nor the names of its
18+
contributors may be used to endorse or promote products derived from this
19+
software without specific prior written permission.
2020
"""
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"""
2-
SPDX-License-Identifier: BSD-3-Clause
2+
SPDX-License-Identifier: BSD-3-Clause
33
4-
Copyright (c) 2015, Gengo, Inc.
5-
All rights reserved.
4+
Copyright (c) 2015, Gengo, Inc.
5+
All rights reserved.
66
7-
Redistribution and use in source and binary forms, with or without modification,
8-
are permitted provided that the following conditions are met:
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
99
10-
* Redistributions of source code must retain the above copyright notice,
11-
this list of conditions and the following disclaimer.
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
1212
13-
* Redistributions in binary form must reproduce the above copyright notice,
14-
this list of conditions and the following disclaimer in the documentation
15-
and/or other materials provided with the distribution.
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
1616
17-
* Neither the name of Gengo, Inc. nor the names of its
18-
contributors may be used to endorse or promote products derived from this
19-
software without specific prior written permission.
17+
* Neither the name of Gengo, Inc. nor the names of its
18+
contributors may be used to endorse or promote products derived from this
19+
software without specific prior written permission.
2020
"""

src/protoc_gen_swagger/options/annotations_pb2.py

Lines changed: 12 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
3-
import grpc
43

4+
import grpc

0 commit comments

Comments
 (0)