258 points · by gjvc · 2y ago · 87 comments
The python3-config works generally well but is only available at the OS level. But you don't want to mess with that (e.g., to access pip-installed packages). Beyond that, everything is a mess! python3 -m venv doesn't even bother creating such a script. anaconda/miniconda? Don't even try!.
So every package pollutes their build scripts with many hardcoded `python3 -c "import sys: print..."` calls.
I've opened a CPython/PR that may help a bit by adding `python3 -m sysconfig --json` flag [0]
See https://pypi.org/project/polars/1.9.0/#files cp38-abi3 wheels means they are compatible with cpython 3.8 or later.
While pypy and graal have API support they don't have abi / abi3 support, so they still have to be built on their own (and per version I think).
See about using ccache -- https://ccache.dev/
How many new extensions are written in C these days? I was under the impression it's mostly things like Boost Python, pybind or PyO3.
I would guess also that HPy would replace the includes of `Python.h` that pybind11 et al make in order to bind to CPython, and so existing extensions should be easier to port?
Less so for general programming.
for C++ 17+, nanobind > pybind11 (both created by the same developer)
">" meaning generally better, as described at https://nanobind.readthedocs.io/en/latest/why.html
First of all, cool to see some activity on this front!
I’ve written a fair share of pure CPython bindings and regularly post about implementing them with minimal overhead (<https://ashvardanian.com/posts/discount-on-keyword-arguments...>) and would love to share a few recommendations, questions, and concerns :)
Just a suggestion to help you grow—I'd restructure the landing page (<https://hpyproject.org/>) and the README of the repo (<https://github.com/hpyproject/hpy>). It could benefit from some examples to clarify the "Nicer API" bullet point. Maybe these could be taken from the API documentation page (<https://docs.hpyproject.org/en/latest/api.html>). The page could also be more convincing with some supporting stats in favor of PyPy, GraalPython, and other Python runtimes. A reader like me might not be sure if they have enough usage and are stable enough.
Avoiding singletons and having encapsulated context objects like `HPyContext` is definitely a great thing to have, especially in the multi-threaded Python future or in complex environments with multiple sub-interpreters. But this doesn't really solve the problem if, under the hood, the `HPyContext` still redirects to CPython's singleton.
I've also looked at the linked benchmarks (<https://pypy.org/posts/2019/12/hpy-kick-off-sprint-report-18...>). They are dated from 2019, five years ago, and already mention CPython's `METH_FASTCALL` fast calling convention, but it seems like they are not compared to it. In either case, parsing arguments from one "ll" string specifier is hardly a detailed benchmark if the underlying magic isn't explained. I occasionally do one-off benchmarks as well, but it's better to describe the principle—why the thing is supposed to be faster. For example, if you're concerned about performance, you'd just parse the arguments directly from the tuple without string formatters—like this:
<https://github.com/ashvardanian/SimSIMD/blob/80cc4bcaddbdee9a0c0e991e13376c234aff3b3f/python/lib.c#L929-L1066>
It’s more error-prone, but it would be cool to see if a high-level solution can achieve under a 10% latency penalty.Hope this is useful :)
I.e. you can do this for Python from MSYS2, for example, but not for the one your users will likely have.
One of the advantages Python has, even when it's bad, is that it's often "good enough". 95% of the software which gets written is never really going to need to be extremely efficient. I would argue that in 2024 Go is actually the perfect combination of the good stuff from both Python and C. But those things aren't necessarily easy to get into if you're not familiar with something like memory management, (maybe strict typing?), explicit error handling and the differences between an interpreted and compiled language.
Anyway I don't think Python is anymore annoying than any other language. The freedom it gives you needs to be reigned in and if you don't then you'll end up with a mess. A mess which is probably perfectly fine.
Can you elaborate? What's done wrong with Python and right with other "moderately used language" ?
For start, C/C++ doesn't even have an official ecosystem. For Java or Golang, it looks better only because the "ecosystem" does not always include native extensions like cgo or JNI. Once you add them the complexity were no better than Python's
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('google', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('google', [os.path.dirname(p)])));m = m or sys.modules.setdefault('google', types.ModuleType('google'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)I agree, but note there’s another way to frame it: “python can be used by people who aren’t professional software developers”.
While Python is fractured, it is nowhere near problems of C ecosystems.
It's almost a relief AIX, Solaris, and HP/UX are either very niche, or going the way of the Dodo.
The people who love it understand that its extreme flexibility makes it applicable everywhere, while academic purity mostly doesn't work in the real work. They also prioritize getting things done over petty squabbling, but they know how to leverage available tooling where reliability is crucial.
(See, I can generalize too)
if something doesn't end up working well, you pivot
Why do you think that? There's no need for a Python 2->3 like transition here, it could have been done while supporting the old C API for a while.
If they succeed and keep the CPython "leaders" who ruined the development experience and social structure of CPython out of PyPy, PyPy might get interesting. If they don't keep them out, those "leaders" will merrily sink yet another project.
HPy on CPython uses the existing C-API under the hood, so there is zero need to build up some keep someone out...