Skip to content

Commit 78d20e5

Browse files
authored
Fix compat with pydantic 2 (#518)
1 parent f81b469 commit 78d20e5

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

jupyter_releaser/cli.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ def list_commands(self, ctx):
146146
return self.commands.keys()
147147

148148

149-
@click.group(cls=ReleaseHelperGroup)
149+
@click.group(cls=ReleaseHelperGroup) # type:ignore[arg-type]
150150
@click.option("--force", default=False, help="Force a command to run even when skipped by config")
151151
def main(force):
152152
"""Jupyter Releaser scripts"""
153153
pass
154154

155155

156156
# Extracted common options
157-
version_spec_options = [
157+
version_spec_options: t.Any = [
158158
click.option(
159159
"--version-spec",
160160
envvar="RH_VERSION_SPEC",
@@ -164,7 +164,7 @@ def main(force):
164164
]
165165

166166

167-
post_version_spec_options = [
167+
post_version_spec_options: t.Any = [
168168
click.option(
169169
"--post-version-spec",
170170
envvar="RH_POST_VERSION_SPEC",
@@ -179,24 +179,26 @@ def main(force):
179179
),
180180
]
181181

182-
version_cmd_options = [
182+
version_cmd_options: t.Any = [
183183
click.option("--version-cmd", envvar="RH_VERSION_COMMAND", help="The version command")
184184
]
185185

186186

187-
branch_options = [
187+
branch_options: t.Any = [
188188
click.option("--ref", envvar="RH_REF", help="The source reference"),
189189
click.option("--branch", envvar="RH_BRANCH", help="The target branch"),
190190
click.option("--repo", envvar="RH_REPOSITORY", help="The git repo"),
191191
]
192192

193-
auth_options = [
193+
auth_options: t.Any = [
194194
click.option("--auth", envvar="GITHUB_ACCESS_TOKEN", help="The GitHub auth token"),
195195
]
196196

197-
username_options = [click.option("--username", envvar="GITHUB_ACTOR", help="The git username")]
197+
username_options: t.Any = [
198+
click.option("--username", envvar="GITHUB_ACTOR", help="The git username")
199+
]
198200

199-
dist_dir_options = [
201+
dist_dir_options: t.Any = [
200202
click.option(
201203
"--dist-dir",
202204
envvar="RH_DIST_DIR",
@@ -205,7 +207,7 @@ def main(force):
205207
)
206208
]
207209

208-
python_packages_options = [
210+
python_packages_options: t.Any = [
209211
click.option(
210212
"--python-packages",
211213
envvar="RH_PYTHON_PACKAGES",
@@ -215,7 +217,7 @@ def main(force):
215217
)
216218
]
217219

218-
check_imports_options = [
220+
check_imports_options: t.Any = [
219221
click.option(
220222
"--check-imports",
221223
envvar="RH_CHECK_IMPORTS",
@@ -225,20 +227,20 @@ def main(force):
225227
)
226228
]
227229

228-
dry_run_options = [
230+
dry_run_options: t.Any = [
229231
click.option("--dry-run", is_flag=True, envvar="RH_DRY_RUN", help="Run as a dry run")
230232
]
231233

232234

233-
git_url_options = [click.option("--git-url", help="A custom url for the git repository")]
235+
git_url_options: t.Any = [click.option("--git-url", help="A custom url for the git repository")]
234236

235237

236-
release_url_options = [
238+
release_url_options: t.Any = [
237239
click.option("--release-url", envvar="RH_RELEASE_URL", help="A draft GitHub release url")
238240
]
239241

240242

241-
changelog_path_options = [
243+
changelog_path_options: t.Any = [
242244
click.option(
243245
"--changelog-path",
244246
envvar="RH_CHANGELOG",
@@ -247,7 +249,7 @@ def main(force):
247249
),
248250
]
249251

250-
since_options = [
252+
since_options: t.Any = [
251253
click.option(
252254
"--since",
253255
envvar="RH_SINCE",
@@ -262,7 +264,7 @@ def main(force):
262264
),
263265
]
264266

265-
changelog_options = (
267+
changelog_options: t.Any = (
266268
branch_options
267269
+ auth_options
268270
+ changelog_path_options
@@ -277,7 +279,7 @@ def main(force):
277279
]
278280
)
279281

280-
npm_install_options = [
282+
npm_install_options: t.Any = [
281283
click.option(
282284
"--npm-install-options",
283285
envvar="RH_NPM_INSTALL_OPTIONS",
@@ -286,7 +288,7 @@ def main(force):
286288
)
287289
]
288290

289-
pydist_check_options = [
291+
pydist_check_options: t.Any = [
290292
click.option(
291293
"--pydist-check-cmd",
292294
envvar="RH_PYDIST_CHECK_CMD",

jupyter_releaser/mock_github.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def write_to_file(name, data):
4848
for key in data:
4949
value = data[key]
5050
if isinstance(value, BaseModel):
51-
value = json.loads(value.json())
51+
if hasattr(value, 'model_dump_json'):
52+
value = json.loads(value.model_dump_json())
53+
else:
54+
value = json.loads(value.json())
5255
result[key] = value
5356
with open(source_file, "w") as fid:
5457
json.dump(result, fid)
@@ -145,7 +148,7 @@ def list_releases(owner: str, repo: str) -> List[Release]:
145148
@app.post("/repos/{owner}/{repo}/releases")
146149
async def create_a_release(owner: str, repo: str, request: Request) -> Release:
147150
"""https://docs.github.com/en/rest/releases/releases#create-a-release"""
148-
release_id = uuid.uuid4().int
151+
release_id = uuid.uuid4().int % (2**32 - 1)
149152
data = await request.json()
150153
base_url = get_mock_github_url()
151154
url = f"{base_url}/repos/{owner}/{repo}/releases/{release_id}"
@@ -183,7 +186,7 @@ async def upload_a_release_asset(owner: str, repo: str, release_id: int, request
183186
"""https://docs.github.com/en/rest/releases/assets#upload-a-release-asset"""
184187
base_url = get_mock_github_url()
185188
model = releases[str(release_id)]
186-
asset_id = uuid.uuid4().int
189+
asset_id = uuid.uuid4().int % (2**32 - 1)
187190
name = request.query_params["name"]
188191
with open(f"{static_dir}/{asset_id}", "wb") as fid:
189192
async for chunk in request.stream():
@@ -242,7 +245,11 @@ def create_a_pull_request(owner: str, repo: str) -> PullRequest:
242245
@app.post("/repos/{owner}/{repo}/issues/{issue_number}/labels")
243246
def add_labels_to_an_issue(owner: str, repo: str, issue_number: int) -> BaseModel:
244247
"""https://docs.github.com/en/rest/issues/labels#add-labels-to-an-issue"""
245-
return BaseModel()
248+
249+
class _Inner(BaseModel):
250+
pass
251+
252+
return _Inner()
246253

247254

248255
@app.post("/repos/{owner}/{repo}/git/refs")

0 commit comments

Comments
 (0)