8000 Merge pull request #660 from realpython/python-uv · realpython/materials@e1e1066 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1e1066

Browse files
authored
Merge pull request #660 from realpython/python-uv
Sample code for the article on `uv`
2 parents 2a88b23 + 0e848fd commit e1e1066

File tree

4 files changed

+225
-0
lines changed
Filter options

4 files changed

+225
-0
lines changed

python-uv/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Managing Python Projects With `uv`: An All-in-One Solution
2+
3+
This folder provides the code examples for the Real Python tutorial [Managing Python Projects With `uv`: An All-in-One Solution](https://realpython.com/python-uv/).

python-uv/main.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import argparse
2+
import sys
3+
4+
import requests
5+
6+
7+
def get_breeds_info():
8+
response = requests.get("https://api.thecatapi.com/v1/breeds")
9+
response.raise_for_status()
10+
return response.json()
11+
12+
13+
def find_breed_info(breed_name):
14+
json_response = get_breeds_info()
15+
for breed in json_response:
16+
if breed["name"] == breed_name:
17+
return breed
18+
return None
19+
20+
21+
def display_breed_profile(breed):
22+
print(f"\n{breed['name']:-^30s}")
23+
print(f"Origin: {breed['origin']}")
24+
print(f"Temperament: {breed['temperament']}")
25+
print(f"Life Span: {breed['life_span']} years")
26+
print(f"Weight: {breed['weight']['imperial']} lbs")
27+
if breed.get("wikipedia_url"):
28+
print(f"\nLearn more: {breed['wikipedia_url']}")
29+
30+
31+
def parse_args():
32+
parser = argparse.ArgumentParser(
33+
description="Get information about cat breeds",
34+
)
35+
parser.add_argument(
36+
"breed",
37+
help="Name of cat breed (e.g., 'Siamese')",
38+
)
39+
return parser.parse_args()
40+
41+
42+
def main():
43+
args = parse_args()
44+
try:
45+
breed = find_breed_info(args.breed)
46+
if not breed:
47+
print("Breed not found. Try another breed name.")
48+
return 0
49+
display_breed_profile(breed)
50+
except Exception as e:
51+
print(f"Error: {e}")
52+
return 1
53+
54+
return 0
55+
56+
57+
if __name__ == "__main__":
58+
sys.exit(main())

python-uv/pyproject.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[project]
2+
name = "rpcats"
3+
version = "0.1.0"
4+
description = "Display cat information for the specified breed."
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"requests>=2.32.3",
9+
]
10+
11+
[dependency-groups]
12+
dev = [
13+
"pytest>=8.3.5",
14+
]
15+
16+
[project.scripts]
17+
rpcats = "main:main"
18+
19+
[build-system]
20+
requires = ["setuptools>=78.1.0", "wheel>=0.45.1"]
21+
build-backend = "setuptools.build_meta"
22+
23+
[[tool.uv.index]]
24+
name = "testpypi"
25+
url = "https://test.pypi.org/simple/"
26+
publish-url = "https://test.pypi.org/legacy/"
27+
explicit = true

python-uv/uv.lock

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0