Skip to content

Commit 6f66f45

Browse files
authored
Add basic linting and formatting checks (#68)
* Added configurations for basic linting and formatting checks * simplify the used ruff ruleset for now * Add GitHub Workflow to perform linting and show results
1 parent 4500a92 commit 6f66f45

File tree

7 files changed

+167
-142
lines changed

7 files changed

+167
-142
lines changed

.github/workflows/code-linting.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Lint Code
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
# Cancel running jobs for the same workflow and branch.
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
12+
jobs:
13+
lint-python:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: x # any version
21+
check-latest: true
22+
- name: Install tox
23+
run: python -m pip install tox
24+
- name: Test
25+
run: tox -ve linting

.github/workflows/tek-repo-lint.yml

Lines changed: 26 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,39 @@
1+
---
12
name: tek-repo-lint
23
on:
34
push:
4-
branches: [ "main" ]
5+
branches: [master]
56
pull_request:
6-
branches: [ "main" ]
7+
branches: [master]
78
workflow_dispatch:
89

9-
# select correct state for repository
10-
env:
11-
# state: private
12-
state: public
13-
1410
jobs:
15-
public-or-private-repo:
16-
runs-on: ubuntu-latest
17-
outputs:
18-
repostate: ${{ steps.repo-state.outputs.repostate }}
19-
steps:
20-
21-
- name: Repo state
22-
id: repo-state
23-
run: echo "repostate=${{env.state}}" >> $GITHUB_OUTPUT
24-
- name: Repo public?
25-
if: "${{ env.state == 'public' }}"
26-
run: echo "Workflow has repo set as public. If this is incorrect, uncomment line 11."
27-
- name: Repo private?
28-
if: "${{ env.state == 'private' }}"
29-
run: echo "Workflow has repo set as private. If this is incorrect, uncomment line 12."
30-
31-
check-for-codeowners-file:
32-
runs-on: ubuntu-latest
33-
steps:
34-
35-
- name: Checkout repo
36-
uses: actions/checkout@v3
37-
38-
- name: Check for CODEOWNERS
39-
id: codeowners_file
40-
uses: initialstate/file-check-action@v1
41-
with:
42-
file: ".github/CODEOWNERS"
43-
44-
- name: CODEOWNERS file Output Test
45-
run: echo ${{ steps.codeowners_file.outputs.file_exists }}
46-
47-
- name: CODEOWNERS file exists with content
48-
if: steps.codeowners_file.outputs.file_exists == 'true'
49-
run: echo CODEOWNERS file exists!
50-
51-
- name: CODEOWNERS file does not exist
52-
if: steps.codeowners_file.outputs.file_exists == 'false'
53-
run: echo CODEOWNERS file does not exist!
54-
55-
check-for-readme-file:
56-
runs-on: ubuntu-latest
57-
steps:
58-
59-
- name: Checkout repo
60-
uses: actions/checkout@v3
61-
62-
- name: Check for README.md
63-
id: readme_file
64-
uses: initialstate/file-check-action@v1
65-
with:
66-
file: "README"
67-
68-
- name: README file Output Test
69-
run: echo ${{ steps.readme_file.outputs.file_exists }}
70-
71-
- name: README file exists with content
72-
if: steps.readme_file.outputs.file_exists == 'true'
73-
run: echo README file exists!
74-
75-
- name: README file does not exist
76-
if: steps.readme_file.outputs.file_exists == 'false'
77-
run: echo README file does not exist!
78-
79-
check-for-license:
80-
needs: public-or-private-repo
81-
if: needs.public-or-private-repo.outputs.repostate == 'public'
11+
check-for-file:
8212
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
filename:
17+
- .github/CODEOWNERS
18+
- README.@(md|rst)
19+
- LICENSE.@(md|rst)
20+
- .github/workflows/codeql.yml
8321
steps:
84-
85-
- name: Checkout repo
86-
uses: actions/checkout@v3
87-
88-
- name: Check for LICENSE.md
89-
id: license_file
90-
uses: initialstate/file-check-action@v1
22+
- uses: actions/checkout@v4
23+
- name: Ensure ${{ matrix.filename }} exists
24+
uses: andstor/file-existence-action@v3
9125
with:
92-
file: "LICENSE"
93-
94-
- name: LICENSE file Output Test
95-
run: echo ${{ steps.license_file.outputs.file_exists }}
96-
97-
- name: LICENSE file exists with content
98-
if: steps.license_file.outputs.file_exists == 'true'
99-
run: echo LICENSE file exists!
100-
101-
- name: LICENSE file does not exist
102-
if: steps.license_file.outputs.file_exists == 'false'
103-
run: echo LICENSE file does not exist!
104-
105-
check-for-dependabot-file:
26+
files: ${{ matrix.filename }}
27+
ignore_case: false
28+
follow_symbolic_links: false
29+
fail: true # Set the step to fail if the file doesn't exist
30+
# Check that all jobs passed
31+
check-repo-lint-passed:
32+
if: ${{ !cancelled() }}
33+
needs: [check-for-file]
10634
runs-on: ubuntu-latest
10735
steps:
108-
109-
- name: Checkout repo
110-
uses: actions/checkout@v3
111-
112-
- name: Check for dependabot.yml
113-
id: dependabot_file
114-
uses: initialstate/file-check-action@v1
36+
- name: Decide whether the needed jobs succeeded or failed
37+
uses: re-actors/alls-green@release/v1
11538
with:
116-
file: ".github/dependabot.yml"
117-
118-
- name: dependabot.yml file Output Test
119-
run: echo ${{ steps.dependabot_file.outputs.file_exists }}
120-
121-
- name: dependabot file exists with content
122-
if: steps.dependabot_file.outputs.file_exists == 'true'
123-
run: echo dependabot file exists!
124-
125-
- name: dependabot file does not exist
126-
if: steps.dependabot_file.outputs.file_exists == 'false'
127-
run: echo dependabot file does not exist!
128-
129-
check-for-codeql-file:
130-
runs-on: ubuntu-latest
131-
steps:
132-
133-
- name: Checkout repo
134-
uses: actions/checkout@v3
135-
136-
- name: Check for codeql-analysis.yml
137-
id: codeql-analysis_file
138-
uses: initialstate/file-check-action@v1
139-
with:
140-
file: ".github/workflows/codeql-analysis.yml"
141-
142-
- name: codeql-analysis.yml file Output Test
143-
run: echo ${{ steps.codeql-analysis_file.outputs.file_exists }}
144-
145-
- name: codeql-analysis file exists with content
146-
if: steps.codeql-analysis_file.outputs.file_exists == 'true'
147-
run: echo codeql-analysis file exists!
148-
149-
- name: codeql-analysis file does not exist
150-
if: steps.codeql-analysis_file.outputs.file_exists == 'false'
151-
run: echo codeql-analysis file does not exist!
39+
jobs: ${{ toJSON(needs) }}

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Ignore IDE config folders
2+
.idea/
3+
.vscode/
4+
5+
# Ignore caches and binaries
6+
.ruff_cache/
7+
__pycache__/
8+
*.py[cod]
9+
.tox/
10+
11+
# Ignore virtual environments
12+
*env*/
13+
*venv*/

.pre-commit-config.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
default_install_hook_types: [pre-commit]
3+
default_stages: [pre-commit]
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.6.0
7+
hooks:
8+
- id: check-yaml
9+
args: [--unsafe]
10+
- id: check-toml
11+
- id: check-json
12+
- id: check-xml
13+
- id: requirements-txt-fixer
14+
# - id: trailing-whitespace # TODO: enable
15+
# - id: end-of-file-fixer # TODO: enable
16+
- id: check-case-conflict
17+
- id: check-merge-conflict
18+
- id: forbid-submodules
19+
# TODO: enable these hooks
20+
# - repo: https://github.com/Lucas-C/pre-commit-hooks
21+
# rev: v1.5.5
22+
# hooks:
23+
# - id: remove-tabs
24+
# - id: forbid-tabs
25+
- repo: https://github.com/python-jsonschema/check-jsonschema
26+
rev: 0.29.0
27+
hooks:
28+
- id: check-github-workflows
29+
args: [--verbose]
30+
- repo: https://github.com/pappasam/toml-sort
31+
rev: v0.23.1
32+
hooks:
33+
- id: toml-sort-fix
34+
- repo: https://github.com/astral-sh/ruff-pre-commit
35+
rev: v0.5.4
36+
hooks:
37+
- id: ruff
38+
# args: [--fix, --exit-non-zero-on-fix]
39+
- id: ruff-format
40+
args: [--check, --diff]
41+
- repo: https://github.com/PyCQA/docformatter
42+
rev: v1.7.5
43+
hooks:
44+
- id: docformatter
45+
additional_dependencies: [tomli]
46+
args: [--check, --diff]

LICENSE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ TEKTRONIX SAMPLE SOURCE CODE LICENSE AGREEMENT
99
Source code written by Tektronix, Inc. or its affiliates ("Tektronix") that is designated as a "sample," "example," "sample code," or any similar designation will be considered "Sample Source Code." Tektronix grants you a license to download, reproduce, display, distribute, modify, and create derivative works of Tektronix Sample Source Code, only for use in or with Tektronix products. You may not remove or alter any copyright notices or trademarks.
1010

1111
SAMPLE SOURCE CODE IS PROVIDED "AS-IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF INTELLECTUAL PROPERTY. IN NO EVENT SHALL TEKTRONIX, ITS AFFILIATES, OFFICERS, EMPLOYEES, DIRECTORS, AGENTS, SUPPLIERS, OR OTHER THIRD PARTIES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SAMPLE SOURCE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12-

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<img alt="Tek Logo" src="https://theme.tekcloud.com/prod/github/tek-logo-round-light-mode.png" width="100px">
55
</picture>
66

7-
# Programmatic Control Examples
7+
# Programmatic Control Examples
88
[![CodeFactor](https://www.codefactor.io/repository/github/tektronix/programmatic-control-examples/badge)](https://www.codefactor.io/repository/github/tektronix/programmatic-control-examples)
99
> Code examples sorted by instrument, including examples taken from the User's Manuals. This is a good place to start off learning about programming for an instrument.
1010
@@ -52,7 +52,7 @@ You may also recognize some of these examples from the [Tektronix and Keithley W
5252
If you don't want to clone this entire repository, it's still possible to take individual files. Navigate to the directory holding the file you want and right-click the file to select _Save link as..._ or some variation on that depending on your browser. The file name will automatically populate and you can save the file where you'd like. Alternatively, you can open the file you want on GitHub and right-click "Raw" at the top of the file to accomplish the same thing.
5353

5454
## Maintainers
55-
Tektronix Product Line Marketing and Application Engineers:
55+
Tektronix Product Line Marketing and Application Engineers:
5656

5757
+ Jeffrey Miller: [bit-lift](https://github.com/bit-lift)
5858
+ Carl Murdock: [cbmurdock](https://github.com/cbmurdock)
@@ -61,7 +61,7 @@ Tektronix Product Line Marketing and Application Engineers:
6161
Licensed under the [Tektronix Sample License](https://www.tek.com/sample-license).
6262

6363
## Contributing<a name="contributing"></a>
64-
First, please consult the Tektronix [Code of Conduct](https://github.com/tektronix/.github/blob/main/CODE_OF_CONDUCT.md). Contributions in the form of new examples or bug fixes are welcome! Please contribute using [Github Flow](https://guides.github.com/introduction/flow/) and make sure you create your own branch from the `master` branch, and when you are ready to push your changes, just submit a pull request with your changes against the `master` branch. If you see something you're not sure is a bug, or if you'd like to request an example, please submit an Issue via GitHub.
64+
First, please consult the Tektronix [Code of Conduct](https://github.com/tektronix/.github/blob/main/CODE_OF_CONDUCT.md). Contributions in the form of new examples or bug fixes are welcome! Please contribute using [Github Flow](https://guides.github.com/introduction/flow/) and make sure you create your own branch from the `master` branch, and when you are ready to push your changes, just submit a pull request with your changes against the `master` branch. If you see something you're not sure is a bug, or if you'd like to request an example, please submit an Issue via GitHub.
6565

6666
If you'd like help from a Tektronix engineer in developing an example, please submit a pull request with what you have so far placed in the proper part of the repository, including any new directories your example may need.
6767

pyproject.toml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[tool.docformatter]
2+
close-quotes-on-newline = true
3+
in-place = true
4+
recursive = true
5+
wrap-descriptions = 100
6+
wrap-summaries = 0
7+
8+
[tool.ruff]
9+
line-length = 100
10+
target-version = "py38" # always generate Python 3.8 compatible code
11+
12+
[tool.ruff.lint]
13+
fixable = ["ALL"]
14+
flake8-quotes = {docstring-quotes = "double"}
15+
ignore = [
16+
"T201" # `print` found
17+
]
18+
pydocstyle = {convention = "google"}
19+
# https://beta.ruff.rs/docs/rules/
20+
select = [
21+
# "ALL" # TODO: enable ALL
22+
"E",
23+
"F",
24+
"I",
25+
"N",
26+
"PLE",
27+
"Q",
28+
"RUF"
29+
]
30+
31+
[tool.ruff.lint.isort]
32+
force-sort-within-sections = false
33+
lines-between-types = 1
34+
order-by-type = false
35+
36+
[tool.tomlsort]
37+
all = true
38+
in_place = true
39+
spaces_before_inline_comment = 2
40+
41+
[tool.tox]
42+
legacy_tox_ini = """
43+
[tox]
44+
requires = tox>4
45+
no_package = True
46+
envlist = linting
47+
skip_missing_interpreters = True
48+
49+
[testenv:linting]
50+
deps =
51+
pre-commit
52+
commands =
53+
pre-commit run --all-files
54+
"""

0 commit comments

Comments
 (0)