Skip to content

Commit 888d2cc

Browse files
authored
Merge pull request #144 from olehermanse/linting
GH Actions: Added pyright, pyflakes, flake8, and started fixing errors
2 parents cdadc80 + ca16f44 commit 888d2cc

File tree

10 files changed

+22
-24
lines changed

10 files changed

+22
-24
lines changed

.github/workflows/tests.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ jobs:
2929
- name: Install dependencies
3030
run: |
3131
python -m pip install --upgrade pip
32-
python -m pip install flake8 pytest setuptools wheel
32+
python -m pip install flake8 pyright pyflakes pytest setuptools wheel
3333
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3434
- name: Lint with flake8
3535
run: |
36-
# stop the build if there are Python syntax errors or undefined names
37-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
38-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
39-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
36+
flake8 . --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160
37+
- name: Lint with pyright (type checking)
38+
run: |
39+
echo TODO - fix pyright errors # pyright cf_remote
40+
- name: Lint with pyflakes
41+
run: |
42+
pyflakes cf_remote
4043
- name: Test with pytest
4144
run: |
4245
pytest

cf_remote/aramid.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ def __init__(
211211
connection to the host
212212
213213
"""
214+
assert type(user) is str and len(user) > 0
215+
assert type(host_name) is str and len(host_name) > 0
214216
parts = urlparse("ssh://%s" % host_name)
215217
self.user = user or parts.username
216218
self.port = port or parts.port
@@ -226,12 +228,15 @@ def __init__(
226228
@property
227229
def login(self):
228230
"""user@host_name for the host"""
231+
assert self.user is not None
232+
assert self.host_name is not None
229233
return self.user + "@" + self.host_name
230234

231235
@property
232236
def host_name_port(self):
233237
""" "host_name:port" or just "host_name" if using standard port"""
234238
port_spec = (":%d" % self.port) if self.port != _DEFAULT_SSH_PORT else ""
239+
assert self.host_name is not None
235240
return self.host_name + port_spec
236241

237242
def __str__(self):

cf_remote/cloud_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
"region": "eu-west-1",
8181
},
8282
"windows": {
83-
"note": "Note that typically we rely on custom pre-configured windows imimages with ssh installed and pre-populated public keys so an image spawned from this criteria will not come with ssh built-in and ready to go.",
83+
"note": "Note that typically we rely on custom pre-configured windows imimages with ssh installed and pre-populated public keys"
84+
+ " so an image spawned from this criteria will not come with ssh built-in and ready to go.",
8485
"owner_id": "801119661308",
8586
"name_pattern": "Windows_Server-{version}-English-Core-Base*",
8687
"user": "Administrator",

cf_remote/commands.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
whoami,
3333
get_package_name,
3434
user_error,
35-
)
36-
from cf_remote.utils import (
37-
user_error,
3835
is_package_url,
3936
print_progress_dot,
4037
ChecksumError,
@@ -477,7 +474,7 @@ def spawn(
477474

478475
def _is_saved_group(vms_info, group_name):
479476
group = vms_info[group_name]
480-
return group.get("meta", {}).get("saved") == True
477+
return group.get("meta", {}).get("saved") is True
481478

482479

483480
def _delete_saved_group(vms_info, group_name):

cf_remote/packages.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from cf_remote.utils import is_in_past, canonify
44
from cf_remote import log
55
import re
6-
import sys
76

87

98
class Artifact:
@@ -223,7 +222,7 @@ def __init__(self, edition="enterprise"):
223222
and release["lts_branch"] not in self.supported_branches
224223
):
225224
continue
226-
if "latestLTS" in release and release["latestLTS"] == True:
225+
if "latestLTS" in release and release["latestLTS"] is True:
227226
self.default = rel
228227
rel.default = True
229228
self.releases.append(rel)

cf_remote/remote.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ def install_host(
590590
return 1
591591
else:
592592
log.warning(
593-
"You did not specify --bootstrap in the install command, so CFEngine has been installed, but not started.\nTo fix this, run:\ncf-remote agent --hosts HOSTS --bootstrap BOOTSTRAP"
593+
"You did not specify --bootstrap in the install command, so CFEngine has been installed, but not started.\n"
594+
+ "To fix this, run:\ncf-remote agent --hosts HOSTS --bootstrap BOOTSTRAP"
594595
)
595596
if demo:
596597
if hub:

cf_remote/spawn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def region(self):
166166
return data.extra["zone"].name
167167

168168
region = self._driver.region
169-
if (type(region) != str) and hasattr(region, "name"):
169+
if (type(region) is not str) and hasattr(region, "name"):
170170
return region.name
171171
else:
172172
return str(region)
@@ -397,7 +397,7 @@ def spawn_vm_in_aws(
397397
sizes = criteria.get("sizes") or aws_defaults["sizes"]
398398
small = sizes[architecture]["size"]
399399
large = sizes[architecture]["xlsize"]
400-
if size == None:
400+
if size is None:
401401
size = (large or small) if (role == "hub") else (small or large)
402402
user = criteria.get("user") or aws_defaults["user"]
403403
ami = criteria.get("ami") or _get_ami(criteria, driver)

cf_remote/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def copy_file(input_path, output_path):
218218

219219

220220
def is_different_checksum(checksum, content):
221-
assert type(content) == bytes
221+
assert type(content) is bytes
222222

223223
digest = hashlib.sha256(content).digest().hex()
224224
return checksum != digest

cf_remote/web.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
from collections import OrderedDict
77
from cf_remote.utils import (
88
is_different_checksum,
9-
user_error,
109
write_json,
1110
mkdir,
12-
parse_json,
1311
)
1412
from cf_remote import log
1513
from cf_remote.paths import cf_remote_dir, cf_remote_packages_dir

tests/test_packages.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import json
2-
from collections import OrderedDict
3-
41
from cf_remote.packages import Release
52
from cf_remote.utils import read_json
6-
from cf_remote import log
7-
8-
# log.set_level("debug")
93

104

115
def test_release():

0 commit comments

Comments
 (0)