Re: proper python3 interpreter invocation

From: Evilham <contact_at_evilham.com>
Date: Wed, 19 Oct 2022 09:36:40 UTC
Hey,

here just someone who has fiddled around with ports more than they 
are willing to admit, so take this with a grain of salt:

On dc., oct. 19 2022, Tomek CEDRO wrote:

> Hello world :-)
>
> Is Python 3 part of the base?

Nope

>
> What would be the most valid way to invoke a Python 3 script?
>
> Two options are possible:
> 1. #!/usr/bin/env python
> 2. #!/usr/bin/env python3

There is no python port on FreeBSD, so 1 would usually fail.
There *is* a python3 meta-port which points to the currently 
blessed python3 version.

>
> I am working on a mobile application in Python + Kivy that can 
> be then
> converted into Android and iOS application. It works fine here 
> on
> FreeBSD even in bare console (DRM KMS). I would like to build 
> Android
> application on FreeBSD (I know iOS version needs macOS+XCode). 
> For
> that I need Android NDK that is officially only provided for 
> Windows,
> macOS and Linux. I did a modification to make it work on FreeBSD 
> using
> Linux binaries. The goal is to create a FreeBSD Port for Android 
> NDK
> (no official support / releases will be provided for our 
> platform).
> But the patches are rejected at the upstream :-(
>
> https://github.com/android/ndk/issues/1780
> https://github.com/android/ndk/issues/1781
> https://github.com/android/ndk/issues/1785


That's great, that you're working on it that is.
For this kind of project, sadly I think it is somewhat common that 
upstream is a tad.. reticent accepting such patches.
Possibly the rationale is that if you get this to work, they'll 
start getting support requests / bug reports that have "nothing to 
do with their project". Who knows.

>
> This one is interesting in particular:
> https://github.com/android/ndk/issues/1785
>
> Some of their scripts use `#!/usr/bin/env python3` and some use
> `#!/usr/bin/env python`. The ones using `python` does not work 
> out of
> the box on FreeBSD.. so I wanted to unify the interpreter to use
> `python3` (or `python` whatever is best if there was any kind of
> sensible discussion).
>
> I know that I can create a Python VirtualEnv where python == 
> python3.
> Also I can create a symlink /usr/local/bin/python3 ->
> /usr/local/bin/python but that customization will make system
> incoherent with other standard installations. Maybe I should 
> simply
> create local patches when creating that port?


There is something even better than local patches, which is a 
shebangfix!
It'll point to the exact python version that is being supported 
(aka python3.X nowadays):

This is something actually supported by the ports infrastructure.
https://docs.freebsd.org/en/books/porters-handbook/uses/#uses-shebangfix

You can use it to, ehem, fix the shebang :-).
Off memory I can't recall a python port using that, but I am 
confident you'll find it by grepping around the ports tree.

Good luck moving forward ^^.
--
Evilham


> Google not only does not and will not provide releases for 
> FreeBSD but
> also rejects patches to make things work here. We are doomed to 
> a
> local fork on purpose :-(
>
> What would be the proper approach on FreeBSD? Where am I wrong?
>
> Any hints welcome :-)
> Tomek