Skip to content

Commit a2a27a2

Browse files
committed
enrich pre-commit hook
1 parent e97ec73 commit a2a27a2

File tree

10 files changed

+37
-15
lines changed

10 files changed

+37
-15
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ jobs:
1717
pip install '.[dev]'
1818
- name: Run tests
1919
run: |
20-
pytest
20+
pytest

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ wheels/
88

99
# Virtual environments
1010
.venv
11-

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@ repos:
88
rev: v1.2.3
99
hooks:
1010
- id: flake8
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: v4.5.0
13+
hooks:
14+
- id: check-case-conflict
15+
- id: check-merge-conflict
16+
- id: check-symlinks
17+
- id: check-toml
18+
- id: check-yaml
19+
- id: end-of-file-fixer
20+
- id: mixed-line-ending
21+
args: ["--fix=lf"]
22+
- id: trailing-whitespace
23+
exclude: \.md$
24+
- id: no-commit-to-branch

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ Install pre-commit hooks to ensure code quality:
6565
```shell
6666
pre-commit install
6767
pre-commit install -t pre-push
68-
```
68+
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ where = ["src"]
4646
max-line-length = 88
4747

4848
[tool.pytest.ini_options]
49-
testpaths = ["src/tests"]
49+
testpaths = ["src/tests"]

shecan.svg

Lines changed: 2 additions & 2 deletions
Loading

src/shecan/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def list_dns():
3737

3838

3939
def current_dns() -> List[Resolver]:
40-
""" List current dns servers in /etc/resolv.conf."""
40+
"""List current dns servers in /etc/resolv.conf."""
4141
resolv_list = []
4242
if sys.platform == "linux":
4343
with open("/etc/resolv.conf", mode="rt") as resovl_file:

src/shecan/cli.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def verify_dns() -> None:
8585

8686

8787
def show_current_dns() -> None:
88-
""" List current dns servers in /etc/resolv.conf."""
88+
"""List current dns servers in /etc/resolv.conf."""
8989
try:
9090
resolvers = shecan.current_dns()
9191
except FileNotFoundError:
@@ -120,7 +120,10 @@ def shecan_cli():
120120
set_.set_defaults(op="set")
121121

122122
# `restore` command
123-
restore = subparsers.add_parser("restore", help="Restore old DNS configuration.")
123+
restore = subparsers.add_parser(
124+
"restore",
125+
help="Restore old DNS configuration.",
126+
)
124127
restore.set_defaults(op="restore")
125128

126129
# `update` command
@@ -129,7 +132,8 @@ def shecan_cli():
129132

130133
# `show` command
131134
show = subparsers.add_parser(
132-
"show", help="Show your current dns servers in '/etc/resolv.conf'."
135+
"show",
136+
help="Show your current dns servers in '/etc/resolv.conf'.",
133137
)
134138
show.set_defaults(op="show")
135139

@@ -148,14 +152,14 @@ def shecan_cli():
148152
elif args.op == "verify":
149153
verify_dns()
150154
elif args.op == "set":
151-
152155
if sys.platform != "linux":
153156
logger.error("Currently only Linux operating system is supported.")
154157
sys.exit(2)
155158

156159
content = [f"nameserver {dns_ip}" for dns_ip in shecan.list_dns()]
157160
if not content:
158-
logger.error("Couldn't find Shecan DNS IP addresses in the config file.")
161+
error_msg = "Couldn't find Shecan DNS IP addresses in the config file."
162+
logger.error(error_msg)
159163
sys.exit(1)
160164

161165
update_resolv_file(content)

src/shecan/db.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ def list_dns(self):
4646
ips = []
4747
return ips
4848

49-
def delete(self,) -> None:
49+
def delete(
50+
self,
51+
) -> None:
5052
"""Remove all Shecan's dns servers from configuration."""
5153
self._parser.remove_section(self._name)
5254
self._initialize()
5355

54-
def remove(self,) -> None:
56+
def remove(
57+
self,
58+
) -> None:
5559
"""Remove the configuration file."""
5660
Path(self.config_file).unlink()

src/shecan/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
~~~~~~~~~~~~~~
44
This module provides utility functions that are used within shecan.
55
"""
6+
67
from typing import Tuple
78
from urllib import request
89

@@ -13,7 +14,7 @@
1314

1415

1516
def get_shecan_ips(url: str = BASE_URL, selector: str = CSS_SELECTOR) -> Tuple[str]:
16-
""" Retrieve shecan DNS IP addresses."""
17+
"""Retrieve shecan DNS IP addresses."""
1718
data = request.urlopen(BASE_URL).read().decode("utf-8")
1819
soup = BeautifulSoup(data, "lxml")
1920
ips = soup.select(selector)

0 commit comments

Comments
 (0)