Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyenv maybe doesn't like usage of "env python" in blueman #435

Closed
rworkman opened this Issue Jan 18, 2016 · 7 comments

Comments

Projects
None yet
4 participants
@rworkman
Copy link
Contributor

rworkman commented Jan 18, 2016

We got a report of problems with pyenv due to blueman's usage of "#!/usr/bin/env python" instead of "#!/usr/bin/python" - I'm not suggesting that this is a bug with blueman; I'm more interested in thoughts and how to address it with the reporter: http://www.linuxquestions.org/questions/slackware-14/current-blueman-using-env-sourced-python-4175564239/

@infirit infirit added the question label Jan 18, 2016

@infirit

This comment has been minimized.

Copy link
Contributor

infirit commented Jan 18, 2016

I am not sure we want to support switching version on the fly for blueman as we build a c module. Switching within the same major would probably be ok but I am pretty sure things go badly when switching major version.

@infirit

This comment has been minimized.

Copy link
Contributor

infirit commented Jan 18, 2016

There is no abi guarantee for python2 and a limited one for python3 so I would be very careful with switching version.

What most distro's do it rewrite the shbang so it works for them. Gentoo ppl of-course take this to the extreme and basically solved this problem already through rewriting shbang [1], python-exec wrapper and building for any version installed or needed/wanted.

[1] https://gitweb.gentoo.org/repo/gentoo.git/tree/eclass/python-utils-r1.eclass#n1059

@zakame

This comment has been minimized.

Copy link

zakame commented Jan 19, 2016

I'm the one who reported my problem on the Slackware forum; let me post in more detail here.

I noticed this first when Slackware-current updated blueman to the latest current stable (2.0.3) where in my Fluxbox startup I had /usr/bin/blueman-applet &, which failed. Upon running on an xterm, I saw

θ61° [zakame@drift:~] % /usr/bin/blueman-applet
Traceback (most recent call last):
  File "/usr/bin/blueman-applet", line 12, in <module>
    import dbus
ImportError: No module named 'dbus'

So naturally I checked the script, and saw it had a #!/usr/bin/env python shebang. Running with system python set explicitly seems to work:

θ80° [zakame@drift:~] % /usr/bin/python /usr/bin/blueman-applet
/usr/bin/blueman-applet:20: PyGIWarning: Notify was imported without specifying a version first. Use gi.require_version
('Notify', '0.7') before import to ensure that the right version gets loaded.                                         
  from gi.repository import Notify
