home.social

#setuptools — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #setuptools, aggregated by home.social.

  1. Accessing github from work is annoying.

    I hope someone else in the world files a bug soon on flake8 not being compatible with a fresh python 3.12+ virtualenv, now that setuptools 82 is out and flake8 is still using the deprecated (now removed) pkg_resources.

    #flake8 #python #setuptools

  2. I need some help packaging a python module that I built. It references a few different python files, and .csv within the folder structure, and searching leads me to examples/tutorials that are either too simple, or way too complex. I can't find anything bridging the gap.

    Any blogs, courses, tutorial, or even as a last resort youtube videos, that may help me out? #python #packaging #flit #setuptools #hatchling

    The project that I'm trying to package is here - git.jmkengineering.com/JMK_Eng

  3. Last week I was a little annoyed about missing Microsoft C++ Build Tools #MSVC on a system without admin rights. I needed a compiler for building the #python C++ extension I developed a while ago. Annoyed not because I could not ask someone to install it for me, but annoyed because of the lack of compiler choices in this particular case. I have to use the MSVC instead of let's say #g++ which I could easily install via the #MinGW-w64 #conda package myself.

    I found out that I can tell #setuptools (the backend build system) via #pip config settings to use a different compiler during build:

  4. A that builds a that & install 0.1.0 & 1.1.0 from python source code. For . This is a beta work in progress, done using chatGPT iteratively, and is my first attempt at packaging something for nixos. Time will tell if this holds up. Uses python &
    ver 0.8.0
    ver 1.0.0 codeberg.org/adingbatponder/re

    This is experimental and beta - see readme file for issues

  5. Ciekawostki o Pythonowym "limited API" i "stable ABI".

    1. #CPython ma "limited API". Jak się tego używa, to kompilowane rozszerzenia są zgodne ze wskazaną wersją i wersjami nowszymi. Takie rozszerzenia dostają sufiks `.abi3.so` (albo podobny) zamiast np. `.cpython-313-x86_64-linux-gnu.so`.

    2. Wsparcie podzielone jest między CPythona i systemy budowania #PEP517. Np. w #setuptools podaje się `py_limited_api=`, i wówczas przy budowaniu dodawane są odpowiednie flagi kompilatora i podmieniany jest sufiks rozszerzeń. #Meson ma coś podobnego.

    3. Ale wersja "freethreading" aktualnie nie obsługuje "stable ABI", więc przy budowaniu z "limited API" dostaje się błąd kompilacji. Podobnie, setuptools rzuca błąd jeżeli z interpreterem freethreading podamy `py_limited_api`, a Meson po prostu pozwala się wysypać kompilacji. Tak więc autorzy paczek muszą sami sprawdzać, czy użyto kompilatora "freethreading", i wyłączyć wówczas "limited API".

    4. Bliżej nieokreślona przyszła wersja CPythona naprawi to wsparcie. Nie przyglądałem się tematowi dokładnie, ale podejrzewam, że będzie to tylko możliwe, jeżeli będziemy budować rozszerzenia dla tej bądź nowszej wersji. Więc ludzie pewnie będą musieli budować dwie wersje — tę dla starszych CPythonów, i dla nowszych + "freethreading". No i oczywiście będzie trzeba odpowiednio zaktualizować warunkowe załączanie "limited API".

    5. No i jest jeszcze #PyPy. PyPy nie ma "stable ABI", ale pozwala budować rozszerzenia z "limited API". Setuptools i Meson po prostu wykrywają, że interpreter nie obsługuje sufiksu `.abi3.so`, i buduje rozszerzenia z normalnym sufiksem.

    #Python

  6. Some fun facts about #Python limited API / stable ABI.

    1. #CPython supports "limited API". When you use it, you get extensions that are compatible with the specified CPython version and versions newer than that. To indicate this compatibility, such extensions use `.abi3.so` suffix (or equivalent) rather than the usual `.cpython-313-x86_64-linux-gnu.so` or alike.

    2. The actual support is split between CPython itself and #PEP517 build systems. For example, if you use #setuptools and specify `py_limited_api=` argument to the extension, setuptools will pass appropriate C compiler flags and swap extension suffix. There's a similar support in #meson, and probably other build systems.

    3. Except that CPython freethreading builds don't support stable ABI right now, so building with "limited API" triggers an explicit error from the headers. Setuptools have opted for building explicit about this: it emits an error if you try to use `py_limited_api` on a freethreading interpreter. Meson currently just gives the compile error. This implies that package authors need to actively special-case freethreading builds and enable "limited API" conditionally.

    4. A some future versions of CPython will support "limited API" in freethreading builds. I haven't been following the discussions closely, but I suspect that it will only be possible when you target that version or newer. So I guess people will need to be building two stable ABI wheels for a time — one targeting older Python versions, and one targeting newer versions plus freethreading. On top of that, all these projects will need to update their "no 'limited API' on freethreading" conditions.

    5. And then there's #PyPy. PyPy does not feature a stable ABI, but it allows you to build extensions using "limited API". So setuptools and meson just detect that there is no `.abi3.so` on PyPy, and use regular suffix for the extensions built with "limited API".

  7. co jest gorsze niż #setuptools? Paczka, która przechodzi na #Hatchling, ale wewnętrznie woła w paskudny sposób setuptools, żeby zbudować rozszerzenie w C — i w ten sposób ignoruje budowanie poza katalogiem źródłowym.

    #Gentoo #PEP517

  8. What's worse than #setuptools? A package switching over to #Hatchling, then internally calling setuptools in an awful way to build a C extension, completely bypassing out-of-tree builds.

    #Gentoo #PEP517

  9. W sumie mogę dać parę rekomendacji systemów budowania #PEP517.

    Dla paczek w samym Pythonie:

    1. #flit_core (pypi.org/project/flit-core/) — leciutki, prosty, i nie ma zależności (za wyjątkiem włączonego tomli dla starszych wersji Pythona).

    2. #hatchling (pypi.org/project/hatchling/) — popularny, duża funkcjonalność, ale ma sporo włączonych zależności, a testy są zależne od reszty projektu hatch (przez co w #Gentoo się mocno z tym męczymy).

    Dla paczek z rozszerzeniami w C: #meson-python (pypi.org/project/meson-python/) — połączenie szerokiej funkcjonalności i poprawności mesona z dobrą integracją z Pythonem.

    Dla paczek z rozserzeniami w Ruście: #maturin (pypi.org/project/maturin/) — po prostu dobry system budowania dla tego typu paczek.

    Stanowczo odradzam:

    A. #setuptools — mnóstwo włączonych do projektu zależności, które wynajdują koło na nowo (które można zastąpić zewnętrznymi, które z kolei mają cykliczną zależność od setuptools), ciągłe wycofywanie starej funkcjonalności (której wciąż używa mnóstwo paczek), wiele nierozwiązanych problemów (np. równoległe budowanie plików C jest częściowo popsute), sporo długu technicznego, a jeżeli to nie wystarcza, to do tego strasznie powolny.

    B. #poetry-core — trudny do poprawnego użycia system budowania, w którym bardzo łatwo popełnić błąd (a zgłaszałem już wiele pomyłek, które ludzie robili migrując swoje projekty).

    C. Praktycznie każdy inny system budowania — pisanie nowych backendów stało się banalne, więc każdy musi mieć swój. Do tego często mają mnóstwo zależności, które wynajdują koło na nowo (jak już ktoś chce wynaleźć własny system budowania, to może równie dobrze pójść na całość i wynaleźć wszystko), brak doświadczenia i tym samym powtarzają te same błędy przeszłości. A jeżeli tego nie wystarczy, to dodawanie pod nie paczek do dystrybucji to tylko kupa roboty bez żadnej realnej korzyści.

    #Python

  10. I suppose I could use my experience to give some #PEP517 build system recommendations.

    For pure #Python packages:

    1. #flit_core (pypi.org/project/flit-core/) — it's lightweight and simple, and has no dependencies (in modern Python versions, for older Pythons it vendors tomli).

    2. #hatchling (pypi.org/project/hatchling/) — it's popular and quite powerful, but has many vendored dependencies and no stand-alone test suite (which makes it painful to maintain in #Gentoo).

    For Python packages with C extensions: #meson-python (pypi.org/project/meson-python/) — which combines the power and correctness of meson build system with good very Python integration.

    For Python packages with Rust extensions: #maturin (pypi.org/project/maturin/) — which is simply a good builder for precisely that kind of packages.

    Now, I strongly discourage:

    A. #setuptools — lots of vendored NIH dependencies (that can alternatively be unvendored for cyclic deps), lots of deprecations over time (we're still seeing tons of deprecation warnings all over the place), many unsolved bugs (e.g. parallel C extension builds are broken in a few ways), a lot of technical debt, and if all that wasn't enough, it's slow.

    B. #poetry-core — a very tricky build system with lots of pitfalls (I've reported a lot of mistakes done when migrating to it).

    C. Practically any other build system — writing new backends is trivial, so everyone and their grandmother must have one. And then, they often carry a lot of NIH dependencies (if you're reinventing a build system, you may reinvent everything else), lack experience and reintroduce the same bugs. And if that wasn't enough, packaging them in distributions is a lot of work for no real benefit to anyone.

  11. Jakiś czas temu dwa systemy budowania #PEP517 dorobiły się funkcji weryfikacji klasyfikatorów #PyPI ("trove classifiers"). Na pierwszy rzut oka, ma to sens: wszak warto poinformować autorów paczek od razu, jeżeli gdzieś popełniono błąd i paczka zostanie odrzucona. Problem stanowi jednak fakt, że ta weryfikacja dotyczy również budowania paczek lokalnie — a więc użytkowników #Gentoo.

    Funkcję zbudowano w oparciu o paczkę "trove-classifiers". Ilekroć nowy klasyfikator dodawany jest do PyPI, wydawana jest nowa wersja tej paczki. Jeżeli używamy narzędzi takich jak `build` czy `pip`, każdorazowo z sieci instalowana jest najnowsza wersja tej paczki. Na Gentoo natomiast, o ile nie wymusimy tego zależnościami, użytkownik może mieć przestarzałą. Jeżeli wówczas spróbuje zainstalować paczkę Pythona, która używa nowszych klasyfikatorów, otrzyma mylący błąd o błędnym klasyfikatorze. Mylący, bowiem: 1) wbrew komunikatowi, klasyfikator jest poprawny; 2) nawet gdyby nie był, to problem nas w ogóle nie dotyczy.

    Dlatego też wystąpiliśmy z prośbą o możliwości wyłączenia tej funkcji. Choć zajęło to trochę czasu, opiekun paczki #Hatchling wykazał zrozumienie dla naszego problemu i zaakceptował moją łatkę. Z kolei opiekun #setuptools… no cóż, podjął się długiej i bezowocnej debaty, która poskutkowała zignorowaniem trywialnego rozwiązania głównego problemu ("niepotrzebna komplikacja"). Zamiast tego, zaproponowano nam rozwiązanie dosyć wątpliwe — całkowite wyłączenie weryfikacji poprawności pliku `pyproject.toml`. Rozwiązanie nieakceptowalne z dwóch powodów: 1) dlatego, że setuptools polega na tej weryfikacji (a więc przy błędach w pliku moglibyśmy dostać zepsutą instalację zamiast błędu); 2) dlatego, że przy budowaniu każdej paczki rzuca paskudnym ostrzeżeniem. W praktyce więc znęcalibyśmy się nad użytkownikami Gentoo, zarzucając ich fałszywymi ostrzeżeniami, i niektórzy z nich prawdopodobnie niepotrzebnie zgłaszaliby problem autorom właściwej paczki.

    Nie używajcie setuptools.

    github.com/pypa/hatch/issues/1
    github.com/pypa/setuptools/iss

    #Python

  12. Some time ago two #PEP517 build systems introduced #PyPI trove classifier verification. At a first glance, it makes sense. After all, if you made a mistake somewhere, you'd rather know early than when you try to upload the package. The problem is, that the verification fires for people building packages locally too — including #Gentoo users.

    Now, this function was based on the #Python "trove-classifiers" package. Whenever a new classifier is introduced, a new release of the package is made. When you're building a package using tools such as `build` or `pip` (isolated build), the newest version of this package is being installed from the Internet. On the other, a Gentoo user may have an old version, unless we enforce an upgrade via package dependencies. Then building packages that use newer classifiers will fail, and with a confusing message too. Confusing because: 1) contrary to the message, the classifier is valid; and 2) even if it weren't, it doesn't affect us in any way.

    And so we asked for an ability to disable this. While it took some time, the #Hatchling showed understanding and eventually merged my patch. On the other hand, the #setuptools maintainer… well, started a long and tedious debate that resulted in ignoring the trivial solution to the actual problem (as "unnecessary complexity"). Instead, we were given another option: we could entirely disable `pyproject.toml` validation. It's not really acceptable, for two reasons: 1) because setuptools actually rely on this validation (so removing it could result in broken package installs instead of an error, if the file is not valid), and 2) because it produces an awful warning on every package build. So we'd end up bullying Gentoo users with false warnings, and some of them would probably end up filing invalid bugs to various upstreams.

    The bottom line is: don't use setuptools.

    github.com/pypa/hatch/issues/1
    github.com/pypa/setuptools/iss

  13. #Wtyczki to świetny sposób na to, by poszerzyć funkcjonalność programów. W gruncie rzeczy, wtyczki są tak przydatne, że niektóre projekty decydują się minimalizować podstawową funkcjonalność i oczekiwać, że wszystko, czego nam potrzeba, dostarczą wtyczki.

    Wtyczki są super. A potem nagle okazuje się, że spotykamy się z jednym lub więcej z poniższych problemów:

    • API głównego programu się zmienia i niektóre wtyczki przestają działać.
    • Niektóre wtyczki zostają porzucone (i patrz: poprzedni punkt).
    • Niektóre porzucone wtyczki doczekują się forków, i teraz różne projekty wymagają różnych forków tej samej wtyczki, które dodatkowo są ze sobą niezgodne.
    • Niektórzy ludzie wolą napisać własną wtyczkę od zera niż użyć istniejącej (z jakiegokolwiek powodu).
    • Wszystkie wtyczki są ładowane automatycznie, więc przypadkowe wtyczki zainstalowane w twoim systemie psują przypadkowe paczki.

    #Gentoo #Python #PyTest #setuptools

  14. I launched a new open-source project yesterday! 🎉

    For the past few months @stuartl and I have been working on a little tool to automatically convert #Python #setuptools scripts (setup.py or setup.cfg) to #pyproject.toml files, and our first release just landed on PyPI: pypi.org/project/setuptools-py

    It's still a little rough around the edges, but it handles the basics. If you have a Python project using setuptools, we'd love it if you give it a try and share any feedback! (Even if you don't actually use the output, that's cool)