Skip to content

Commit bfafab4

Browse files
authored
Lint Tiltfiles with ruff and fix findings (#625)
Signed-off-by: Daniel Bast <[email protected]>
1 parent 41dae53 commit bfafab4

File tree

28 files changed

+155
-148
lines changed

28 files changed

+155
-148
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ repos:
1111
- id: check-executables-have-shebangs
1212
- id: check-shebang-scripts-are-executable
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.8.2
14+
rev: v0.8.4
1515
hooks:
1616
- id: ruff
1717
args: [--fix]
18-
exclude: ^.*/Tiltfile$
18+
types_or: [tiltfile]
1919
- repo: https://github.com/shellcheck-py/shellcheck-py
2020
rev: v0.10.0.1
2121
hooks:

cert_manager/Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def deploy_cert_manager(registry="quay.io/jetstack", version="v1.3.1", load_to_k
3333
else:
3434
cert_manager_test_resources_versioned = cert_manager_test_resources.format(cert_manager_api_version='v1')
3535

36-
if load_to_kind == True:
36+
if load_to_kind:
3737
print("Loading images to kind")
3838
# Prepull all the cert-manager images to your local environment and then load them directly into kind. This speeds up
3939
# setup if you're repeatedly destroying and recreating your kind cluster, as it doesn't have to pull the images over

configmap/Tiltfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def configmap_yaml(name, namespace="", from_file=None, watch=True, from_env_file
4040
for f in from_file:
4141
args.extend(["--from-file", f])
4242
if watch:
43-
l = f.split('=')
44-
watch_file(l[len(l)-1])
43+
line = f.split('=')
44+
watch_file(line[len(line)-1])
4545
generator = True
4646
else:
4747
fail("Bad from_file argument: %s" % from_file)

configmap/test/Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ configmap_create('job-config', from_file='my-job.ini=./my-job.ini')
44
configmap_create('env-job-config', from_env_file='my-job.env')
55
configmap_from_dict('from-dict-config', inputs={"hello":"world"})
66

7-
k8s_yaml('job.yaml')
7+
k8s_yaml('job.yaml')

file_sync_only/Tiltfile

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def file_sync_only(image='', manifests=[], deps=["."], live_update=[], allow_dup
3737

3838
# sync files at first time
3939
def _first_sync_from_liveupdate(image, live_update, k8s_resources):
40-
for l in live_update:
41-
if type(l) == "live_update_sync_step":
42-
local_path, remote_path = _get_sync_params(l)
40+
for step in live_update:
41+
if type(step) == "live_update_sync_step":
42+
local_path, remote_path = _get_sync_params(step)
4343
syncname = "firstsync-%s-%s" % (image.replace("/", "_"), local_path.replace("/", "_"))
4444
local_resource(syncname,
4545
'touch %s' % local_path,
@@ -81,4 +81,3 @@ def _get_related_resources(manifests, image):
8181
fail("found multiple image tags for %s in manifests %s" % (image, manifests))
8282

8383
return k8s_resources, tags_in_manifests[0]
84-

get_obj/Tiltfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
def get_container(decoded_yaml, container_selector):
22
containers=decoded_yaml["spec"]["template"]["spec"]["containers"]
3-
found_containers=[]
43

54
for container in containers:
65
if container["name"] == container_selector:
76
return container
8-
7+
98
fail("failed to find container %s in the manifest %s" % (container_selector, containers))
109

1110
def get_image(container):
1211
return container["image"]
1312

1413
def remove_probe(container, probe):
1514
if container.get(probe):
16-
container.pop(probe)
15+
container.pop(probe)
1716

1817
def get_obj(name, kind, container_selector = None, namespace = None, disable_probes = False):
1918
"""

get_obj/test/Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ k8s_resource(
2323
"8080:8080",
2424
"9229:9229"
2525
]
26-
)
26+
)

get_obj/test/setup.Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ docker_build(
55
'remote-dev-test-image',
66
'.'
77
)
8-
k8s_yaml('deployment.yaml')
8+
k8s_yaml('deployment.yaml')

git_resource/Tiltfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ def git_checkout(repository_url, checkout_dir=None, unsafe_mode=False):
106106

107107
def deploy_from_dir(resource_name, directory, dockerfile='Dockerfile', namespace='default', resource_deps=[], port_forwards=[], build_callback=None, deployment_callback=None):
108108
if deployment_callback == None:
109-
deployment_callback = lambda resource_name, image_name, namespace: _default_deployment_callback(resource_name, image_name, namespace)
109+
def deployment_callback(resource_name, image_name, namespace):
110+
return _default_deployment_callback(resource_name, image_name, namespace)
110111

111112
if build_callback == None:
112-
build_callback = lambda resource_name, directory, dockerfile: _default_build_callback(resource_name, directory, dockerfile=dockerfile)
113+
def build_callback(resource_name, directory, dockerfile):
114+
return _default_build_callback(resource_name, directory, dockerfile=dockerfile)
113115

114116
image_name = build_callback(resource_name, directory, dockerfile=dockerfile)
115117
yaml = deployment_callback(resource_name, image_name, namespace)

hasura/Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DEFAULT_HASURA_PORT = 8080
1111
DEFAULT_HASURA_RESOURCE_NAME = 'hasura'
1212

1313
def hasura_console(release_name='',
14-
path='.',
14+
path='.',
1515
hasura_resource_name=None,
1616
hasura_endpoint= 'http://localhost:8080',
1717
hasura_secret=DEFAULT_HASURA_SECRET,

helm_remote/Tiltfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def helm_remote_yaml(chart, repo_url='', repo_name='', release_name='', values=[
131131
# str.isalnum accepts dots, which is only dangerous when slashes are allowed
132132
# https://helm.sh/docs/chart_best_practices/conventions/#chart-names
133133

134-
if chart.replace('-', '').isalnum() == False or chart != chart.replace('.', ''):
134+
if not chart.replace('-', '').isalnum() or chart != chart.replace('.', ''):
135135
# https://helm.sh/docs/chart_best_practices/conventions/#chart-names
136136
fail('Chart name is not valid')
137137

138-
if repo_name != chart and repo_name.replace('-', '').isalnum() == False or repo_name != repo_name.replace('.', ''):
138+
if repo_name != chart and not repo_name.replace('-', '').isalnum() or repo_name != repo_name.replace('.', ''):
139139
# https://helm.sh/docs/chart_best_practices/conventions/#chart-names
140140
if not repo_name.startswith('oci://'):
141141
fail('Repo name is not valid')

k8s_yaml_glob/Tiltfile

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def k8s_yaml_glob(*glob_patterns, **kwargs):
1010

1111
for glob_pattern in glob_patterns:
1212
script = 'import glob; print("|".join( p for p in glob.glob(\"' + glob_pattern + '")))'
13-
cmd = python_cmd + " -c '" + script + "'"
1413
val = str(local(command=python_cmd + " -c '" + script + "'", quiet=False)).strip()
1514
yaml_paths = val.split("|")
1615
k8s_yaml(yaml_paths, **kwargs)

kubebuilder/Tiltfile

+17-17
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ def kubebuilder(DOMAIN, GROUP, VERSION, KIND, IMG='controller:latest', CONTROLLE
2424

2525
return encode_yaml_stream(decoded)
2626
return data
27-
27+
2828
def manifests():
2929
return 'controller-gen ' + CONTROLLERGEN
30-
30+
3131
def generate():
3232
return 'controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./...";'
33-
33+
3434
def vetfmt():
3535
return 'go vet ./...; go fmt ./...'
36-
36+
3737
# build to tilt_bin beause kubebuilder has a dockerignore for bin/
3838
def binary():
3939
return 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o tilt_bin/manager cmd/main.go'
@@ -43,29 +43,29 @@ def kubebuilder(DOMAIN, GROUP, VERSION, KIND, IMG='controller:latest', CONTROLLE
4343

4444
DIRNAME = os.path.basename(os. getcwd())
4545
# if kubebuilder
46-
if os.path.exists('go.mod') == False:
46+
if not os.path.exists('go.mod'):
4747
local("go mod init %s" % DIRNAME)
48-
49-
if os.path.exists('PROJECT') == False:
48+
49+
if not os.path.exists('PROJECT'):
5050
local("kubebuilder init --domain %s" % DOMAIN)
51-
52-
if os.path.exists('api') == False:
51+
52+
if not os.path.exists('api'):
5353
local("kubebuilder create api --resource --controller --group %s --version %s --kind %s" % (GROUP, VERSION, KIND))
54-
54+
5555
local(manifests() + generate())
56-
56+
5757
local_resource('CRD', manifests() + 'kustomize build config/crd | kubectl apply -f -', deps=["api"])
58-
58+
5959
k8s_yaml(yaml())
60-
60+
6161
deps = ['internal/controller', 'cmd/main.go']
6262
deps.append('api')
63-
63+
6464
local_resource('Watch&Compile', generate() + binary(), deps=deps, ignore=['*/*/zz_generated.deepcopy.go'])
65-
65+
6666
local_resource('Sample YAML', 'kubectl apply -f ./config/samples', deps=["./config/samples"], resource_deps=[DIRNAME + "-controller-manager"])
67-
68-
docker_build_with_restart(IMG, '.',
67+
68+
docker_build_with_restart(IMG, '.',
6969
dockerfile_contents=DOCKERFILE,
7070
entrypoint='/manager',
7171
only=['./tilt_bin/manager'],

list_dependencies/Tiltfile

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ load('ext://uibutton', 'cmd_button')
33
display_deps_path = os.path.join(os.getcwd(), 'deps.py')
44

55
def display_dependencies():
6-
cmd_button(
7-
name = 'show_deps',
8-
resource = '(Tiltfile)',
9-
argv = [display_deps_path],
10-
text = 'list pending dependencies',
11-
icon_name = 'account_tree'
12-
)
6+
cmd_button(
7+
name = 'show_deps',
8+
resource = '(Tiltfile)',
9+
argv = [display_deps_path],
10+
text = 'list pending dependencies',
11+
icon_name = 'account_tree'
12+
)

list_port_forwards/Tiltfile

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ load('ext://uibutton', 'cmd_button')
33
display_pf_script_path = os.path.join(os.getcwd(), "display_port_forwards.sh")
44

55
def display_port_forwards():
6-
cmd_button(
7-
name = 'which_ports',
8-
resource = '(Tiltfile)',
9-
argv = [display_pf_script_path],
10-
text='List port forwards',
11-
icon_name='travel_explore',
12-
)
6+
cmd_button(
7+
name = 'which_ports',
8+
resource = '(Tiltfile)',
9+
argv = [display_pf_script_path],
10+
text='List port forwards',
11+
icon_name='travel_explore',
12+
)

0 commit comments

Comments
 (0)