blueman-applet version 2.0.3 starting
_________
Load (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:60)
['NetUsage', 'DBusService', 'Networking', 'RecentConns', 'DiscvManager', 'Headset', 'ExitItem', 'GameControllerWakelock
', 'PowerManager', 'PPPSupport', 'StatusIcon', 'NMDUNSupport', 'Menu', 'ShowConnected', 'AuthAgent', 'StandardItems', '
SerialManager', 'TransferService', 'NMPANSupport', 'KillSwitch', 'DhcpClient']                                        
_________
get_interface_version (/usr/lib64/python2.7/site-packages/blueman/bluez/BlueZInterface.py:13)
Detected BlueZ 5 
/usr/lib64/python2.7/site-packages/blueman/plugins/applet/GameControllerWakelock.py:11: PyGIWarning: GdkX11 was importe
d without specifying a version first. Use gi.require_version('GdkX11', '3.0') before import to ensure that the right ve
rsion gets loaded.                                                                                                    
  from gi.repository import Gdk, GdkX11
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.StatusIcon.StatusIcon'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.DBusService.DBusService'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.Headset.Headset'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.Networking.Networking'> 
_________
load_nap_settings (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/Networking.py:36)
Loading NAP settings 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.NMDUNSupport.NMDUNSupport'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.GameControllerWakelock.GameControllerWakelock'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.SerialManager.SerialManager'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.Menu.Menu'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.ExitItem.ExitItem'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.PowerManager.PowerManager'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.KillSwitch.KillSwitch'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.AuthAgent.AuthAgent'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.ShowConnected.ShowConnected'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
Not loading DhcpClient because it's conflict has higher priority 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.TransferService.TransferService'> 
_________
get_interface_version (/usr/lib64/python2.7/site-packages/blueman/bluez/obex/Base.py:20)
Detected BlueZ integrated obexd 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.DiscvManager.DiscvManager'> 
_________
update_menuitems (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/DiscvManager.py:123)
warning: Adapter is None 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.RecentConns.RecentConns'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
Not loading PPPSupport because it's conflict has higher priority 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.StandardItems.StandardItems'> 
_________
__load_plugin (/usr/lib64/python2.7/site-packages/blueman/main/PluginManager.py:133)
loading <class 'blueman.plugins.applet.NMPANSupport.NMPANSupport'> 
_________
io_event (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/KillSwitch.py:71)
killswitch registered 0 
_________
io_event (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/KillSwitch.py:71)
State: False 
_________
UpdatePowerState (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:159)
off True 
foff False 
on True 
current state True 
new state False 
_________
UpdatePowerState (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:159)
Signalling False 
_________
_on_obex_owner_changed (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/TransferService.py:170)
obex owner changed: :1.17 

(blueman-applet:23139): Gdk-CRITICAL **: gdk_window_thaw_toplevel_updates: assertion 'window->update_and_descendants_fr
eeze_count > 0' failed                                                                                                
_________
on_registered (/usr/lib64/python2.7/site-packages/blueman/bluez/obex/AgentManager.py:18)
/org/blueman/obex_agent 
_________
on_dbus_name_owner_change (/usr/bin/blueman-applet:94)
org.bluez owner changed to :1.1 
_________
set_nap (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/Networking.py:65)
set nap False 
_________
update_menuitems (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/DiscvManager.py:123)
warning: Adapter is None 
_________
enumerate_connections (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/ShowConnected.py:50)
Found 0 existing connections 
_________
RequestPowerState (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:131)
Requesting True 
_________
on_power_state_change_requested (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/KillSwitch.py:118)
True 
_________
UpdatePowerState (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:159)
off True 
foff False 
on False 
current state False 
new state False 
_________
io_event (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/KillSwitch.py:71)
killswitch changed 0 
_________
io_event (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/KillSwitch.py:71)
State: True 
_________
UpdatePowerState (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:159)
off True 
foff False 
on True 
current state False 
new state False 
_________
check (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:119)
callbacks done 
_________
set_adapter_state (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:90)
True 
_________
io_event (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/KillSwitch.py:71)
killswitch registered 8 
_________
io_event (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/KillSwitch.py:71)
State: True 
_________
UpdatePowerState (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:159)
off False 
foff False 
on True 
current state False 
new state True 
_________
UpdatePowerState (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:159)
Signalling True 
_________
initialize (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/RecentConns.py:144)
rebuilding menu 
_________
on_adapter_added (/usr/bin/blueman-applet:104)
Adapter added  /org/bluez/hci0 
_________
on_activate (/usr/bin/blueman-applet:107)
Adapter activated 
_________
set_nap (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/Networking.py:65)
set nap False 
_________
register_agent (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/AuthAgent.py:63)
Registering agent 
_________
enumerate_connections (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/ShowConnected.py:50)
Found 0 existing connections 
_________
initialize (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/RecentConns.py:144)
rebuilding menu 
_________
UpdatePowerState (/usr/lib64/python2.7/site-packages/blueman/plugins/applet/PowerManager.py:159)
off False 
foff False 
on True 
current state True 
new state True 

However, upon trying to click on the Bluetooth systray icon (or equivalently, right-clicking it to get the context menu and click "Devices") to open the blueman-manager fails:

Traceback (most recent call last):
  File "/usr/bin/blueman-manager", line 11, in <module>
    import dbus
ImportError: No module named 'dbus'

Backtracing this leads to blueman.Functions#launch, which in turn uses Gio.AppInfo#launch. I could no longer trace beyond that, but I suspect it uses an os.execv() to actually launch the scripts, which might explain the above (e.g. it launches the script with my pyenv-enabled user environment.)

@zakame

This comment has been minimized.

Copy link

zakame commented Jan 19, 2016

My workaround for now so far is to wrap my blueman-applet call in a script that explicitly turns off pyenv:

#!/bin/sh
PYENV_VERSION=system /usr/bin/blueman-applet
@cschramm

This comment has been minimized.

Copy link
Member

cschramm commented Jan 19, 2016

As @infirit describes for Gentoo, the shebangs also get replaced in deb packages by debhelper. After switching to Python 3 it now sets #!/usr/bin/python3. I thought this is common practice between all packaging systems.

We introduced /usr/bin/env as it seemed like the better default, see #187.

@infirit

This comment has been minimized.

Copy link
Contributor

infirit commented Feb 10, 2016

I think we can summarize this thread with:

  • /usr/bin/env python is more portable than hardcoding the paths.
  • Distro's typically modify the shebang to suit their needs.
  • We do not support switching python version on the fly as we require binary modules

If I am wrong please do correct me otherwise I suggest we close this 😄.

@cschramm cschramm closed this Feb 10, 2016

@rworkman

This comment has been minimized.

Copy link
Contributor Author

rworkman commented Feb 10, 2016

Yep, I think that's a decent summary - I'll recommend appropriate changes to our build. Thanks!

cschramm added a commit to cschramm/blueman that referenced this issue Mar 14, 2016

Put Python major version in shebang
This allows building for systems with both Python 2 and 3 without replacing the shebang. Replacing will only be necessary if env shall not be used e.g. as PyEnv might be present (see blueman-project#435) or a specific minor version needs to be defined (i.e. there are multiple minor versions on the target system and blueman is not built for the newest one; we cannot use minor versions as they are not mandatory, see PEP 394).

cschramm added a commit to cschramm/blueman that referenced this issue Mar 14, 2016

Put Python major version in shebang
This allows building for systems with both Python 2 and 3 without replacing the shebang. Replacing will only be necessary if env shall not be used e.g. as PyEnv might be present (see blueman-project#435) or a specific minor version needs to be defined (i.e. there are multiple minor versions on the target system and blueman is not built for the newest one; we cannot use minor versions as they are not mandatory, see PEP 394).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.