os.environ and os.getenv()

Post Reply

Topic author
jeremybegg
Active Contributor
Posts: 29
Joined: Mon Jun 08, 2020 3:39 am
Reputation: 0
Status: Offline

os.environ and os.getenv()

Post by jeremybegg » Sun Dec 29, 2024 10:06 pm

Hi,

I've installed the Python and Python Wheels kit on my OpenVMS x86 V9.2-3 virtual machine, and want to tinker with Flask.

The Flask "quick-start" guide makes mention of defining environment variables such as FLASK_APP and FLASK_ENV, but no matter how I define them, Flask doesn't find them. I tried logical names and local and global DCL variables.

Flask, like many other Python modules, uses os.environ to look for these variables. But it seems that on OpenVMS, os.environ has a fixed set of values:

Code: Select all

VSMX86» my_test_symbol := symbol
VSMX86» show sym my_test_symbol
  MY_TEST_SYMBOL = "SYMBOL"
VSMX86» define my_test_symbol logical
VSMX86» show log my_test_symbol
   "MY_TEST_SYMBOL" = "logical" (LNM$PROCESS_TABLE)
VSMX86» python
Python 3.10.0 (default, Feb 21 2024, 05:22:10) [C] on OpenVMS
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ
environ({'PATH': '/DISK$USERS/JEREMY', 'HOME': '/DISK$USERS/JEREMY', 'TERM': 'vt400-132', 'USER': 'JEREMY', 'PYTHONHOME': '/python$r
oot'})
>>> os.environ.get('MY_TEST_SYMBOL')
>>> os.getenv('MY_TEST_SYMBOL')
'logical'
>>>
According to the Python documentation for the os module, os.getenv() simply looks up keys in os.environ.

It would appear this is NOT the case in VSI Python. Is there a workaround, so that modules which use os.environ will work?

Thanks
Jeremy Begg

User avatar

arne_v
Senior Member
Posts: 639
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: os.environ and os.getenv()

Post by arne_v » Sun Dec 29, 2024 10:17 pm

See https://forum.vmssoftware.com/viewtopic ... 68&p=21676

Added in 19 seconds:
There should be a fix underway.
Arne
arne@vajhoej.dk
VMS user since 1986


jfp
Contributor
Posts: 18
Joined: Wed Jun 17, 2020 6:34 am
Reputation: 0
Status: Offline

Re: os.environ and os.getenv()

Post by jfp » Thu Jan 02, 2025 9:28 am

Hi Jeremy,

This is a bug I have written a fix years ago for mercurial :
https://foss.heptapod.net/mercurial/mer ... type=heads

search for OpenVMS, extract :

Code: Select all

_nativeenviron = os.supports_bytes_environ
if _nativeenviron:
    environ = os.environb  # re-exports
    if pycompat.sysplatform == b'OpenVMS':
        # workaround for a bug in VSI 3.10 port
        # os.environb is only populated with a few Predefined symbols
        def newget(self, key, default=None):
            # pytype on linux does not understand OpenVMS special modules
            import _decc  # pytype: disable=import-error

            v = _decc.getenv(key, None)
            if isinstance(key, bytes):
                return default if v is None else v.encode('latin-1')
            else:
                return default if v is None else v

        environ.__class__.get = newget
JF

Post Reply