robhagemans / pcbasic

PC-BASIC - A free, cross-platform emulator for the GW-BASIC family of interpreters
http://www.pc-basic.org
Other
396 stars 48 forks source link

pcbasic doesn't run as part of a linux service #133

Closed savetz closed 2 years ago

savetz commented 3 years ago

Bug report

Problem I am invoking pcbasic from a python script on linux. When the script is run from the command line, it works perfectly and pcbasic works perfectly. But when my script in run as a linux system service, pcbasic fails. As far as I can tell, it is checking os.getenv('TERM') and excepting a string, but I guess since it's running from a service, os.getenv returns None.

Feb 21 22:56:11 8bitbot python3[26473]: Traceback (most recent call last): Feb 21 22:56:11 8bitbot python3[26473]: File "/home/atari8/.local/bin/pcbasic", line 6, in Feb 21 22:56:11 8bitbot python3[26473]: from pcbasic import main Feb 21 22:56:11 8bitbot python3[26473]: File "/home/atari8/.local/lib/python2.7/site-packages/pcbasic/init.py", line 15, in Feb 21 22:56:11 8bitbot python3[26473]: from .basic import version Feb 21 22:56:11 8bitbot python3[26473]: File "/home/atari8/.local/lib/python2.7/site-packages/pcbasic/basic/init.py", line 9, in Feb 21 22:56:11 8bitbot python3[26473]: from .api import Session, codepage, font Feb 21 22:56:11 8bitbot python3[26473]: File "/home/atari8/.local/lib/python2.7/site-packages/pcbasic/basic/api.py", line 11, in Feb 21 22:56:11 8bitbot python3[26473]: from ..compat import text_type Feb 21 22:56:11 8bitbot python3[26473]: File "/home/atari8/.local/lib/python2.7/site-packages/pcbasic/compat/init.py", line 52, in Feb 21 22:56:11 8bitbot python3[26473]: from .posix_console import console, read_all_available, IS_CONSOLE_APP Feb 21 22:56:11 8bitbot python3[26473]: File "/home/atari8/.local/lib/python2.7/site-packages/pcbasic/compat/posix_console.py", line 50, in Feb 21 22:56:11 8bitbot python3[26473]: if os.getenv('TERM').startswith('linux'): Feb 21 22:56:11 8bitbot python3[26473]: AttributeError: 'NoneType' object has no attribute 'startswith'

Notes I am completely willing to be wrong or stupid here.

PC-BASIC version: 2.0.3 Operating system version: Raspbian GNU/Linux 10 (buster)

Marrin commented 3 years ago

How exactly are you trying to run that and why still Python 2.7? That's EOL since last year.

robhagemans commented 3 years ago

Not sure what exactly is being tried or whether that's a good idea, but looking at the stack trace I think the diagnosis is correct - the assumption is that $TERM is defined and if not, it breaks. So this should probably read os.getenv('TERM', default='').startswith('linux'). This won't be dependent on Python version, though 2.7 is of course retired now.

savetz commented 3 years ago

@robhagemans solution solved my problem. Thank you!

As for the question of why I am using python 2.7 — on every installation I have used in my (relatively limited) experience, on both macos and linux, 'python' launches python 2.x and 'python3' launches python 3.x. I think that's pretty standard behavior? I installed pcbasic without changing a thing, it asked for python, so it got 2.7, and worked fine, so I haven't worried about it.

robhagemans commented 3 years ago

Just to confirm python 2.7 remains supported by PC-BASIC for now - by which I mean it's written to work both in 2.7 and 3.x, and releases have been testes on both. This is mainly to avoid breaking existing scripts, and because all the work to make it compatible with both has been done anyway - so it seems reasonable to not break it with minor changes. It may change, or at least become unofficial, with one of the next releases, since 2.7 is EOL.

As it stands, indeed it uses #!/usr/bin/env python as this is the PEP394-recommended way for a script that supports both versions. I'll likely change this to python3 with the next release even if I retain 2.7 compatibility.

robhagemans commented 2 years ago

Fixed on develop by commit 10c465a3d