bugdantic 0.4.0__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bugdantic
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Bugzilla client based on pydantic
5
5
  Author-email: James Graham <james@hoppipolla.co.uk>
6
6
  License-Expression: MPL-2.0
@@ -11,8 +11,9 @@ License-File: LICENSE
11
11
  Requires-Dist: httpx[http2]>=0.28.1
12
12
  Requires-Dist: pydantic>=2.11.3
13
13
  Provides-Extra: test
14
- Requires-Dist: mypy==1.18.2; extra == "test"
15
- Requires-Dist: ruff==0.14.1; extra == "test"
16
- Requires-Dist: pytest==8.4.2; extra == "test"
14
+ Requires-Dist: mypy==2.3.0; extra == "test"
15
+ Requires-Dist: ruff==0.16.2; extra == "test"
16
+ Requires-Dist: pytest==9.1.1; extra == "test"
17
17
  Requires-Dist: pytest-ruff==0.5; extra == "test"
18
+ Requires-Dist: ty==0.0.71; extra == "test"
18
19
  Dynamic: license-file
@@ -2,15 +2,13 @@ import base64
2
2
  import enum
3
3
  import json
4
4
  import logging
5
+ from collections.abc import Mapping, MutableMapping, Sequence
5
6
  from dataclasses import dataclass
6
7
  from datetime import datetime
7
8
  from typing import (
8
9
  Any,
9
10
  Generic,
10
- Mapping,
11
- MutableMapping,
12
11
  Optional,
13
- Sequence,
14
12
  Self,
15
13
  TypeVar,
16
14
  cast,
@@ -454,6 +452,13 @@ def bug_search_model(bug_type: type[BugType]) -> type[BugSearchGeneric[BugType]]
454
452
  )
455
453
 
456
454
 
455
+ def model_field_names(model: type[BaseModel]) -> list[str]:
456
+ return [
457
+ field.alias if field.alias else name
458
+ for name, field in model.model_fields.items()
459
+ ]
460
+
461
+
457
462
  class Bugzilla:
458
463
  def __init__(self, config: BugzillaConfig):
459
464
  self.config = config
@@ -488,8 +493,7 @@ class Bugzilla:
488
493
  if exclude_fields is not None:
489
494
  params["exclude_fields"] = ",".join(exclude_fields)
490
495
 
491
- if path.startswith("/"):
492
- path = path[1:]
496
+ path = path.removeprefix("/")
493
497
 
494
498
  url = urljoin(self.config.base_url, f"/rest/{path}")
495
499
 
@@ -508,13 +512,13 @@ class Bugzilla:
508
512
  assert response is not None
509
513
  try:
510
514
  response.raise_for_status()
511
- except Exception as e:
515
+ except Exception:
512
516
  msg = "Request failed"
513
517
  json_resp = response.json()
514
518
  if json_resp:
515
519
  msg += f"\n{json_resp.get('message')}"
516
520
  logging.error(msg)
517
- raise e
521
+ raise
518
522
  return response.json()
519
523
  else:
