def test_ipython(tmp_path): os.chdir(str(tmp_path)) dotenv_file = tmp_path / '.env' dotenv_file.write_text("MYNEWVALUE=q1w2e3\n") ipshell = InteractiveShellEmbed() ipshell.magic("load_ext dotenv") ipshell.magic("dotenv") assert os.environ["MYNEWVALUE"] == 'q1w2e3'
def test_ipython(tmp_path): os.chdir(str(tmp_path)) dotenv_file = tmp_path / '.env' dotenv_file.write_text("MYNEWVALUE=q1w2e3\n") ipshell = InteractiveShellEmbed() ipshell.magic("load_ext dotenv") ipshell.magic("dotenv") assert os.environ["MYNEWVALUE"] == 'q1w2e3'
def test_ipython(): tmpdir = os.path.realpath(tempfile.mkdtemp()) os.chdir(tmpdir) filename = os.path.join(tmpdir, '.env') with open(filename, 'w') as f: f.write("MYNEWVALUE=q1w2e3\n") ipshell = InteractiveShellEmbed() ipshell.magic("load_ext dotenv") ipshell.magic("dotenv") assert os.environ["MYNEWVALUE"] == 'q1w2e3'
def test_ipython_override(tmp_path): from IPython.terminal.embed import InteractiveShellEmbed os.chdir(str(tmp_path)) dotenv_file = tmp_path / '.env' os.environ["MYNEWVALUE"] = "OVERRIDE" dotenv_file.write_text("MYNEWVALUE=q1w2e3\n") ipshell = InteractiveShellEmbed() ipshell.magic("load_ext dotenv") ipshell.magic("dotenv -o") assert os.environ["MYNEWVALUE"] == 'q1w2e3'
def test_ipython_new_variable(tmp_path): from IPython.terminal.embed import InteractiveShellEmbed dotenv_file = tmp_path / ".env" dotenv_file.write_text("a=b\n") os.chdir(str(tmp_path)) ipshell = InteractiveShellEmbed() ipshell.magic("load_ext dotenv") ipshell.magic("dotenv") assert os.environ == {"a": "b"}
def start(): ip_shell = InteractiveShellEmbed() present_working_directory = ip_shell.magic("%pwd") print(present_working_directory) os.system("cd "+present_working_directory) temp=os.system(cmd) print(temp)
def get_companyname(self): Company_name = [] ip_shell = InteractiveShellEmbed() present_working_directory = ip_shell.magic("%pwd") print(present_working_directory + '/DK companies.xlsx') workbook = xlrd.open_workbook(present_working_directory + '/DK companies.xlsx', on_demand=True) max_nb_row = 0 for sheet in workbook.sheets(): max_nb_row = max(max_nb_row, sheet.nrows) for rows in range(1, max_nb_row): for sheet in workbook.sheets(): if rows < sheet.nrows: rows = sheet.row_values(rows) if rows[3].find('DK') > -1: Company_name.append(rows) return Company_name
if __name__ == '__main__': from IPython.terminal.embed import InteractiveShellEmbed import argparse import pandas as pd import os # argparse.ArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=argparse.HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True) parser = argparse.ArgumentParser(description='') # parser.add_argument(name or flags...[, action][, nargs][, const][, default][, type][, choices][, required][, help][, metavar][, dest]) parser.add_argument('-i', '--inp', help='Input recfile', required=True) parser.add_argument('-s', '--script', help='Script file to run or to create', required=True) args = parser.parse_args() global rec rec = load(args.inp) rec = pd.DataFrame(rec) if not os.path.exists(args.script): ipshell = InteractiveShellEmbed() print('rec file data stored in recfile') ipshell.magic(f"%logstart {args.script}") ipshell() else: with open(args.script, 'r') as script: cmd = script.read() exec(cmd) if rec.index.name is None: rec.index.name = 'recid'
def n(): "Next element in the MENU" PAST_MENU.append(MENU.pop(0)) return PAST_MENU[-1]() def p(): """Previous element in the menu""" MENU.insert(0, PAST_MENU.pop()) return MENU[0]() def r(): shell.magic("%clear") shell.magic("%rep") for k in pystemd.systemd1.unit_signatures.KNOWN_UNIT_SIGNATURES: k = k.decode() exec(f'{k}="{k}"') if __name__ == '__main__': shell = InteractiveShellEmbed() clean_unit() shell.show_banner(display_banner) shell.magic("%autocall 2") shell.magic("%clear") shell.mainloop()
from IPython.terminal.embed import InteractiveShellEmbed ipshell = InteractiveShellEmbed() ipshell.dummy_mode = True import os import numpy as np print('\nInstall Trax:') ipshell.magic("%pip install -q -U trax") import trax
def main(): ''' Run IPython shell. ''' ipy_shell = InteractiveShellEmbed( banner1=f'IPython Shell: Starbelly v{__version__}') ipy_shell.magic('autoawait trio') ipy_shell()