News for hackers. Stuff that matters.
Re:Hypermodern Python by hprotagonist on Thursday May 28, 2020 @08:37AM (#23336528)
> Then there's the rigmarole around getting one of these environments to play nice with cron...

You pass cron the full path to your entry point. Where’s the rigamarole?

Re:Hypermodern Python by jalons on Thursday May 28, 2020 @08:55AM (#23336656)
You've also got to include the pyenv shim instantiation. So now you've got something like

0 0 * * * /path/to/bash/script/to/init/pyenv && /my/path/to/poetry run /my/path/to/python.py -arg1

Re:Hypermodern Python by Chiron1991 on Thursday May 28, 2020 @09:04AM (#23336752)
Hm, haven't tried it, but doing this should be much easier:

0 0 * * * /path/to/interpreter/created/by/poetry/bin/python myscript.py

Re:Hypermodern Python by EE84M3i on Thursday May 28, 2020 @09:58AM (#23337272)
Does bin/python in a virtualenv set PYTHONHOME correctly..?
Re:Hypermodern Python by remlov on Thursday May 28, 2020 @11:18AM (#23338338)
Yes. And the answer by Chiron1991 is the proper way to do this since pretty much forever.
Re:Hypermodern Python by EE84M3i on Thursday May 28, 2020 @11:54AM (#23338758)
Strange, this does seem to work with python3.8 on ubuntu 20.04 (the site-packages shows up in sys.path), but for me in a virtualenv bin/python is a symlink to the system python, so how does python 'know' what path to use? Is there logic baked into the interpreter?

I seem to recall that with python2.7 that calling bin/python in a virtualenv without activating the virtualenv did not used to "work" (i.e. it would use the system packages). Did this change at some point or is my memory just wrong?

Re:Hypermodern Python by jalons on Thursday May 28, 2020 @05:52PM (#23343206)
Yes, if the python interpreter the poetry environment utilizes is in your $PATH.
Re:Hypermodern Python by hprotagonist on Thursday May 28, 2020 @09:23AM (#23336917)
this is precisely correct.
Re:Hypermodern Python by cbcoutinho on Thursday May 28, 2020 @09:01AM (#23336719)
If the path to your executable is fixed, just put it in the shebang and you're done - makes everything way more explicit at the cost of some dynamic behavior.

An anecdote: Homebrew uses this method for shipping python executables.

Re:Hypermodern Python by im3w1l on Thursday May 28, 2020 @10:16AM (#23337498)
The "production version" of your script should be running in your system environment with system packages. pyenv and friends should be used for testing with different versions and making sure you don't accidentally depend on idiosyncrasies of your box.

The exception is if your python thingy is "the main thing" running on a server, i.e. your customer facing webapp.

My $.10 anyway

Re:Hypermodern Python by jalons on Thursday May 28, 2020 @10:21AM (#23337581)
I tend to agree with you that pyenv|pipenv|etc shouldn't be used for actual production usage.

This of course leads to other issues to solve, now that your development environment doesn't actually mirror production.

Re:Hypermodern Python by ses1984 on Thursday May 28, 2020 @10:23AM (#23337610)
How do you package your entire pyenv as one or more system packages?
Re:Hypermodern Python by im3w1l on Thursday May 28, 2020 @11:18AM (#23338340)
This isn't exactly what you are asking, but https://askubuntu.com/questions/90764/how-do-i-create-a-deb-...
Re:Hypermodern Python by hprotagonist on Thursday May 28, 2020 @11:02AM (#23338111)
pyinstaller, shiv, pex, docker: depending on use case, any of these may be appropriate.