-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Sample code for the article on uv
#660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
257a83f
Sample code for the article on `uv`
lpozo b7c7687
Merge branch 'master' into python-uv
lpozo d04fdc7
TR updates, first round
lpozo fd8ac39
Fix formatting issues
lpozo 6caca3e
Merge branch 'master' into python-uv
lpozo a5666ea
TR updates, second round
lpozo 99ea39d
Add blank line
lpozo 0e848fd
Merge branch 'master' into python-uv
brendaweles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Managing Python Projects With `uv`: An All-in-One Solution | ||
|
|
||
| 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/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import argparse | ||
| import sys | ||
|
|
||
| import requests | ||
|
|
||
|
|
||
| def get_breeds_info(): | ||
| response = requests.get("https://api.thecatapi.com/v1/breeds") | ||
| response.raise_for_status() | ||
| return response.json() | ||
|
|
||
|
|
||
| def find_breed_info(breed_name): | ||
| json_response = get_breeds_info() | ||
| for breed in json_response: | ||
| if breed["name"] == breed_name: | ||
| return breed | ||
| return {} | ||
|
|
||
|
|
||
| def display_breed_profile(breed): | ||
| print(f"\n{breed['name']:-^30s}") | ||
| print(f"Origin: {breed['origin']}") | ||
| print(f"Temperament: {breed['temperament']}") | ||
| print(f"Life Span: {breed['life_span']} years") | ||
| print(f"Weight: {breed['weight']['imperial']} lbs") | ||
| if breed.get("wikipedia_url"): | ||
| print(f"\nLearn more: {breed['wikipedia_url']}") | ||
|
|
||
|
|
||
| def parse_args(): | ||
| parser = argparse.ArgumentParser( | ||
| description="Get information about cat breeds", | ||
| ) | ||
| parser.add_argument( | ||
| "breed", | ||
| help="Name of cat breed (e.g., 'Siamese')", | ||
| ) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main(): | ||
| args = parse_args() | ||
| try: | ||
| breed = find_breed_info(args.breed) | ||
| if not breed: | ||
| print("Breed not found. Try another breed name.") | ||
| return 0 | ||
| display_breed_profile(breed) | ||
| except Exception as e: | ||
| print(f"Error: {e}") | ||
| return 1 | ||
|
|
||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [project] | ||
| name = "rpcats" | ||
| version = "0.1.0" | ||
| description = "Add your description here" | ||
|
martin-martin marked this conversation as resolved.
Outdated
|
||
| readme = "README.md" | ||
| requires-python = ">=3.13" | ||
| dependencies = [ | ||
| "requests>=2.32.3", | ||
| ] | ||
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "pytest>=8.3.5", | ||
| ] | ||
|
|
||
| [project.scripts] | ||
| rpcats = "main:main" | ||
|
|
||
| [build-system] | ||
| requires = ["setuptools>=78.1.0", "wheel>=0.45.1"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [[tool.uv.index]] | ||
| name = "testpypi" | ||
| url = "https://test.pypi.org/simple/" | ||
| publish-url = "https://test.pypi.org/legacy/" | ||
| explicit = true | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.