Skip to content

Commit

Permalink
Drop temp_pystata_kernel_program_name before creation
Browse files Browse the repository at this point in the history
Fixes the "program temp_pystata_kernel_program_name already defined r(110); " error.
  • Loading branch information
ticoneva committed Sep 4, 2023
1 parent 9702a02 commit ad4c62b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires Stata 17 or above.
Consider [stata_kernel](https://github.com/kylebarron/stata_kernel) instead if you have an
older version of Stata.

**Note: Starting with version 0.3.0, `pystata-kernel` will be updated once every six months.
**Note: Starting with version 0.3.1, `pystata-kernel` will be updated once every six months.
If new features and timely updates are important to you,
please consider using [`nbstata`](https://github.com/hugetim/nbstata),
which is further along in development.**
Expand Down
2 changes: 1 addition & 1 deletion pystata-kernel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.3.0'
__version__ = '0.3.1'

from .kernel import PyStataKernel
2 changes: 2 additions & 0 deletions pystata-kernel/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ def _is_start_of_program_block(clean_code_line_stripped):

def _run_as_program(clean_non_prog_code):
_program_name = "temp_pystata_kernel_program_name"
_program_drop_code = f"capture program drop {_program_name}"
_program_define_code = f"program {_program_name}\n{clean_non_prog_code}\nend\n"
pystata.stata.run(_program_drop_code,quietly=True)
pystata.stata.run(_program_define_code, quietly=True)
pystata.stata.run(_program_name, quietly=False, inline=True, echo=False)
pystata.stata.run(f"program drop {_program_name}", quietly=True)
Expand Down
4 changes: 2 additions & 2 deletions pystata-kernel/kernel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
pystata-kernel
Version: 0.3.0
Version: 0.3.1
A simple Jupyter kernel based on pystata.
Requires Stata 17 and stata_setup.
'''
Expand All @@ -13,7 +13,7 @@

class PyStataKernel(IPythonKernel):
implementation = 'pystata-kernel'
implementation_version = '0.3.0'
implementation_version = '0.3.1'
language = 'stata'
language_version = '17'
language_info = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='pystata-kernel',
version='0.3.0',
version='0.3.1',
packages=['pystata-kernel'],
package_data={'pystata-kernel': ['logo-64x64.png']},
description='A simple Jupyter kernel for Stata based on pystata',
Expand Down
14 changes: 14 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest
from pystata-kernel.helpers import clean_code

class Test_clean_code(unittest.TestCase):

def test_forvalues(self):
raw = """forvalues i=1/10 {
sum a
}
"""
out = """noisily forvalues i=1/10 {
noisily sum a
}"""
self.assertEqual(clean_code(raw), out)

0 comments on commit ad4c62b

Please sign in to comment.