Skip to content

Commit b8ab929

Browse files
authored
Makefile, action: lint with mypy + resolve lints (#58)
Signed-off-by: Andrew Pan <[email protected]>
1 parent b71bf55 commit b8ab929

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ dev: env/pyvenv.cfg
1212

1313
.PHONY: lint
1414
lint: env/pyvenv.cfg action.py
15-
./env/bin/python -m black action.py
16-
./env/bin/python -m isort action.py
17-
./env/bin/python -m flake8 --max-line-length 100 action.py
15+
. ./env/bin/activate && \
16+
black action.py && \
17+
isort action.py && \
18+
mypy action.py && \
19+
flake8 --max-line-length 100 action.py

action.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
_HERE = Path(__file__).parent.resolve()
3232
_TEMPLATES = _HERE / "templates"
3333

34-
_SUMMARY = Path(os.getenv("GITHUB_STEP_SUMMARY")).open("a")
34+
_summary_path = os.getenv("GITHUB_STEP_SUMMARY")
35+
assert _summary_path is not None
36+
_SUMMARY = Path(_summary_path).open("a")
37+
3538
_RENDER_SUMMARY = os.getenv("GHA_SIGSTORE_PYTHON_SUMMARY", "true") == "true"
3639
_DEBUG = os.getenv("GHA_SIGSTORE_PYTHON_INTERNAL_BE_CAREFUL_DEBUG", "false") != "false"
3740

@@ -117,49 +120,49 @@ def _fatal_help(msg):
117120
sigstore_python_env["SIGSTORE_LOGLEVEL"] = "DEBUG"
118121

119122
identity_token = os.getenv("GHA_SIGSTORE_PYTHON_IDENTITY_TOKEN")
120-
if identity_token != "":
123+
if identity_token:
121124
sigstore_sign_args.extend(["--identity-token", identity_token])
122125

123126
client_id = os.getenv("GHA_SIGSTORE_PYTHON_OIDC_CLIENT_ID")
124-
if client_id != "":
127+
if client_id:
125128
sigstore_sign_args.extend(["--oidc-client-id", client_id])
126129

127130
client_secret = os.getenv("GHA_SIGSTORE_PYTHON_OIDC_CLIENT_SECRET")
128-
if client_secret != "":
131+
if client_secret:
129132
sigstore_sign_args.extend(["--oidc-client-secret", client_secret])
130133

131134
signature = os.getenv("GHA_SIGSTORE_PYTHON_SIGNATURE")
132-
if signature != "":
135+
if signature:
133136
sigstore_sign_args.extend(["--signature", signature])
134137
sigstore_verify_args.extend(["--signature", signature])
135138
signing_artifact_paths.append(signature)
136139

137140
certificate = os.getenv("GHA_SIGSTORE_PYTHON_CERTIFICATE")
138-
if certificate != "":
141+
if certificate:
139142
sigstore_sign_args.extend(["--certificate", certificate])
140143
sigstore_verify_args.extend(["--certificate", certificate])
141144
signing_artifact_paths.append(certificate)
142145

143146
bundle = os.getenv("GHA_SIGSTORE_PYTHON_BUNDLE")
144-
if bundle != "":
147+
if bundle:
145148
sigstore_sign_args.extend(["--bundle", bundle])
146149
sigstore_verify_args.extend(["--bundle", bundle])
147150
signing_artifact_paths.append(bundle)
148151

149152
fulcio_url = os.getenv("GHA_SIGSTORE_PYTHON_FULCIO_URL")
150-
if fulcio_url != "":
153+
if fulcio_url:
151154
sigstore_sign_args.extend(["--fulcio-url", fulcio_url])
152155

153156
rekor_url = os.getenv("GHA_SIGSTORE_PYTHON_REKOR_URL")
154-
if rekor_url != "":
157+
if rekor_url:
155158
sigstore_global_args.extend(["--rekor-url", rekor_url])
156159

157160
ctfe = os.getenv("GHA_SIGSTORE_PYTHON_CTFE")
158-
if ctfe != "":
161+
if ctfe:
159162
sigstore_sign_args.extend(["--ctfe", ctfe])
160163

161164
rekor_root_pubkey = os.getenv("GHA_SIGSTORE_PYTHON_REKOR_ROOT_PUBKEY")
162-
if rekor_root_pubkey != "":
165+
if rekor_root_pubkey:
163166
sigstore_global_args.extend(["--rekor-root-pubkey", rekor_root_pubkey])
164167

165168
if os.getenv("GHA_SIGSTORE_PYTHON_STAGING", "false") != "false":
@@ -170,15 +173,15 @@ def _fatal_help(msg):
170173
_fatal_help("verify-cert-identity must be specified when verify is enabled")
171174
elif not enable_verify and verify_cert_identity:
172175
_fatal_help("verify-cert-identity cannot be specified without verify: true")
173-
else:
176+
elif verify_cert_identity:
174177
sigstore_verify_args.extend(["--cert-identity", verify_cert_identity])
175178

176179
verify_oidc_issuer = os.getenv("GHA_SIGSTORE_PYTHON_VERIFY_OIDC_ISSUER")
177180
if enable_verify and not verify_oidc_issuer:
178181
_fatal_help("verify-oidc-issuer must be specified when verify is enabled")
179182
elif not enable_verify and verify_oidc_issuer:
180183
_fatal_help("verify-oidc-issuer cannot be specified without verify: true")
181-
else:
184+
elif verify_oidc_issuer:
182185
sigstore_verify_args.extend(["--cert-oidc-issuer", verify_oidc_issuer])
183186

184187
if os.getenv("GHA_SIGSTORE_PYTHON_RELEASE_SIGNING_ARTIFACTS") == "true":
@@ -211,8 +214,8 @@ def _fatal_help(msg):
211214
if "--bundle" not in sigstore_sign_args:
212215
signing_artifact_paths.append(f"{file_}.sigstore")
213216

214-
sigstore_sign_args.extend(files)
215-
sigstore_verify_args.extend(files)
217+
sigstore_sign_args.extend([str(f) for f in files])
218+
sigstore_verify_args.extend([str(f) for f in files])
216219

217220
_debug(f"signing: sigstore-python {[str(a) for a in sigstore_sign_args]}")
218221

@@ -273,7 +276,9 @@ def _fatal_help(msg):
273276
#
274277
# In GitHub Actions, environment variables can be made to persist across
275278
# workflow steps by appending to the file at `GITHUB_ENV`.
276-
with Path(os.getenv("GITHUB_ENV")).open("a") as gh_env:
279+
_github_env = os.getenv("GITHUB_ENV")
280+
assert _github_env is not None
281+
with Path(_github_env).open("a") as gh_env:
277282
# Multiline values must match the following syntax:
278283
#
279284
# {name}<<{delimiter}

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
flake8
22
isort
33
black
4+
mypy
5+
types-requests

0 commit comments

Comments
 (0)