Skip to content

Commit

Permalink
Added 'echo' to config
Browse files Browse the repository at this point in the history
The 'echo' option in config determines if the kernel should echo single commands.
  • Loading branch information
ticoneva committed Aug 11, 2022
1 parent 8fb6a18 commit f0638a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ installer cannot find any Stata installation.

The location of the configuration file is:

- `[prefix]/etc/pykernel-stata.conf` if `--sys-prefix` or `--prefix` is specified.
- `~/.pykernel-stata.conf` otherwise.
- `[prefix]/etc/pystata-kernel.conf` if `--sys-prefix` or `--prefix` is specified.
- `~/.pystata-kernel.conf` otherwise.

If a configuration file exists in both locations, the user version takes precedent.

Expand All @@ -44,6 +44,9 @@ The following settings are permitted inside the configuration file:
Default is 'be'.
- `graph_format`: Graph format. Acceptable values are 'png', 'pdf', 'svg' and 'pystata'.
Specify the last option if you want to use `pystata`'s setting. Default is 'png'.
- `echo`: If set to 'True', the kernel will echo the command while running a cell with only
a single command. This setting has no effect on cells containing multiple commands.
Default is 'False'.

Settings must be under the title `[pystata-kernel]`. Example:

Expand Down
6 changes: 5 additions & 1 deletion pystata-kernel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def get_config():
global_config_path = Path(os.path.join(sys.prefix,'etc','pystata-kernel.conf'))
user_config_path = Path('~/.pystata-kernel.conf').expanduser()

env = {'stata_dir': None, 'edition': None, 'graph_format': 'png'}
env = {'stata_dir': None,
'edition': None,
'graph_format': 'png',
'echo': 'False'
}

for cpath in (global_config_path,user_config_path):
try:
Expand Down
6 changes: 5 additions & 1 deletion pystata-kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)
self.stata_ready = False
self.shell.execution_count = 0
self.echo = False

def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
Expand All @@ -43,12 +44,15 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None,
pass
else:
set_graph_format(env['graph_format'])

if env['echo'] == 'True':
self.echo = True

self.stata_ready = True

# Execute Stata code
from pystata.stata import run
run(code, quietly=False, inline=True)
run(code, quietly=False, inline=True, echo=self.echo)
self.shell.execution_count += 1

return {'status': 'ok',
Expand Down

0 comments on commit f0638a4

Please sign in to comment.