Packaging Your Python Code With pyproject.toml | Complete Code Conversation

Поделиться
HTML-код
  • Опубликовано: 6 янв 2025

Комментарии • 64

  • @dawidp749
    @dawidp749 Год назад +15

    I watch like 15 min of this video on the moment and I can say it is one of the best tutorials that i saw in a while. The way how you slowly divide problem and show all the casess, and explain why and how it is happening is brillant

  • @alexandarjelenic2880
    @alexandarjelenic2880 2 года назад +54

    timestamps:
    1:40 running the first cli using python .cli.py
    4:20 create directory "snakesay" to contain project. which will be the name of the package
    move all files to that folder
    5:10 python snakesay does not work. need __main__. but still runs using .\snakesay\cli.py
    6:48 rename clip.py to __main__
    7:30 python snakesay works now, but...
    8:15 if you call a folder it needs to have __main__
    8:40 python -m to call module, does not work as python looks in its path
    9:45 python uses two paths, the active path, and another path of all libraries.
    13:45 absolute imports " from snakesay import snake" is needed when using -m
    ans points to snake module explicity
    15:05 now "python snakesay" does not work again due to module not found
    15:30 python with -m searches for different paths
    to get both "python" and "python -m" both working
    16:00 you should not sys.path.append(yourpath)
    this will work, but does not scale well. this is commonly used but is a bad practice
    scaling problem is that you cant share it easily and does not help you merge programs
    17:25 the plan is to install the package, you will pip install, but no need to upload it anywhere
    you can pip install your directory.
    18:00 you will be able to use consistent inports and it will work in any CWD
    19:00 historical solutions
    20:24 intro to setuptools. it is not part of the standard library.
    22:00 most importantant PEPs on how to setup packagages historically. messy history
    22:50 create a local package
    23:00 create pyproject.toml one directory up all consifg can be placed here, this replaces setup.py, or setup.cfg
    24:20 setuptools home page shows config setup tools using .toml,build system, project, and optional dependenace,
    like a dictionary
    25:50 PEP 621 storing metadata in pyproject.toml
    26:40 toml is not python specific, it is general
    27:05 copy the build-system section from the setuptools.pypa.io/en/latest/userguide/pyproject_config.html and paste into pyproject.toml
    30:44 create "snakesay-project" and move contents into it
    31:40 and move the .toml into the project folder and now install this into a virtual environment
    32:00 in the project folder python -m venv venv
    32:20 for windows activate the venv by ".\venv\Scripts\activate
    32:50 in the toml create the [project] name = "snakesay" version ="1.0.0"
    33:30 inside the snake-project folder python -m pip install -e . to allow changes updates to the source code
    36:20 "Successfull installed snakesay-1.0.0" now can can call it from anywhere using with or without the -m flag
    37:50 now you can "import snakesay" in any python script when the venv is activated
    38:20 now there is no reason to think about the path, or relative imports,even if deep inside you package, you can always "from snakesave import snake"
    38:48 the last step, to create an entry point, so that it is recognized by the terminal.
    39:20 including project scripts to create an entry point, updating the .toml
    41:50 need to pip instal the pyproject as changes where made to it.
    42:30 now you can go anywhere on the commange line and call your program, but now it calls the program twice
    43:40 to fix you need if __name__== "__main__" in the __main__.py
    4920 Flint, Poetry support .toml as well now
    46:35 whats an .egg? egg is a predecceor for wheels, it contains metadata and source for editable installs.
    48:10 from inportlib import metdata to see metadata on a project from an egg. gitignore egg files
    49:35 summary

  • @farukhannan8230
    @farukhannan8230 10 месяцев назад +2

    Just brilliant. The whole back and forth conversations, step by step build up. its a gem of tutorial for any python developer . i learned alot just by this video. Thank you for this great effort!!!!!!!

  • @hexmoo
    @hexmoo 27 дней назад +1

    I have been struggling to understand how import logic works between folders in a structured format, as I have been trying to import a helper class, from a script in folder A's subfolder to a script in folder B's subfolder, but couldn't find a way to make it work. Not only has this video given me the exact explanation as to how things work and why certain workarounds aren't as great as they might first seem, but also gave the proper solution to my problem. THANK YOU! 🙂

  • @lord_consistent
    @lord_consistent 9 месяцев назад +1

    Conversation Style of explaining the Topic is an awesome Idea at the first place. Thank You both of You

  • @zvyenxs8560
    @zvyenxs8560 5 месяцев назад +2

    I have been using a lot of it at work, but this video made me properly understand what and why i have been doing those things. really great stuff !

  • @themichaelw
    @themichaelw Год назад +2

    I've been a huge fan of the Real Python blog for ages but this is the first video I've seen. Phenomenal video Ian and Geir! So clear, so thorough. I too had been contemplating doing the "simple" path hack, but I figured it's worth investing time in learning the proper way to do things, and this lesson did not disappoint. It has already saved me hours of headache. Cheers.

  • @jorgenlarsen775
    @jorgenlarsen775 10 месяцев назад

    This is really a good review of pyproject.toml. I really appreciate this calm, slow introduction to the subject. Too many tutorials rush through the topic quickly, but here the understanding is built up slowly.

  • @julianhamann2446
    @julianhamann2446 Год назад +6

    What a brilliant tutorial. Makes what could be a complex topic simple and easy to understand.

  • @Mraeth8n
    @Mraeth8n 11 месяцев назад

    God bless you two! I have been struggling with this for a very long time. I am so happy that I found this video and so thankful that you two created this video and explained everything in such an awesome and understandable way.

  • @ArjunRamesh-f2c
    @ArjunRamesh-f2c 10 месяцев назад

    This is just the right balance of technology description and teaching! Amazing work.

  • @ZacheryBlakeDavis
    @ZacheryBlakeDavis Год назад +2

    Thank you for explaining the problem while also showing the solution.

  • @kevon217
    @kevon217 Год назад +13

    this was a great tutorial. very great step-by-step explanations and intuitions.

  • @TongLi-g2f
    @TongLi-g2f 2 месяца назад

    Masterpiece of a tutorial on the topic; better than everything else I've come across. Thanks :)

  • @JorgeRamirez-vz3gl
    @JorgeRamirez-vz3gl 2 года назад +4

    Lol I've been having issues with this for a while and you guys explained it with just enough detail. Thank you

  • @hitwhy
    @hitwhy 2 года назад +13

    Thank you for the excellent tutorial. While AFAIK a package should have a __init__.py file in it, snakesay doesn't have one. It still works. So is the init file necessary? Thank you.

  • @JMurmu-t5k
    @JMurmu-t5k Год назад

    such a nice conversation and will not say a tutorial video but a tutorial should be like this.

  • @rodrigocaballerohurtado5367
    @rodrigocaballerohurtado5367 8 месяцев назад

    I loved this one. All the basic questions I don't do were asked and answered with quality

  • @andreikniazev9407
    @andreikniazev9407 Год назад +2

    I was struggling with python to do packaging right now, but you helped me! Thank you! Amazing vide 🤘

  • @justchary
    @justchary 10 месяцев назад

    Finally a good explanation about packages! thank you!

  • @Windeycastle
    @Windeycastle Год назад

    Every question I had was asked and answered in 1 video. Thanks a lot!

  • @SergioSousa
    @SergioSousa 5 месяцев назад

    This is a very informative and well done video. Thank you very much for making this content available.

  • @SouvikPalMAIE
    @SouvikPalMAIE 3 месяца назад

    Brilliant tutorial. Is there any video explaining the project dependency part, I saw in docs that we can do a lot including mentioning OS for our dependencies

  • @bharathwajan6079
    @bharathwajan6079 10 месяцев назад

    Very nice videos answered a lot of questions which is in my mind for a long time .

  • @stanleykubrick-pv9wu
    @stanleykubrick-pv9wu Год назад

    This video just made my life a lot better! Great thorough explanations, thank you!

  • @johnmoff9324
    @johnmoff9324 Месяц назад

    15:18 not clear why this didn't work, earlier he said if you dont use -m the snakesay dir is added into path, so why `from snakesay import` doesnt work when the dir snakesay is in path?

  • @crdcj
    @crdcj Год назад

    You guys are awesome! I finally got it. What an amazing teaching!

  •  11 месяцев назад

    Thank you so much for this video. This was awesome!

  • @Ai-sauce
    @Ai-sauce Год назад

    great tutorial and was fun through out the video, thanks!

  • @noiseless2
    @noiseless2 9 месяцев назад

    Fantastic video, thank you !

  • @Investmentpunk1
    @Investmentpunk1 6 месяцев назад

    Who are the 2 guys presenting the topic in the video? It's an unbelievable good presentation and explanation of the topic!
    Did you guys do any other video tutorials or content? Where can i find it?

  • @omarfessi2761
    @omarfessi2761 Месяц назад

    Great content! Thank you both.
    Where is your __init__.py ? It really confused me

  • @tascsolutions6483
    @tascsolutions6483 9 месяцев назад

    Excellent tutorial! I was getting tired of being frustrated with all the 'modules not found', 'no parent package found errors'.

  • @hora2100
    @hora2100 Год назад

    It works but it says command not found when i execute it with sudo and the script name.Anyfix would be deeply appreciated?

  • @al76am8
    @al76am8 27 дней назад

    What is your terminal emulator? I really like color scheme!

  • @janasandeep
    @janasandeep Год назад +1

    8:43 Why to call with `-m` option?

  • @rgv5966
    @rgv5966 Год назад

    loved it, great tutorial!

  • @Python_Bacon
    @Python_Bacon Год назад

    Thanks for the video, was helpful.

  • @js46644
    @js46644 Год назад

    This is very well done, but having some chapters defined would be nice

  • @alphabat3269
    @alphabat3269 2 года назад +3

    Fantastic tutorial! Cheers!

  • @dcyadgaroff
    @dcyadgaroff Год назад +1

    So how do I take this and put into a Docker container?

    • @lattice737
      @lattice737 Год назад

      Was also wondering about this. I'm thinking this project could be stored in a repo, then you could clone the repo and add the package to requirements. Not sure if that would work or, if it does, if that's the best way to do it

  • @markchadwick77
    @markchadwick77 2 года назад

    While viewing __main__.py in vscode, I notice that in the line 'from snakesay import snake', vscode does not recognize 'snakesay' (the text color is white). Is there something that needs to be done so vscode recognizes it, gives it the proper highlight, and doesn't have pylance show it as an error?

    • @lattice737
      @lattice737 Год назад +2

      I have traditionally used extraPaths in .vscode to help with this. Kinda hacky, though. Would love to find a more automatic solution

  • @GeraldWaters
    @GeraldWaters 2 года назад +2

    While I appreciate the forward looking nature of this conversation, it was disappointing that no mention was made of how to expect support for pyproject.toml to map with older versions of things. For example, my home setup (Xubuntu 20.04) has Python 3.8 and my workplace is still on Python 3.6. I assumed I could just look up those facts but they're proving non-obvious to find. I try to write Python code avoiding new "just for convenience" features so that my code can run on older versions - but that would be pointless if the packaging system I go to use requires newer versions. Or is this matter independent of the Python versions and instead reliant on versions of pip and setuptools being sufficiently updated? If so, I can see that the "current" version of pip requires CPython 3.7 or later (which begs more checking re Python 3.6). I can't yet find equivalent requirements for setuptools.

    • @Michallote
      @Michallote 3 месяца назад

      Wow Python3.6, you do realise it has lost support years ago?

    • @GeraldWaters
      @GeraldWaters 3 месяца назад

      @@Michallote ah, so it wasn't obvious to you that me saying "my workplace is still on Python 3.6" is talking about an environment where such things are quite outside my control? In large organisations it doesn't matter what I might realise, only what "IT" chooses to install.

  • @TheAzerue
    @TheAzerue Год назад

    Really helpful.

  • @the-ghost-in-the-machine1108
    @the-ghost-in-the-machine1108 11 месяцев назад

    Excellent.

  • @jake115577
    @jake115577 9 месяцев назад

    THANK YOU!

  • @hi_arav
    @hi_arav Год назад

    Great video!

  • @aramis61
    @aramis61 2 года назад +1

    Thanks!

  • @johnshanahan7010
    @johnshanahan7010 Год назад

    Great tutorial, but the conversation is quite slow with long pauses

  • @ahasibrifat7568
    @ahasibrifat7568 2 года назад

    Thanks

  • @chanwoopark5397
    @chanwoopark5397 Год назад

    8:20 python module

  • @afonsosalbrecht
    @afonsosalbrecht Год назад

    you should have explained how to run this script from anywhere in the system without having your virtualenv activated.

    • @lattice737
      @lattice737 Год назад +1

      That kind of global scope is discouraged for Python packages. They note this when discussing installation

  • @magno5157
    @magno5157 6 месяцев назад

    It's kinda cringe to have one person who has all the answers and the other pretends like he doesn't know and asks questions. Could you all just chat normally without having any one of you pretend like he doesn't know the topic at all?

  • @jlamoree
    @jlamoree Год назад

    Thanks!

  • @erintorgerson1485
    @erintorgerson1485 11 месяцев назад

    Thanks!