How to use the plumbum.local.env function in plumbum

To help you get started, we’ve selected a few plumbum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tomerfiliba / plumbum / tests / test_env.py View on Github external
def test_custom_env(self):
        with local.env():
            items = {"one": "OnE", "tww": "TWOO"}
            local.env.update(items)
            assert "tww" in local.env
            local.env.clear()
            assert "tww" not in local.env
github tkluck / pac4cli / test / runtests.py View on Github external
def test_direct_proxy(self):
        proxy = pac4cli["-F", "DIRECT", "-p", "23128"] & BG
        sleep(3)
        try:
            with plumbum.local.env(http_proxy="localhost:23128"):
                curl("http://www.booking.com")
                self.assertTrue(True)
        finally:
            proxy.proc.kill()
github tomerfiliba / plumbum / tests / _test_paramiko.py View on Github external
from plumbum.paramiko_machine import ParamikoMachine as PM
from plumbum import local

local.env.path.append("c:\\progra~1\\git\\bin")
from plumbum.cmd import ls, grep


m = PM("192.168.1.143")
mls = m["ls"]
mgrep = m["grep"]
# (mls | mgrep["b"])()

(mls | grep["\\."])()

(ls | mgrep["\\."])()
github tkluck / pac4cli / test / runtests.py View on Github external
# server for wpad.dat
        with plumbum.local.cwd(testdir / "wpadserver"):
            static_server = python["-m", "http.server", 8080] & BG

        # mock upstream proxies
        fake_proxy_1 = (serve_once[23130] < testdir / "fake-proxy-1-response") & BG
        fake_proxy_2 = (serve_once[23131] < testdir / "fake-proxy-2-response") & BG

        # proxy getting its config from DHCP
        with plumbum.local.env(DBUS_SYSTEM_BUS_ADDRESS=os.environ['DBUS_SYSTEM_BUS_ADDRESS']):
            proxy_to_test = pac4cli["-p", "23129"] & BG(stdout=sys.stdout, stderr=sys.stderr)

        sleep(3)
        try:
            with plumbum.local.env(http_proxy="localhost:23129"):
                self.assertEqual(
                    curl("http://www.booking.com"),
                    # when changing this string, don't forget to change
                    # the Content-Length header as well.
                    "Hello from fake proxy no 1!",
                )
                self.assertEqual(
                    curl("http://www.google.com"),
                    # (same)
                    "Hello from fake proxy no 2!",
                )
        finally:
            proxy_to_test.proc.kill()
            fake_proxy_2.proc.kill()
            fake_proxy_1.proc.kill()
            static_server.proc.kill()
github tomerfiliba / plumbum / tests / test_local.py View on Github external
def test_local(self):
        from plumbum.cmd import cat, head
        assert "plumbum" in str(local.cwd)
        assert "PATH" in local.env.getdict()
        assert local.path("foo") == os.path.join(os.getcwd(), "foo")
        local.which("ls")
        local["ls"]
        assert local.python("-c", "print ('hi there')").splitlines() == ["hi there"]
github tomerfiliba / plumbum / tests / test_local.py View on Github external
def test_env(self):
        assert "PATH" in local.env
        assert "FOOBAR72" not in local.env
        with pytest.raises(ProcessExecutionError):
            local.python("-c", "import os;os.environ['FOOBAR72']")
        local.env["FOOBAR72"] = "spAm"
        assert local.python("-c", "import os;print (os.environ['FOOBAR72'])").splitlines() == ["spAm"]

        with local.env(FOOBAR73 = 1889):
            assert local.python("-c", "import os;print (os.environ['FOOBAR73'])").splitlines() == ["1889"]
            with local.env(FOOBAR73 = 1778):
                assert local.python("-c", "import os;print (os.environ['FOOBAR73'])").splitlines() == ["1778"]
            assert local.python("-c", "import os;print (os.environ['FOOBAR73'])").splitlines() == ["1889"]
        with pytest.raises(ProcessExecutionError):
            local.python("-c", "import os;os.environ['FOOBAR73']")

        # path manipulation
        with pytest.raises(CommandNotFound):
            local.which("dummy-executable")
        with local.env():
            local.env.path.insert(0, local.cwd / "not-in-path")
            p = local.which("dummy-executable")
            assert p == local.cwd / "not-in-path" / "dummy-executable"
github GooFit / GooFit / examples / RunAll.py View on Github external
def main(self, threads=None):
        env = local.env(OMP_NUM_THREADS=threads) if threads else local.env()
        with env:
            results = make_results(self.profile)
        failed = [result for result in results if result['code'] != 0]
        successes = [result for result in results if result['code'] == 0]

        if failed:
            colors.fatal.print("Failed:")
            for result in failed:
                colors.fatal.print(result['name'], result['code'])
        else:
            colors.success.print("All programs completed.")

        print()
        colors.info.print('{0:20}:\tTotal time (s)\tFit times'.format("Program"))
        for result in successes:
            fit = ', '.join(MIN_TIME.findall(result['stdout']))
github ibis-project / ibis / ci / datamgr.py View on Github external
)
            continue

        load = psql[
            '--host',
            params['host'],
            '--port',
            params['port'],
            '--username',
            params['user'],
            '--dbname',
            database,
            '--command',
            query.format(table),
        ]
        with local.env(PGPASSWORD=params['password']):
            with src.open('r') as f:
                load(stdin=f)

    engine.execute('VACUUM FULL ANALYZE')