Skip to content

Commit d9688fa

Browse files
authored
refactor: use single quotes consistently in Python scripts (#301)
1 parent 7d242c6 commit d9688fa

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

generators/generate-debian-versions.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def is_unsupported_comparison(line):
3131

3232

3333
def uncomment(line):
34-
if line.startswith("#"):
34+
if line.startswith('#'):
3535
return line[1:]
36-
if line.startswith("//"):
36+
if line.startswith('//'):
3737
return line[2:]
3838
return line
3939

4040

4141
def download_debian_db():
42-
urllib.request.urlretrieve("https://osv-vulnerabilities.storage.googleapis.com/Debian/all.zip", "debian-db.zip")
42+
urllib.request.urlretrieve('https://osv-vulnerabilities.storage.googleapis.com/Debian/all.zip', 'debian-db.zip')
4343

4444

4545
def extract_packages_with_versions(osvs):
@@ -75,17 +75,17 @@ def __init__(self, cache_path):
7575
def _load_cache(self):
7676
if self.cache_path:
7777
self.cache_path.touch()
78-
with open(self.cache_path, "r") as f:
78+
with open(self.cache_path, 'r') as f:
7979
lines = f.readlines()
8080

8181
for line in lines:
8282
line = line.strip()
83-
key, result = line.split(",")
83+
key, result = line.split(',')
8484

85-
if result == "True":
85+
if result == 'True':
8686
self.cache[key] = True
8787
continue
88-
if result == "False":
88+
if result == 'False':
8989
self.cache[key] = False
9090
continue
9191

@@ -95,15 +95,15 @@ def _save_to_cache(self, key, result):
9595
self.cache[key] = result
9696
if self.cache_path:
9797
self.cache_path.touch()
98-
with open(self.cache_path, "a") as f:
99-
f.write(f"{key},{result}\n")
98+
with open(self.cache_path, 'a') as f:
99+
f.write(f'{key},{result}\n')
100100

101101
def compare(self, a, op, b):
102-
key = f"{a} {op} {b}"
102+
key = f'{a} {op} {b}'
103103
if key in self.cache:
104104
return self.cache[key]
105105

106-
cmd = ["dpkg", "--compare-versions", a, op, b]
106+
cmd = ['dpkg', '--compare-versions', a, op, b]
107107
out = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
108108

109109
if out.stdout:
@@ -116,7 +116,7 @@ def compare(self, a, op, b):
116116
return r
117117

118118

119-
debian_comparer = DebianVersionComparer("/tmp/debian-versions-generator-cache.csv")
119+
debian_comparer = DebianVersionComparer('/tmp/debian-versions-generator-cache.csv')
120120

121121

122122
class DebianVersion:
@@ -144,39 +144,39 @@ def compare(v1, relate, v2):
144144
return ops[relate](v1, v2)
145145

146146

147-
def compare_versions(lines, select="all"):
147+
def compare_versions(lines, select='all'):
148148
has_any_failed = False
149149

150150
for line in lines:
151151
line = line.strip()
152152

153-
if line == "" or line.startswith('#') or line.startswith('//'):
153+
if line == '' or line.startswith('#') or line.startswith('//'):
154154
maybe_unsupported = uncomment(line).strip()
155155

156156
if is_unsupported_comparison(maybe_unsupported):
157-
print(f"\033[96mS\033[0m: \033[93m{maybe_unsupported}\033[0m")
157+
print(f'\033[96mS\033[0m: \033[93m{maybe_unsupported}\033[0m')
158158
continue
159159

160-
v1, op, v2 = line.strip().split(" ")
160+
v1, op, v2 = line.strip().split(' ')
161161

162162
r = compare(DebianVersion(v1), op, DebianVersion(v2))
163163

164164
if not r:
165165
has_any_failed = r
166166

167-
if select == "failures" and r:
167+
if select == 'failures' and r:
168168
continue
169169

170-
if select == "successes" and not r:
170+
if select == 'successes' and not r:
171171
continue
172172

173173
color = '\033[92m' if r else '\033[91m'
174-
rs = "T" if r else "F"
175-
print(f"{color}{rs}\033[0m: \033[93m{line}\033[0m")
174+
rs = 'T' if r else 'F'
175+
print(f'{color}{rs}\033[0m: \033[93m{line}\033[0m')
176176
return has_any_failed
177177

178178

179-
def compare_versions_in_file(filepath, select="all"):
179+
def compare_versions_in_file(filepath, select='all'):
180180
with open(filepath) as f:
181181
lines = f.readlines()
182182
return compare_versions(lines, select)
@@ -188,10 +188,10 @@ def generate_version_compares(versions):
188188
if i == 0:
189189
continue
190190

191-
comparison = f"{versions[i - 1]} < {version}\n"
191+
comparison = f'{versions[i - 1]} < {version}\n'
192192

193193
if is_unsupported_comparison(comparison.strip()):
194-
comparison = "# " + comparison
194+
comparison = '# ' + comparison
195195
comparisons.append(comparison)
196196
return comparisons
197197

@@ -218,16 +218,16 @@ def fetch_packages_versions():
218218
return extract_packages_with_versions(osvs)
219219

220220

221-
outfile = "pkg/semantic/fixtures/debian-versions-generated.txt"
221+
outfile = 'pkg/semantic/fixtures/debian-versions-generated.txt'
222222

223223
packs = fetch_packages_versions()
224-
with open(outfile, "w") as f:
224+
with open(outfile, 'w') as f:
225225
f.writelines(generate_package_compares(packs))
226-
f.write("\n")
226+
f.write('\n')
227227

228228
# set this to either "failures" or "successes" to only have those comparison results
229229
# printed; setting it to anything else will have all comparison results printed
230-
show = os.environ.get("VERSION_GENERATOR_PRINT", "failures")
230+
show = os.environ.get('VERSION_GENERATOR_PRINT', 'failures')
231231

232232
did_any_fail = compare_versions_in_file(outfile, show)
233233

generators/generate-pypi-versions.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import urllib.request
88
import zipfile
99

10-
# this requires you run "pip install packaging" - have to be careful about versions too
11-
# because of the "legacy version" stuff
10+
# this requires you run 'pip install packaging' - have to be careful about versions too
11+
# because of the 'legacy version' stuff
1212

1313
# An array of version comparisons that are known to be unsupported and so
1414
# should be commented out in the generated fixture.
@@ -24,15 +24,15 @@ def is_unsupported_comparison(line):
2424

2525

2626
def uncomment(line):
27-
if line.startswith("#"):
27+
if line.startswith('#'):
2828
return line[1:]
29-
if line.startswith("//"):
29+
if line.startswith('//'):
3030
return line[2:]
3131
return line
3232

3333

3434
def download_pypi_db():
35-
urllib.request.urlretrieve("https://osv-vulnerabilities.storage.googleapis.com/PyPI/all.zip", "pypi-db.zip")
35+
urllib.request.urlretrieve('https://osv-vulnerabilities.storage.googleapis.com/PyPI/all.zip', 'pypi-db.zip')
3636

3737

3838
def extract_packages_with_versions(osvs):
@@ -52,7 +52,7 @@ def extract_packages_with_versions(osvs):
5252
try:
5353
dict[package].append(packaging.version.parse(version))
5454
except packaging.version.InvalidVersion:
55-
print(f"skipping invalid version {version} for {package}")
55+
print(f'skipping invalid version {version} for {package}')
5656

5757
# deduplicate and sort the versions for each package
5858
for package in dict:
@@ -66,39 +66,39 @@ def compare(v1, relate, v2):
6666
return ops[relate](v1, v2)
6767

6868

69-
def compare_versions(lines, select="all"):
69+
def compare_versions(lines, select='all'):
7070
has_any_failed = False
7171

7272
for line in lines:
7373
line = line.strip()
7474

75-
if line == "" or line.startswith('#') or line.startswith('//'):
75+
if line == '' or line.startswith('#') or line.startswith('//'):
7676
maybe_unsupported = uncomment(line).strip()
7777

7878
if is_unsupported_comparison(maybe_unsupported):
79-
print(f"\033[96mS\033[0m: \033[93m{maybe_unsupported}\033[0m")
79+
print(f'\033[96mS\033[0m: \033[93m{maybe_unsupported}\033[0m')
8080
continue
8181

82-
v1, op, v2 = line.strip().split(" ")
82+
v1, op, v2 = line.strip().split(' ')
8383

8484
r = compare(packaging.version.parse(v1), op, packaging.version.parse(v2))
8585

8686
if not r:
8787
has_any_failed = True
8888

89-
if select == "failures" and r:
89+
if select == 'failures' and r:
9090
continue
9191

92-
if select == "successes" and not r:
92+
if select == 'successes' and not r:
9393
continue
9494

9595
color = '\033[92m' if r else '\033[91m'
96-
rs = "T" if r else "F"
97-
print(f"{color}{rs}\033[0m: \033[93m{line}\033[0m")
96+
rs = 'T' if r else 'F'
97+
print(f'{color}{rs}\033[0m: \033[93m{line}\033[0m')
9898
return has_any_failed
9999

100100

101-
def compare_versions_in_file(filepath, select="all"):
101+
def compare_versions_in_file(filepath, select='all'):
102102
with open(filepath) as f:
103103
lines = f.readlines()
104104
return compare_versions(lines, select)
@@ -110,10 +110,10 @@ def generate_version_compares(versions):
110110
if i == 0:
111111
continue
112112

113-
comparison = f"{versions[i - 1]} < {version}\n"
113+
comparison = f'{versions[i - 1]} < {version}\n'
114114

115115
if is_unsupported_comparison(comparison.strip()):
116-
comparison = "# " + comparison
116+
comparison = '# ' + comparison
117117
comparisons.append(comparison)
118118
return comparisons
119119

@@ -140,16 +140,16 @@ def fetch_packages_versions():
140140
return extract_packages_with_versions(osvs)
141141

142142

143-
outfile = "pkg/semantic/fixtures/pypi-versions-generated.txt"
143+
outfile = 'pkg/semantic/fixtures/pypi-versions-generated.txt'
144144

145145
packs = fetch_packages_versions()
146-
with open(outfile, "w") as f:
146+
with open(outfile, 'w') as f:
147147
f.writelines(generate_package_compares(packs))
148-
f.write("\n")
148+
f.write('\n')
149149

150-
# set this to either "failures" or "successes" to only have those comparison results
150+
# set this to either 'failures' or 'successes' to only have those comparison results
151151
# printed; setting it to anything else will have all comparison results printed
152-
show = os.environ.get("VERSION_GENERATOR_PRINT", "failures")
152+
show = os.environ.get('VERSION_GENERATOR_PRINT', 'failures')
153153

154154
did_any_fail = compare_versions_in_file(outfile, show)
155155

0 commit comments

Comments
 (0)