-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from jld23/master
Add SAS log Magics.
- Loading branch information
Showing
8 changed files
with
124 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# | ||
# Copyright SAS Institute | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the License); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
def isnotebook(): | ||
try: | ||
shell = get_ipython().__class__.__name__ | ||
if shell == 'ZMQInteractiveShell': | ||
return True # Jupyter notebook or qtconsole | ||
elif shell == 'TerminalInteractiveShell': | ||
return False # Terminal running IPython | ||
else: | ||
return False # Other type (?) | ||
except NameError: | ||
return False # Probably standard Python interpreter | ||
|
||
if isnotebook(): | ||
from sas_kernel.magics.log_magic import logMagic | ||
get_ipython().register_magics(logMagic) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,4 @@ | |
|
||
|
||
"""SAS Kernel Juypter Implementation""" | ||
|
||
__version__ = '2.1.7' | ||
from sas_kernel.version import __version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# | ||
# Copyright SAS Institute | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the License); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from metakernel import Magic | ||
from IPython.display import HTML | ||
from pygments import highlight | ||
from saspy.SASLogLexer import SASLogStyle, SASLogLexer | ||
from pygments.formatters import HtmlFormatter | ||
|
||
class logMagic(Magic): | ||
def __init__(self, *args, **kwargs): | ||
super(logMagic, self).__init__(*args, **kwargs) | ||
|
||
def line_showLog(self): | ||
""" | ||
SAS Kernel magic to show the SAS log for the previous submitted code. | ||
This magic is only available within the SAS Kernel | ||
""" | ||
if self.kernel.mva is None: | ||
print("Can't show log because no session exists") | ||
else: | ||
return self.kernel.Display(HTML(self.kernel.cachedlog)) | ||
|
||
|
||
def line_showFullLog(self): | ||
""" | ||
SAS Kernel magic to show the entire SAS log since the kernel was started (last restarted) | ||
This magic is only available within the SAS Kernel | ||
""" | ||
if self.kernel.mva is None: | ||
self.kernel._allow_stdin = True | ||
self.kernel._start_sas() | ||
print("Session Started probably not the log you want") | ||
full_log = highlight(self.kernel.mva.saslog(), SASLogLexer(), HtmlFormatter(full=True, style=SASLogStyle, lineseparator="<br>")) | ||
return self.kernel.Display(HTML(full_log)) | ||
|
||
def register_magics(kernel): | ||
kernel.register_magics(logMagic) | ||
|
||
|
||
def register_ipython_magics(): | ||
from metakernel import IPythonKernel | ||
from IPython.core.magic import register_line_magic | ||
kernel = IPythonKernel() | ||
magic = logMagic(kernel) | ||
# Make magics callable: | ||
kernel.line_magics["showLog"] = magic | ||
kernel.line_magics["showFullLog"] = magic | ||
|
||
@register_line_magic | ||
def showLog(line): | ||
kernel.call_magic("%showLog " + line) | ||
|
||
@register_line_magic | ||
def showFullLog(line): | ||
kernel.call_magic("%showFullLog " + line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright SAS Institute | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the License); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
__version__ = '2.2.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters