- 4
- 23 360
Timnology
Netherlands
Приєднався 6 лип 2024
Creating free educational videos for software developer and data engineer professionals and enthusiasts!
Create a modern pre-commit setup for Python using UV, Ruff and more
This video shows how to create a solid pre-commit setup for Python.
Previous video containing the CI pipeline: ua-cam.com/video/Y6D2XaFV3Cc/v-deo.html
The repo is available at github.com/timvancann/yt-python-ci
Write up is available at www.timnology.io/articles/python-pre-commit
Buy me a coffee: buymeacoffee.com/timvancann
Pre-commit: pre-commit.com/
#code #python #tutorial #education #cicd #uv #ruff #pyright #precommit
00:00:00 Intro
00:00:26 Goal
00:00:45 Installation
00:01:24 Lock file
00:02:01 Running the CLI
00:02:51 Ruff
00:03:00 Pyright
00:03:34 Tests
00:04:33 Outro
Previous video containing the CI pipeline: ua-cam.com/video/Y6D2XaFV3Cc/v-deo.html
The repo is available at github.com/timvancann/yt-python-ci
Write up is available at www.timnology.io/articles/python-pre-commit
Buy me a coffee: buymeacoffee.com/timvancann
Pre-commit: pre-commit.com/
#code #python #tutorial #education #cicd #uv #ruff #pyright #precommit
00:00:00 Intro
00:00:26 Goal
00:00:45 Installation
00:01:24 Lock file
00:02:01 Running the CLI
00:02:51 Ruff
00:03:00 Pyright
00:03:34 Tests
00:04:33 Outro
Переглядів: 1 804
Відео
Setup a modern Python Code Quality CI Pipeline using UV, Ruff and more
Переглядів 3,9 тис.2 місяці тому
This video shows how to setup a modern CI Pipeline using various tools such as UV, Ruff, Pytest and Pyright. A write-up is available at: www.timnology.io/articles/python-ci The repo is available at github.com/timvancann/yt-python-ci Buy me a coffee: buymeacoffee.com/timvancann #code #python #tutorial #education #cicd #uv #ruff #pyright 00:00:00 Intro 00:00:18 Initialisation 00:00:35 Lock file 0...
UV - A modern python project and dependency manager
Переглядів 15 тис.4 місяці тому
This video showcase the latest features of UV after their impressive blogpost: astral.sh/blog/uv-unified-python-packaging A write-up is available at: www.timnology.io/articles/uv Buy me a coffee: buymeacoffee.com/timvancann #code #python #tutorial #education 00:00 Intro 00:28 Installation 00:45 Initialization 01:07 Adding dependencies 01:37 Running commands 03:24 Installing python 04:15 Speed t...
Master the python logging module
Переглядів 3 тис.4 місяці тому
This video gives insight into the python logging module. Master handers, filters, formatters, log hierarchy and log configuration. A write-up is available at www.timnology.io/articles/python-logging Buy me a coffee: buymeacoffee.com/timvancann #python #code #tutorial #education 0:00 Intro 0:18 Logger 0:28 LogLevels 1:04 Handlers 1:42 Handler loglevel 2:07 Handler formatter 2:55 LastResort handl...
Thank you! Fantastic. Just was playing around with it and it was not working for me. Found your video and it helped :)
Have you considered adding mypy as well?
wait, it installing interpreter inside of .env ?
UV reserves a folder within your home directory to store all python versions and links the env to that location. You have quite a bit control over this: docs.astral.sh/uv/guides/install-python/
interestingly changing python version from the pyproject.toml and then running "uv sync" does not update the venv python version for me (windows user). I have to manually run "uv venv --python 3.x" and then rerun "uv sync" to reinstall the libraries
Please create more videos man!!!
I have a few more planned!
I was trying to do thesame task for more than week... building python software into packages is crap! UV makes it much more pleasent. Thanks for the video.
Can make video on pants compared to uv please please
What a gem!
Thank you so much for the follow up video. Another fantastic video. Could you please share your thoughts on the tools and ways to document your python projects.
To document the project I typically use www.mkdocs.org/ and use a CI pipeline to push it to a static website provider such as azure.microsoft.com/en-us/products/app-service/static. Alternatively you can host static websites on most cloud storages such as GCP Buckets, Amazon S3 and Azure Storage Accounts.
I love it a lot! 2 questions. 1) will you update the website to add pre-commit instruction? 2) the pre-commit versioned hooks aren't updated to stay in sync if pyproject.toml version are updated, do you have any idea how to keep the pre-commit and local project tooling on the same version? example: pyright recently complained: ``` WARNING: there is a new pyright version available (v1.1.387 -> v1.1.390). Please install the new version or set PYRIGHT_PYTHON_FORCE_VERSION to `latest` ``` which requires updating both files
1. Oh dang, thanks for the heads-up. I forgot to hit publish, the website is updated with the write-up now :). 2. There are a few ways to go about that, one way is to simply not update to the latest version unless you're missing features or run into bugs. A second is to indeed do it manually, for small projects that is usually fine. Lastly, the more mature option is to use automated systems such as docs.renovatebot.com/ which what I typically use. It supports UV, lock files AND pre-commit!
Thanks for that!
@0:44 just so you know: some of the characters in the icons are a lot closer together than the others, looks kinda weird. Maybe a kerning setting in the tool you're using to generate those?
Thanks, now I can't unsee that, didn't notice it before :p. I use www.manim.community/ for the animations. I'll have a look if it does something weird with the kerning for non build-in fonts.
Thanks for sharing ❤️
Thank you for sharing. This helps a lot.
Is there a particular reason why the pre-commit file is inside the tests folder? and not in the project root. Also, I believe the pyproject.toml file is in the tests folder just to run this specific example? Could you also give an example for gitlab?
Both files are in the root. Perhaps they appear to be in the tests folder because of the right pointing chevron, but they are siblings. See the repo: github.com/timvancann/yt-python-ci. Pre-commit hooks are fully independent of CI provider, so this setup will work fine for gitlab as well.
Can u share your nvim config, or make a video about it ? 🙏
In this video I'm using IntelliJ, but in others I'm using neovim. I'll have a think in how to showcase how I've setup my dev environment..
what do you think about loguru?
I do not have enough experience with loguru to give an education opinion. I think it works really well to hide a lot of boilerplate from the default module and gives a TON of options. However, I've never had the need for such a setup, even in enterprise code bases. Colors and such a great if you keep reading the output in a console, but in a more streamlined setup logs are usually gathered/pushed to an external service such a sentry, datadog, Azure Log Analytics, AWS Cloudwatch, GCP Cloud Logging or equivalent services. With a good alerting setup you only need to query and search the logs when something breaks.
@@Timnology-r4s Yes. The thing that is important to me is to avoid writing useless code and reading the docker console output in the early stages of deploy.
Your videos are amazing.
Great video! Would you consider making a video about your PyCharm settings? Your setup looks minimalist, similar to my VSCode, and I’m interested in migrating from VSCode to PyCharm. I’ve customized a lot of settings in VSCode, but I’d like to learn more about PyCharm and its benefits. I've tried adjusting some settings and the UI to resemble yours, but I couldn’t quite get it right. I’d also love to know about integrations with tools like Ruff and Pyright in PyCharm and how they work together.
Thanks for the suggestions. I'll have a think on how to structure such a video! To quickly get what was shown in the video you can install the catppuccin color scheme. The cleanliness mostly comes from enabling view -> appearance -> Presentation Mode. Distraction Free mode also works really well to hide a lot of UI elements.
@@Timnology-r4s Thanks i will check!
You are really motivating me to introduce a CI / CD pipeline for my python startup development! Every of your videos is like a friendly reminder, that I should be doing that.
I consider that a win!
Thank you. One suggesstion; When you share the screen, there should be some space at the bottom of terminal text input place so that when we pause the video, youtube's bar will not block the input and we will still be able to see the input.
Good suggestion! I've incorporated that into my new video!
Its lowkey hard to tell that you have 600 subs. I got to 4:00 before I looked down by accident and saw it. Keep it up!
Amazing video! This channel is criminally underrated. It would be cool to see how you would migrate an existing project managed via poetry over to using uv in a future video!
What IDE are you using?
I wouldn't call it an IDE though it comes close to one: in this video I use neovim, with the astronvim.com/ distribution. Typically I use JetBrains IntelliJ for my day to day job.
Cough npm cough… it might be good the only thing it must be adopted as a language standard first
¡Excelente! aunque no entendí todo ¿que puedo hacer para aprender y llegar a ese nivel?
just working on my own package, any reason you did not use "uv build"?
I see I made a boo Boo there. I wrote the repo before uv added a build backend, but recorded the video after they did. So the cli command uses `uv build`, but the CI uses `uv run build`. It should be `uv build` everywhere. Good catch!
Is it fast on cold CI start? Does it generate cross platform lockfile?
Yes it is fast. If not fast enough you can enable caching: github.com/astral-sh/setup-uv?tab=readme-ov-file#enable-caching Yes, the lock file is cross platform compatible.
High quality videos, congratulations!
Tip: vertical flip your head video to point to the screen instead off screen thanks for the video!
Oh snap, that's a good tip. I've never even thought about that!
It does not look like any kind of breakthrough. Just another package manager on top of an existing one with even more new commands to learn.
works great, but my lsp is complaning when i install other packages, as though they weren't installed
99% chance your lsp is using the wrong interpreter. If you use neovim (or zed, or helix), there are plugins that allow you to easily switch venv, but what I found works great is: uv run nvim . That automatically launches vim with the correct venv. In vscode no clue, you probably have to setup a python interpreter by pointing to the .venv/bin/python script. The same holds true for Jetbrains products.
@@Timnology-r4s hero! haha amazing and yeah that is it. i will slowly transition to UV, it really looks amazing.
New SUB here Just flawless ❤
Wonderful video. Just one question. In order to format and apply the fixes before commits, do you run each ruff, pytest, pyright ... commands manually or do you use some other tools like Tox?
Good question! Perhaps I should do a video about that as well. I typically setup a solid pre-commit hook that does all that, as well as making sure my editor does formatting on auto-save.
@@Timnology-r4s That would be a great follow up video for this one. I look forward for that. Thanks again for the great videos.
A great video for using uv in CI. Do you use uv in pre commit hooks or in IDE? I am trying to automate python code formatting, so IDE and/or pre-commit hooks can take care of it, and CI won't complain about formatting error.
Good question. I use both. For neovim none-ls with ruff, and in IntelliJ with the ruff plugin. This takes care of auto formatting on save. Pre-commit books are there to verify and pick up anything that the IDE missed (as well as doing a bunch of other things, like running tests)
@@Timnology-r4s thank you!
Poetry does the same thing
Some of it, yes. Though poetry isn't fully PEP compliant and is significantly slower on large projects.
What terminal are you using there?
www.warp.dev/ Fantastic terminal
A thing that I really like at using poetry as my project dependency manager is that it's create the virtual environment folder outside the project, that's really a cool function So, how can I do the same thing with UV? I noticed that is has been created a .venv folder at the root project...
Personally, I really like having the .venv folder right where the code lives. However, uv does give you the option to specify a custom folder: docs.astral.sh/uv/pip/environments/#creating-a-virtual-environment
Sir, 2 Q that I want to ask: 1. How can train/run Yolo with GPU (that Pytorch only install with pip?) 2. How to build uv python app to exe?
1. I never work with pytorch, but this github issue seems to have a solution running on GPU: github.com/astral-sh/uv/issues/7202#issuecomment-2447539317. 2. To get a python exe you can use pyinstaller.org/en/stable/. A simple `uv add --dev pyinstaller ` and `uv run pyinstaller` would do the trick :)
Thank you for your video. I am newbie and learning. This was really helpful. Also, if you don’t mind a trivial ask , I liked your font and color scheme- could you share the names
Glad you found it useful. All questions are welcome! I use the open source Jetbrains Mono Nerd font (www.nerdfonts.com/font-downloads), and Catppuccin Mocha color scheme (catppuccin.com/)
Well this looks great but do i need to manually update and manually manage dependencies for every uv version?
Not precisely, like with requirements.txt, or Poetry, you need to manage your dependencies per project. The version of uv you are running doesn't matter. UV is there to resolve the complicated dependency tree that is pip.
Good content!
This was a great video. I understand now, why you should maybe use uv in python projects
I'm following this exactly and locally --locked is fine but when I trigger the action it fails. Any ideas? All of my code is commited and pushed
I change the version of astral-sh/setup-uv@v3 to latest and it fixed the issue. Great content by the way.
Glad you found the fix!
lol. may be great tool but i followed your directions and only get error messages. bummer glad it worked for other people
What kind of error messages did you get?
partly why your dependencies installed so quick is because they are cached on your machine.
That is correct, though even after removing the cache the installation is single digit seconds. The power of UV really shines in its completeness as a tool, PEP compliancy and lightning fast dependency resolution.
tui thấy giống npm install (package.js) trong javaScripts.
Hi Tim, interesting video. What is the plugin you are using for the popup terminal?
It's the build in terminal In astronvim: toggleterm (github.com/akinsho/toggleterm.nvim)
i was expecting to see a 'K' by the subscribers count
Most of my Python code only uses the standard library (theres a heck of a lot you can do with those batteries) and a lot of modules I prefer to implement my own classes/functions. Might try with my Flask apps though or maybe if I made some of my stuff libraries on PIP.
fantastic video, can you make a video of Granian and Rust based frameworks?
Thank you! I'm not planning on doing a lot of lower level videos, if anything it's going to be a video of FastAPI which used Granian under the hood as ASGI framework.