Re: NVDA Add-ons Community Directive: do NOT override system environment variables by assigning new strings


 

Hi,
Ah, thanks for clarifying many things for us (and for me, personally).
Cheers,
Joseph

-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io>
On Behalf Of James Scholes
Sent: Thursday, January 21, 2021 4:16 PM
To: nvda-addons@nvda-addons.groups.io
Subject: Re: [nvda-addons] NVDA Add-ons Community Directive: do NOT override
system environment variables by assigning new strings

I agree that overwriting the PATH variable rather than adding to it is a bad
idea. But just to be clear:

1. If an NVDA add-on uses os.environ, any changes made will only apply
inside the running NVDA process. Which is still bad, but the system
variable will not be altered and Windows will not collapse. When you
restart NVDA, it will get the old value back.
2. An NVDA add-on developer would really have to go out of their way to
screw up the environment variables for the user account or entire system.
If they had the knowledge or desire to do so, their intentions are likely
nefarious and probably unaffected by any community notices.
3. If you do really, legitimately want to add a directory to PATH, you
should prepend it and not append to avoid conflicts with anything in other
directories on the system which share an executable name.

Regards,

James Scholes

On 21/01/2021 at 1:15 pm, Joseph Lee wrote:
Hi all,

The following NVDA Add-ons community directive applies to ALL add-ons
going forward and will be applied when reviewing add-ons:

You can query system environment variables by doing:

import os

os.environ[variableString]

 

A crucial environment variable is system path (os.environ[“path”]). This
variable is used by operating systems (in this case, Windows) to search
listed directories for executables. The variable is not really a string – it
is a list of strings separated by a semicolon.

If an add-on wants to add new paths to environment variables:

# Don’t do this:

os.environ[“path”] = newStr

 

# Alternative 1:

Os.environ[“path”] += “;” + pathStr

 

# Alternative 2:

environPath = os.environ[“path”].split(“;”)

environPath.append(newPath)

os.environ[“path”] = “;”.join(environPath)

 

# Improved alternative 2:

newPath = somePath

environPath = os.environ[“path”].split(“;”)

if newPath not in environPath:

environPath.append(newPath)

  os.environ[“path”] = “;”.join(environPath)

 

Any add-on that overrides environment variables without preserving old
values will break add-ons that opens executables for their features.

 

Community directive: going forward, if an add-on is found to have modified
system environment variables without preserving existing values will be
flagged and authors will be asked to release a fix as soon as possible. Or,
for that matter, do NOT ever (EVER) modify environment variables just for
convenience (especially system path variable, as it will break NVDA,
add-ons, and quite possibly Windows). This directive takes effect
immediately.

 

The above directive applies to all add-ons, including those outside
community add-ons website.

 

Affected add-ons:

* Acapela TTS 1.6.5 (based on investigations by an add-on author).
* Others that directly edit environment path variable without preserving
existing values.

 

Next steps:

1. Existing add-ons on community add-ons website should be examined by
authors to see if the above community directive should be applied.
2. New add-ons or add-ons currently under review (including ones with
pending review requests) will be subject to the directive before review
(including pending review) begins.
3. Developers of add-ons hosted outside community add-ons website will be
asked to modify their add-ons if the above community directive should be
applied to their add-ons.
4. The NVDA Add-ons community urges developers of Acapela TTS add-on to
release a fix as soon as possible.

 

Cheers,

Joseph

Join nvda-addons@nvda-addons.groups.io to automatically receive all group messages.