Skip to content

Commit

Permalink
feat: Lint CI checks (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiky30 authored Jan 24, 2024
1 parent 3db5a39 commit 509b68f
Show file tree
Hide file tree
Showing 22 changed files with 276 additions and 123 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint
on:
push:
branches-ignore:
- "release/**"

jobs:
lint:
name: Lint code
runs-on: ubuntu-latest

steps:
- name: Check out repo
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Pre-commit checks
run: |
pip install pre-commit==3.6.0
pre-commit run --all-files
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.11

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: end-of-file-fixer
- id: detect-private-key
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Introduction

A package to run a Raspberry Pi in an outbuilding such as a garden shed, for the internet of sheds.
A package to run a Raspberry Pi in an outbuilding such as a garden shed, for the internet of sheds.

Automated use cases:
- Weather station
Expand All @@ -11,15 +11,15 @@ Automated use cases:

## TODO:
1. Fix: Bug: The script startup gets an incorrect time (Hasn't yet got the internet time)
2. Instructions on pinout
2. Instructions on pinout

### Wish list:
- Poetry (Not started)
- ASGI backend server (Daphne)
- Native webcomponent FE with Bootstrap
- pip install raspberry pi
- modular components that are easy to install from a software and hardware perspective
- Provide systemd script to 3rd parties
- modular components that are easy to install from a software and hardware perspective
- Provide systemd script to 3rd parties
- venv is crucial before installing any third party packages!
- Pre commit config with ci integration

Expand All @@ -44,7 +44,7 @@ sudo raspi-config
sudo reboot
```

Sanity check that the 1 Wire data is available:
Sanity check that the 1 Wire data is available:

```shell
ls /sys/bus/w1/devices/
Expand All @@ -57,30 +57,30 @@ cat /sys/bus/w1/devices/28-000003ebbf13/w1_slave

### Script auto start with systemd

Create a file in systemd
Create a file in systemd

```shell
nano /lib/systemd/system/shed-pi.service
````

With the contents
With the contents

```ini
[Unit]
Description=Shed-Pi
After=multi-user.target
StartLimitIntervalSec=0
[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/shed-pi/temp_logger.py
StandardInput=tty-force
[Install]
WantedBy=multi-user.target
```

Enable the service, (CAVEAT: didn't work when manually starting, works on reboot)
Enable the service, (CAVEAT: didn't work when manually starting, works on reboot)
```shell
sudo systemctl daemon-reload
sudo systemctl enable shed-pi.service
Expand All @@ -93,6 +93,25 @@ Read the logs
tail -f /var/log/shed-pi.log
```
## Development
### Precommit
Install pre-commit: https://pre-commit.com/
Configure precommit on your local git for the project by running the following at the root of the project:
```shell
pre-commit install
```
Pre-commit will then automatically run for your changes at commit time.
To run the pre-commit config manually, run:
```shell
pre-commit run --all-files
```
## Release
Generate the release
Expand All @@ -101,4 +120,4 @@ Generate the release
pip install -q build
python -m build
twine upload dist/*
```
```
11 changes: 0 additions & 11 deletions insert_data.py

This file was deleted.

6 changes: 4 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shedpi_hub_example_project.settings')
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "shedpi_hub_example_project.settings"
)
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -18,5 +20,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
77 changes: 77 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,80 @@ classifiers = [
[project.urls]
"Homepage" = "https://github.com/Aiky30/shed-pi"
"Bug Tracker" = "https://github.com/Aiky30/shed-pi/issues"

[tool.black]
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| build
| dist
)/
'''

[tool.ruff]
# Official documentation on ruff rules can be viewed here: https://beta.ruff.rs/docs/rules/
# Please note that some pydocstyle rules do not work for the PEP257 docstring format this repo uses. Please view the
# official documentation for more information: https://www.pydocstyle.org/en/5.0.1/error_codes.html#default-conventions
select = [
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"I", # isort
"N", # pep8-naming
#"D101", # pydocstyle: Missing docstring in public class
#"D102", # pydocstyle: Missing docstring in public method
#"D103", # pydocstyle: Missing docstring in public function
"D201", # pydocstyle: No blank lines allowed before function docstring (found {num_lines})
"D202", # pydocstyle: No blank lines allowed after function docstring (found {num_lines})
"D204", # pydocstyle: 1 blank line required after class docstring
"D206", # pydocstyle: Docstring should be indented with spaces, not tabs
"D207", # pydocstyle: Docstring is under-indented
"D208", # pydocstyle: Docstring is over-indented
"D209", # pydocstyle: Multi-line docstring closing quotes should be on a separate line
"D300", # pydocstyle: Use triple double quotes """
"D403", # pydocstyle: First word of the first line should be properly capitalized
#"ANN001", # flake8-annotations: Missing type annotation for function argument {name}
#"ANN002", # flake8-annotations: Missing type annotation for *{name}
#"ANN003", # flake8-annotations: Missing type annotation for **{name}
#"ANN201", # flake8-annotations: Missing return type annotation for public function {name}
#"ANN202", # flake8-annotations: Missing return type annotation for private function {name}
#"ANN204", # flake8-annotations: Missing return type annotation for special method {name}
#"ANN205", # flake8-annotations: Missing return type annotation for staticmethod {name}
#"ANN206", # flake8-annotations: Missing return type annotation for classmethod {name}
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"INP", # flake8-no-pep420
"PIE", # flake8-pie
#"T20", # flake8-print
"Q", # flake8-quotes
"SLF", # flake8-self
"SIM", # flake8-simplify
"PTH", # flake8-use-pathlib
"ERA", # eradicate
"RUF", # ruff-specific rules
]
ignore = [
"G004",
"ERA001",
"PTH123",
]
exclude = [
".git",
".pytest_cache",
".ruff_cache",
".venv",
".gitignore",
".github",
"migrations"
]
force-exclude = true
line-length = 120
target-version = "py311"
22 changes: 10 additions & 12 deletions shed_pi.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Description-Content-Type: text/markdown

## Introduction

A package to run a Raspberry Pi in an outbuilding such as a garden shed, for the internet of sheds.
A package to run a Raspberry Pi in an outbuilding such as a garden shed, for the internet of sheds.

Automated use cases:
- Weather station
Expand All @@ -24,15 +24,15 @@ Automated use cases:

## TODO:
1. Fix: Bug: The script startup gets an incorrect time (Hasn't yet got the internet time)
2. Instructions on pinout
2. Instructions on pinout

### Wish list:
- Poetry (Not started)
- ASGI backend server (Daphne)
- Native webcomponent FE with Bootstrap
- pip install raspberry pi
- modular components that are easy to install from a software and hardware perspective
- Provide systemd script to 3rd parties
- modular components that are easy to install from a software and hardware perspective
- Provide systemd script to 3rd parties
- venv is crucial before installing any third party packages!
- Pre commit config with ci integration

Expand All @@ -57,7 +57,7 @@ sudo raspi-config
sudo reboot
```

Sanity check that the 1 Wire data is available:
Sanity check that the 1 Wire data is available:

```shell
ls /sys/bus/w1/devices/
Expand All @@ -70,30 +70,30 @@ cat /sys/bus/w1/devices/28-000003ebbf13/w1_slave

### Script auto start with systemd

Create a file in systemd
Create a file in systemd

```shell
nano /lib/systemd/system/shed-pi.service
````

With the contents
With the contents

```ini
[Unit]
Description=Shed-Pi
After=multi-user.target
StartLimitIntervalSec=0

[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/shed-pi/temp_logger.py
StandardInput=tty-force

[Install]
WantedBy=multi-user.target
```

Enable the service, (CAVEAT: didn't work when manually starting, works on reboot)
Enable the service, (CAVEAT: didn't work when manually starting, works on reboot)
```shell
sudo systemctl daemon-reload
sudo systemctl enable shed-pi.service
Expand All @@ -105,5 +105,3 @@ Read the logs
```shell
tail -f /var/log/shed-pi.log
```


2 changes: 1 addition & 1 deletion shed_pi.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ temp_logger.py
shed_pi.egg-info/PKG-INFO
shed_pi.egg-info/SOURCES.txt
shed_pi.egg-info/dependency_links.txt
shed_pi.egg-info/top_level.txt
shed_pi.egg-info/top_level.txt
1 change: 0 additions & 1 deletion shed_pi.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

4 changes: 2 additions & 2 deletions shedpi_hub_dashboard/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class ShedpiHubDashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'shedpi_hub_dashboard'
default_auto_field = "django.db.models.BigAutoField"
name = "shedpi_hub_dashboard"
Loading

0 comments on commit 509b68f

Please sign in to comment.