Setup a Python project with PDM

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

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

  • @AndreiDamian
    @AndreiDamian 9 месяцев назад +4

    Thanks for the video. Why do you recommend creating the src directory?

    • @orcharddweller
      @orcharddweller  9 месяцев назад +5

      I’m glad you enjoyed it!
      In Python you can import modules from the directory you are in, so without src you will not import from the installed version of your project, but rather from the files itself. In most cases that is fine, but it can lead to tiny confusing bugs sometimes.
      Here’s some more info:
      packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/

  • @Hellbending
    @Hellbending 7 месяцев назад +1

    Been using PDM for quite some time as I found poetries docs initially somewhat difficult to read and understand and I was new to python. (or even why you might use it, and then I started using Linux more frequently and understood lol)
    Perhaps I missed a convention with python file, naming conventions, but can you go into more detail or link me an article around the section about using a __main__.py as a file?
    I’m already in the habit of doing an ‘if name == __main__: block in main.py, but I’m not entirely sure what you’re doing here with the __main__.py file and all of that

    • @orcharddweller
      @orcharddweller  7 месяцев назад

      __main__.py is the file you want to use when you need an entrypoint to your program. It's so that you can run it with python -m module_name instead of python -m module_name.main
      here's the docs:
      docs.python.org/3/library/__main__.html

    • @Hellbending
      @Hellbending 7 месяцев назад

      @@orcharddweller having a quick skim through the docs. It seems like this is more specific to packaging things onto pypy or for the building of pulling packages down, that along the right lines?
      I’ve always just done python(the interpreter) and then main.py and then at the bottom of main.py I’ll have an “if name main” block and then just call main with any runtime specific things for the JIT.
      TIL - it’s not just a convention haha cheers bro

    • @orcharddweller
      @orcharddweller  7 месяцев назад +2

      There's a million ways to run your stuff in python (which imho is a bad thing). Its fine to just run a script file, but then you have to make sure that your dependencies are properly installed, and you might end up with some very subtle bugs with your imports unless you're really careful.
      Running scripts as modules means you have to adhere to python packaging rules. And that's a good thing, because you can expect all the things you build to just work, and you have some rules to follow that will most likely work with all the toolings that you potentially use.

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

    So i always get "No apps associated with package"

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

      When trying to install your package with pipx right?
      Did you remember to add the [project.scripts] like in 11:53? (for poetry it's [tool.poetry.scripts] instead)
      it should look like that:
      [project.scripts]
      your-new-command-name = "your.module.path:your_main_function_name"

  • @JacobAsmuth-jw8uc
    @JacobAsmuth-jw8uc 8 месяцев назад

    Hello. My module is not found when I run pdm run -m mymodule. Am I missing something in the pyproject.toml?

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

      Did you run pdm install? You need to run it at least once for the editable install to work.

    • @JacobAsmuth-jw8uc
      @JacobAsmuth-jw8uc 8 месяцев назад

      @@orcharddwellerWorked, thank you! I was just running pdm build

    • @TotalImmort7l
      @TotalImmort7l 7 месяцев назад

      Have you tried using pdm run python -m mymodule? Let me know if that helps

  • @yash1152
    @yash1152 4 месяца назад +1

    1:32 aah yes, i definitely think that "non-python external libraries" should have been in their own category.
    the absence of this point makes this video kinda pointless for me...

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

      Try rye. Been playing with it recently 😁