Skip to main content

setenvironment

MacOS_Tests Win_Tests Ubuntu_Tests

Linting

Finally, a cross platform way to set system environment variables and paths that are persistant across reboots.

Works with Windows, MacOS and Linux and github runners, see note below.

Extensively tested.

Command line interface

# Setting environmental variables
setenvironment show
setenviornment bashrc  # unix only.
setenvironment set foo bar
setenvironment has foo
setenvironment get foo
setenvironment del foo
# Path manipulation.
setenvironment addpath /my/path
setenvironment get PATH
setenvironment delpath /my/path
setenvironment refresh "echo this command is in a refreshed environment"

Python API

from setenvironment import (
    set_env_var, add_env_path, unset_env_var, remove_env_path, set_config_file, reload_environment, ...
)
# by default, ~/.bashrc is used
set_env_var("FOO", "BAR")
get_env_var("FOO") # returns BAR
add_env_path("MYPATH")
unset_env_var("FOO")
remove_env_path("MYPATH")
# use ~/.bash_profile instead (no op on Windows)
set_config_file("~/.bash_profile")
set_env_var("FOO", "BAR")
add_env_path("MYPATH")
unset_env_var("FOO")
remove_env_path("MYPATH")
# Loads settings into the current environment. This reads the
# registry on windows or the ~/.bashrc file on unix.
reload_environment()
# Path groups are usefull for uninstall programs. Each add
# copies the path both into the PATH and also to the key.
# When you want to remove paths you can query the key and selectively
# remove paths that are in the set.
add_to_path_group("MYPATHKEY", "/path/to/dir")
remove_to_path_group("MYPATHKEY", "/path/to/dir")
# Or else you can just remove ALL of the paths at once.
remove_path_group("MYPATHKEY")

Github

These are designed to be compatible with github runners.

Ubuntu MUST use the following to make this package work.

name: Ubuntu_Tests

# Directs GitHub to run tests using ~/.bashrc
defaults:
    run:
      shell: bash -ieo pipefail {0}

on: [push]

Windows

Paths are set in the registery and the current os.environ

  • writes to the registery
  • broadcasts the new value (cmd.exe ignores this though) to all available processes
  • paths like /my/path will be converted to \\my\\path

MacOS / Linux

Paths are set in either ~/.bash_aliases or ~/.bash_profile or ~/.bashrc file or you can override it, see set_config_file(...) and the command line arguments if using the command line api.

  • export the variable (so you can source the script)
  • set the os.environ to the proper value
  • write the value to the .bashrc file (make sure it's chmod +w)

Release Notes

  • 2.0.3: Disables the refresh.cmd, since it doesn't work for subprocesses.
  • 2.0.2: Re-enabled broadcast changes on win32, fixing new terminal launch.
  • 2.0.1: Bug fix.
  • 2.0.0: Rewrite. New command line api. Extensively tested on mac/win/ubuntu X github.

Metadata

Release files for setenvironment 2.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for setenvironment 2.0.3
File Size Uploaded
setenvironment-2.0.3.tar.gz 29.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for setenvironment 2.0.3
File Interpreter ABI Platform
setenvironment-2.0.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 51.0 kB

Release files / setenvironment-2.0.3.tar.gz

Download URL setenvironment-2.0.3.tar.gz
Size 29.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0d79b41981df0c7349396aaaea99c18e282795e4c20e3c5ad060003a61d7629b
BLAKE2b-256 checksum
How to use checksums
1b747cdc8d78e06e32955f14c0ac6b4905bf1375d60968a61144b8b358ae3760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / setenvironment-2.0.3-py2.py3-none-any.whl

Download URL setenvironment-2.0.3-py2.py3-none-any.whl
Size 21.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9cee2abdf2b8a479a01f1e02dab8d03eaf99c449a1d47093517ae17992e568e4
BLAKE2b-256 checksum
How to use checksums
bd33e023fa75cdf7965700a76e694358d75a20a83e91d9458f58891dff94bd73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2.0

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page