24,628 karma · joined Oct 21, 2019 (7y ago) · 5,512 submissions
https://www.bitecode.dev/
Email: contact at bitecode.dev
comment 6y ago · link · parent
I'm full of hopes for this feature, but it's going to be a slow hard work, and we'll only rip the benefit on the long run. So no use to rush it.
I feel like we rushed asyncio and type hints, and it took years to make them usable after they were introduced.
comment 6y ago · link · parent
Unless you happen to work at the legenday ones that do care about you, don't play according to their rules. Those are here for their benefit, not yours.
Remote or not.
comment 6y ago · link · parent
Also, rendering a beautiful word document is quite chalenge.
Rendered latex document looks stunningly clean and professional out of the box.
They also are plain text, which mean they can be diffed, used with git indexed easily, etc. They play well with anything, being text.
You can even read them without having to render them.
And finally, latex check the structure of your doc. If you change it, it will crash, preventing you from commiting dead references.
comment 6y ago · link · parent
I've tried writting a book using LateX, and it's been nothing but a miserable experience. I'm been coding for 15 years, and tweaking my Linux machine for longer. I know what it means to face rought edges.
But LaTeX is another level of shenanigans.
I seem to understand that researchers use latex because of the seemingless formula integration and automation of references.
Well, why not use asciidoc (https://asciidoctor.org/docs/user-manual/#mathematical-expre...) or myst (https://myst-parser.readthedocs.io/en/latest/using/syntax.ht...) then? They are an order of magnitude easier to use, they can generate websites and pdf, use markdown but allow extensions, they support references, and accept latex formulas.
Is it a case of "everybody uses it so I have to"?
comment 6y ago · link · parent
Let's examine the README example for a minute:
user: Optional[User]
if user is not None:
balance = user.get_balance()
if balance is not None:
balance_credit = balance.credit_amount()
if balance_credit is not None and balance_credit > 0:
can_buy_stuff = True
else:
can_buy_stuff = False
I don't know if it's been deliberatly twisted, but that's not what I would called idiomatic or realistic for a Python program:- one should probably never reach this part of the code if there is no user. But I'll indulge the author.
- don't put can_buy_stuff in an else close, what's the point?
- using type hints for no reason, but not other modern facilities like the walrus operator?
- do we really want users without a balance? Let's indulge this, but it seems a bad design.
- what's with all those unecessary conditional blocks?
- credit_amount should never be None. It's a Balance object, put a sane default value. But ok, indulging again.
So, you get down to:
user: Optional[User]
can_buy_stuff = False
if user and (balance := user.get_balance()):
can_buy_stuff = (balance.credit_amount() or 0) > 0
I don't think the solution the lib offers is superior: can_buy_stuff: Maybe[bool] = Maybe.from_value(user).map(
lambda real_user: real_user.get_balance(),
).map(
lambda balance: balance.credit_amount(),
).map(
lambda balance_credit: balance_credit > 0,
)
And that's if we are using the rules of the README, which are not fair.If we have a well designed API, and we use a function (more testable, and hey, are we doing FP or not ?), then:
def can_buy_stuff(user: User):
if (balance := user.get_balance()):
return balance.credit_amount() > 0
return False
Checking the user should not be part of this algo, credit_amount should be 0 if never set. We could even remove return False, I keep it because I like explicitness.You could even that as a method or raise NoBalance depending of your case.
Bottom line, if you really feel that strongly about None, don't jump on the bazooka to kill this fly, go to https://discuss.python.org and advocate for PEP 505 (None-aware operators): https://www.python.org/dev/peps/pep-0505/
It's been deferred since 2015.
That doesn't mean we should not experiment with other paradigms in Python, and I do think this lib is an interesting experiment, but I don't find it conclusive.
comment 6y ago · link · parent
Besides, if you want to develop and automatically test using multiple Python versions and a range of versions of your dependencies, none of the tools from the article will do it.
At best they are one of the ways to get dependancies before you use a tool to do it. You can do that with raw pip and venv as well.
What you need though, is something like tox, which has existed for years.
As mentioned in my comment, I personnally use nox for this, as it is, ironically, more modern to my taste.
Nox doesn't care if you use poetry, pew, virtualenv wrapper or venv manually.
I would certainly advice to learn something like nox or doit before learning poetry, for example.
Now I don't advice against learning poetry, mind you. It's a good tool, well written.
Pyenv is another matter entirely. The day one really need what pyenv gives you to the point it's worth investing in it, they can discard all my advices entirely, as they would have the skill and experience to not need my explanations.
comment 6y ago · link · parent
The rest is not popular enought to be a blocker. You will hear them scream a lot, but they will be like 0.00001% of the user base, and we can just tell them to stay on CPython with its limitations. They don't lose anything, just not gain anything either.
Those C extensions authors are directly in communication with Python core devs, when they are not core devs themselves, so if HPY is adopted, we can expect a total adoption under 5 years.
Numpy authors already said it would take 1 year to adopt it.
Give the huge number of benefits of HPY, I deeply hope it will be a success.
comment 6y ago · link · parent
That being said, a lot of extensions are pre-compiled and provided as wheel, which is the case for tensorflow (I don't know for CUDA, I can't test on a laptop without a GPU).
Let's see what this means:
$ py -m venv test
$ test\Scripts\activate
$ pip install tensorflow
$ code hello_tensor.py
# import tensorflow as tf
# def main():
# with tf.compat.v1.Session() as sess:
# a = tf.constant(3.0)
# b = tf.constant(4.0)
# c = a+b
# print(sess.run(c))
Now with shiv: $ copy hello_tensor.py test\Lib\site-packages
$ shiv -e hello_tensor.main --site-packages test\Lib\site-packages\ -o hello_tensor.pyz
$ python hello_tensor.pyz
...
2020-05-28 17:31:46.580704: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
7.0
So it works fine, but remember:- it will only run on the system this particular wheel has been designed to run on. In my case cp38-win_amd64.
- it will come bundled with tensorflow, which is a behemot, meaning your hello world pyz will around 500 Mo.
- it needs to unzip, so the first run will be REALLY slow
For something like this, I would advice a more generic deployment tool, like fabric 2 if it's remote, or a make-like tool such as doit if it's local only.
Make your deployment script, and zipapp that.
comment 6y ago · link · parent
Let's try an example with numpy:
$ py -m venv foo
$ foo\Scripts\activate
$ pip install numpy
$ code hello_numpy.py
# import numpy as np
# def main():
# print(np.arange(15).reshape(3, 5))
$ python hello_numpy.py
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]]
Now with shiv: $ copy hello_numpy.py foo\Lib\site-packages
$ shiv -e hello_numpy.main --site-packages test\Lib\site-packages\ -o hello_numpy.pyz
$ python hello_numpy.pyz
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]]
So it works fine, but remember:- it will only run on the system this particular numpy wheel has been designed to run on. In my case cp38-win_amd64.
- it will comes bundle with numpy. Numpy is quite big, which means your hello world pyz will be 14.1 Mo.
- it needs to unzip, so the first run will be slow
comment 6y ago · link · parent
Yes, it's not ideal.
But it beats shipping your entire dev env to the server.
I find it a good compromise. The extraction is done is $HOME/.shiv/{zipappname}_{zipapphash} so it's not a horrible mess. But if your project is big, you do have to clean up the old install because it can eat a significant amount of space.
For you regular cmd tool though, it's a blip.
comment 6y ago · link · parent
I think the reason is that something like shiv was missing: it streamlines the process, shows a finish product instead of just telling people "all the thing they can do", and the automatic unzipping solved plenty of problems that you had with alternative like Pex, espacially on windows or with static resources.
So now you have it. Spread the word.
comment 6y ago · link · parent
It's an official feature (https://docs.python.org/fr/3/library/zipapp.html) that lets Python execute an entire project bundled into a zip file.
If you don't want to create it by hand, use shiv: https://pypi.org/project/shiv/
It's the best of both worlds.
comment 6y ago · link · parent
So if one day RustPython gets compatible enought with CPython that you can use it as a drop in replacement, you can start creating a tool that compiles any Python VM for any target, and bring along your program with it. Making a standalone version of it would become much easier.
Right now, doing so either requires you to bring in a pre-compile version of cpython for your target (which is what briefcase does) or compile the thing yourself with gcc + headers + deps(which is what nuitka does).
It's not easy.
comment 6y ago · link · parent
Using an interpretted language always leads to this.
I know no popular interpretted language with a seamless experience to ship a standalone exe.
In fact, Python is probably the one with the best story here, since it has nuitka (https://nuitka.net/), which allows to compile Python code into a fully standalone exe.
But then you need to install a compiler, headers, etc. And no cross compilation of course. Not to mention on Linux, you have to ensure you target the lowest version of libc you can.
You are still very far from Go or Rust, and I'm hoping one day that RustPython will succeed because that would mean an amazing deployment story.
Meanwhile, you trade the ease of deployment of compiled languages for the ease of development of interpretted ones.
I think it's a fare trade for most people: you dev the program much more often that you deploy it.
That doesn't mean we shouldn't work, as a community, to improve the deployment story. It's a serious hindrance.
That's the raison d'être of the Briefcase project (https://beeware.org/project/projects/tools/briefcase/). It's still in progress, but the last prez I saw on it was quite impressive already.
comment 6y ago · link · parent
So a huge number of cases can be handled with just that. It will be "reproducible" enought for a lot of people.
comment 6y ago · link · parent
We even how have a nice tool to automate the bundling for you:
https://pypi.org/project/shiv/
Of course you still have to figure out how to get a Python installed on the final machine, that's the price to pay to be an interpreted language.
We don't have yet a story to ship a beautiful exe/dmg/deb/rpm that embeds the zipapp and libpython in an easy way.
comment 6y ago · link · parent
Those tools have been existing for years, and as always with Python, they serve only a subset of the Python users.
Not that it's a bad article. If you don't know about them, give it a read, it's good to know it exists and the post is well written.
But don't think it's the ultimate stack or whatever.
And if you learn Python, you should always strive to master the basics first:
- installing python.org for windows and mac, or apt/yum on Linux (those ones are tricky, it's more than just the "python" package to get pip and venv)
- don't try to get the latest and greatest version (which is 3.8, or 3.9 alpha today). 3.6 is great already and is wildly available. I personnally strive for 3.7 now, but I'm happy with 3.6 if I don't have to use asyncio. So get the most modern version that is easy to install for you.
- be comfortable with "-m", the "py" command on windows, "pip" (-m, --user, install, install -r, freeze), and "-m venv".
- make sure you understand what the PYTHON PATH is and how it works regarding the import system
- know how to configure your favorite editor to work with those
Once you have those basics, you can go and try whatever have you: peotry, pyenv, pew, virtualenvwrapper, pipenv and so on. It will be easy because you will have a solid understanding of where it comes from and how it plugs in into the ecosystem. You will be able to chose if they are worth it or not for you. And more importantly, when you will have to move away from them (because of work, because they don't suit you, because they are abandonned...), you will always be able to fall back to basics.
But franckly, there are so many things that you should be learning before those extras: pdb, black, pylint, zipapps... Or even concepts like generators, decorators, unpacking, etc. They all have a better value for the time you spend on them than learning a new "modern" stack.
Not that it's not useful to have a modern stack. I update my stack all the time.
I'm currently using pip + pew + doit + nox + pytest, and I'm experimenting with dephell.
But it's my full time job. I'm an expert.
Most Python devs have a much limited amount of resource to spent in learning stuff. They have deadlines, and other stuff to care about than Python.
I know because I go from company to administrations to students to train them, and it's always the same: they chose Python because it's an efficient use of their time.