File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -214,6 +214,12 @@ ignore = [
214214[tool .ruff .lint .isort ]
215215force-single-line = false
216216
217+ [tool .ty .lint ]
218+ # Needed because importlib_metadata is only installed on Python < 3.10,
219+ # but we need ty:ignore for when ty runs on Python >= 3.10
220+ ignore = [" unused-ignore-comment" ]
221+
222+
217223[tool .uv ]
218224package = true
219225default-groups = " all"
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env -S uv run --script
2+ # /// script
3+ # dependencies = [
4+ # "httpclient-logging",
5+ # "requests",
6+ # "rich",
7+ # ]
8+ # ///
9+
10+ """Demo requests usage."""
11+
12+ import logging
13+
14+ import requests
15+ import rich
16+ import rich .logging
17+
18+ # configure colorized logging to console
19+ # enables output from all loggers including http.client
20+ logging .basicConfig (
21+ level = logging .DEBUG ,
22+ format = "%(name)s - %(message)s" ,
23+ handlers = [rich .logging .RichHandler (rich_tracebacks = False )],
24+ )
25+
26+ # experiment with different levels
27+ # logging.getLogger("example").setLevel(logging.INFO)
28+ # logging.getLogger("http.client").setLevel(logging.INFO)
29+ # logging.getLogger("urllib3").setLevel(logging.INFO)
30+
31+ log = logging .getLogger ("example" )
32+
33+ url = "https://peps.python.org/api/peps.json"
34+
35+ log .info (f"Fetching data from { url } " )
36+ resp = requests .get (url , timeout = 5 )
37+ log .info ("Requests response status code: %s" , resp .status_code )
38+ data = resp .json ()
39+
40+ rich .print ([(k , v ["title" ]) for k , v in data .items ()][:10 ])
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env -S uv run --script
2+ # /// script
3+ # dependencies = [
4+ # "httpclient-logging",
5+ # "libranet-logging",
6+ # "requests",
7+ # "rich",
8+ # ]
9+ # ///
10+
11+ """Demo requests usage."""
12+
13+ import json
14+ import logging
15+ import urllib .request
16+
17+ # configure colorized logging to console
18+ # enables output from all loggers including http.client
19+ # logging.basicConfig(
20+ # level=logging.DEBUG,
21+ # format="%(name)s - %(message)s",
22+ # handlers=[rich.logging.RichHandler(rich_tracebacks=False)],
23+ # )
24+ import libranet_logging
25+ import rich
26+ import rich .logging
27+
28+ libranet_logging .initialize ()
29+
30+ # experiment with different levels
31+ # logging.getLogger("example").setLevel(logging.INFO)
32+ # logging.getLogger("http.client").setLevel(logging.INFO)
33+ # logging.getLogger("urllib3").setLevel(logging.INFO)
34+
35+ log = logging .getLogger ("example" )
36+
37+ url = "https://peps.python.org/api/peps.json"
38+
39+ log .info (f"Fetching data from { url } " )
40+ resp = urllib .request .urlopen (url , timeout = 5 )
41+ log .info ("Requests response status code: %s" , resp .code )
42+ data = json .load (resp )
43+
44+ rich .print ([(k , v ["title" ]) for k , v in data .items ()][:10 ])
Original file line number Diff line number Diff line change 1212if sys .version_info >= (3 , 10 ):
1313 import importlib .metadata as importlib_metadata
1414else :
15- import importlib_metadata
15+ import importlib_metadata # ty:ignore[unresolved-import]
1616
1717PACKAGE : str = __package__ or ""
1818
You can’t perform that action at this time.
0 commit comments