520
524
  logging.info(f"""Not updating, would send {method} request to {path} with body:
@@ -558,7 +562,7 @@ class Bugzilla:
558
562
  return self._bug(bug_id, Bug, include_fields)
559
563
 
560
564
  def bug_as(self, bug_id: int, bug_type: type[BugType]) -> Optional[BugType]:
561
- include_fields = list(bug_type.model_fields.keys())
565
+ include_fields = model_field_names(bug_type)
562
566
  return self._bug(bug_id, bug_type, include_fields)
563
567
 
564
568
  def bugs(
@@ -585,9 +589,9 @@ class Bugzilla:
585
589
  bug_ids: Sequence[int],
586
590
  bug_type: type[BugType],
587
591
  page_size: int = 100,
588
- ) -> list[Bug]:
592
+ ) -> list[BugType]:
589
593
  """Get multiple bugs specified by id"""
590
- results: list[Bug] = []
594
+ results: list[BugType] = []
591
595
  for bug_ids_chunk in [
592
596
  bug_ids[n : n + page_size] for n in range(0, len(bug_ids), page_size)
593
597
  ]:
@@ -668,8 +672,8 @@ class Bugzilla:
668
672
 
669
673
  def search_as(
670
674
  self, query: QueryParams, bug_type: type[BugType], page_size: int = 100
671
- ):
672
- include_fields = list(bug_type.model_fields.keys())
675
+ ) -> list[BugType]:
676
+ include_fields = model_field_names(bug_type)
673
677
  return self._search(bug_type, query, include_fields, page_size)
674
678
 
675
679
  def update_bugs(
@@ -1,12 +1,12 @@
1
1
  """Utility functions for working with cf_user_story fields that
2
2
  are used to store key: value pair data"""
3
3
 
4
+ import re
4
5
  from collections import defaultdict
5
- from enum import IntEnum
6
+ from collections.abc import Iterator, Mapping
6
7
  from dataclasses import dataclass
7
-
8
- import re
9
- from typing import Iterator, Optional, Mapping, Self
8
+ from enum import IntEnum
9
+ from typing import Optional, Self
10
10
 
11
11
 
12
12
  def parse(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bugdantic
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Bugzilla client based on pydantic
5
5
  Author-email: James Graham <james@hoppipolla.co.uk>
6
6
  License-Expression: MPL-2.0
@@ -11,8 +11,9 @@ License-File: LICENSE
11
11
  Requires-Dist: httpx[http2]>=0.28.1
12
12
  Requires-Dist: pydantic>=2.11.3
13
13
  Provides-Extra: test
14
- Requires-Dist: mypy==1.18.2; extra == "test"
15
- Requires-Dist: ruff==0.14.1; extra == "test"
16
- Requires-Dist: pytest==8.4.2; extra == "test"
14
+ Requires-Dist: mypy==2.3.0; extra == "test"
15
+ Requires-Dist: ruff==0.16.2; extra == "test"
16
+ Requires-Dist: pytest==9.1.1; extra == "test"
17
17
  Requires-Dist: pytest-ruff==0.5; extra == "test"
18
+ Requires-Dist: ty==0.0.71; extra == "test"
18
19
  Dynamic: license-file
@@ -2,7 +2,8 @@ httpx[http2]>=0.28.1
2
2
  pydantic>=2.11.3
3
3
 
4
4
  [test]
5
- mypy==1.18.2
6
- ruff==0.14.1
7
- pytest==8.4.2
5
+ mypy==2.3.0
6
+ ruff==0.16.2
7
+ pytest==9.1.1
8
8
  pytest-ruff==0.5
9
+ ty==0.0.71
@@ -5,7 +5,7 @@ authors = [
5
5
  {name = "James Graham", email = "james@hoppipolla.co.uk"}
6
6
  ]
7
7
 
8
- version = "0.4.0"
8
+ version = "0.4.2"
9
9
  requires-python = ">=3.11"
10
10
  license = "MPL-2.0"
11
11
  classifiers = [
@@ -20,8 +20,15 @@ dependencies = [
20
20
 
21
21
  [project.optional-dependencies]
22
22
  test = [
23
- "mypy==1.18.2",
24
- "ruff==0.14.1",
25
- "pytest==8.4.2",
23
+ "mypy==2.3.0",
24
+ "ruff==0.16.2",
25
+ "pytest==9.1.1",
26
26
  "pytest-ruff==0.5",
27
+ "ty==0.0.71",
27
28
  ]
29
+
30
+ [tool.mypy]
31
+ disallow_untyped_defs = true
32
+
33
+ [tool.ruff.lint]
34
+ ignore = ["UP045", "LOG015"]
@@ -1,5 +1,5 @@
1
1
  import pytest
2
- from pydantic import BaseModel
2
+ from pydantic import BaseModel, Field
3
3
 
4
4
  from bugdantic import Bugzilla, BugzillaConfig
5
5
  from bugdantic.bugzilla import BugComment
@@ -69,3 +69,14 @@ def test_search_as(bugzilla):
69
69
  assert isinstance(bug, BugData)
70
70
  assert bug.id == expected_id
71
71
  assert isinstance(bug.comments, list)
72
+
73
+
74
+ def test_bug_as_alias(bugzilla):
75
+ class BugData(BaseModel):
76
+ id: int
77
+ user_story: str = Field(alias="cf_user_story")
78
+
79
+ result = bugzilla.bug_as(975444, BugData)
80
+ assert isinstance(result, BugData)
81
+ assert result.id == 975444
82
+ assert result.user_story is not None
File without changes
File without changes
File without changes
File without changes