Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nteract detect; fix notebook_app set by environment variable; dis… #111

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ venv.bak/
/private_local

# dependencies
/Scripts
/share
/etc
**/Scripts/**
**/share/**
**/etc/**

# private notebooks
/my notebooks
Expand Down
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
"python.condaPath": "C:\\Users\\michabin\\Anaconda3\\Scripts",
"python.terminal.activateEnvironment": true,
"restructuredtext.confPath": "",
"python.linting.pylintEnabled": true,
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/K", "C:\\Users\\michabin\\anaconda3\\Scripts\\activate.bat"],
"terminal.integrated.env.windows": {
"PYTHONPATH": "C:\\MyProjects\\KqlmagicAtMicrosoftGithub\\jupyter-Kqlmagic\\azure"
},
"python.linting.enabled": true
}
2 changes: 1 addition & 1 deletion azure/Kqlmagic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# to avoid this warnig to be dispayed:
# UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
import setuptools
except:
except: # pylint: disable=bare-except
pass

from .magic_extension import load_ipython_extension, unload_ipython_extension, _register_kqlmagic_magic
Expand Down
2 changes: 1 addition & 1 deletion azure/Kqlmagic/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def finalize_options(self):
def run_tests(self):
try:
import pytest # type: ignore reportMissingImports # pylint: disable=import-error
except:
except: # pylint: disable=bare-except
pass
else:
errno = pytest.main(self.pytest_args)
Expand Down
2 changes: 1 addition & 1 deletion azure/Kqlmagic/activate_kernel_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def is_python_code(lines:List[str])->bool:
tr_py_code = IPythonAPI.transform_cell(py_code)
ast.parse(tr_py_code)
is_py_code = True
except:
except: # pylint: disable=bare-except
pass
return is_py_code

Expand Down
8 changes: 4 additions & 4 deletions azure/Kqlmagic/bug_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def _python_info() -> dict:
else:
implementation_version = 'Unknown'

except:
except: # pylint: disable=bare-except
pass

try:
implementation_branch = platform.python_branch()
except:
except: # pylint: disable=bare-except
implementation_branch = 'Unknown'

return {'name': implementation, 'version': implementation_version, 'branch': implementation_branch}
Expand All @@ -62,12 +62,12 @@ def _platform_info() -> dict:

try:
platform_system = platform.system()
except:
except: # pylint: disable=bare-except
platform_system = 'Unknown'

try:
platform_release = platform.release()
except:
except: # pylint: disable=bare-except
platform_release = 'Unknown'

return {'system': platform_system, 'release': platform_release}
Expand Down
2 changes: 1 addition & 1 deletion azure/Kqlmagic/cache_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _get_endpoint_version(self, json_response:Dict[str,Any])->str:
try:
tables_num = json_response["Tables"].__len__() # pylint: disable=W0612
return "v1"
except:
except: # pylint: disable=bare-except
return "v2"


Expand Down
4 changes: 2 additions & 2 deletions azure/Kqlmagic/column_guesser.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ def _build_chart_sub_tables(self, properties:dict, name=None, x_type="first") ->
elif tab.col_y_min is None:
try:
tab.col_y_min = min(min(filter(lambda x: x is not None, tab.values())), 0) * 1.1
except:
except: # pylint: disable=bare-except
tab.col_y_min = None
elif tab.col_y_max is None:
try:
tab.col_y_max = max(filter(lambda x: x is not None, tab.values())) * 1.1
except:
except: # pylint: disable=bare-except
tab.col_y_max = None

return self.chart_sub_tables
Expand Down
4 changes: 2 additions & 2 deletions azure/Kqlmagic/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ def get_module(cls, module_name:str, package_name:str=None, version_location:str
version_module = importlib.import_module(version_location)
cls.installed_modules[version_location] = version_module
version = version_module.__version__
except:
except: # pylint: disable=bare-except
try:
import pkg_resources # part of setuptools
version = pkg_resources.require(package_name)[0].version
except:
except: # pylint: disable=bare-except
pass
cls.installed_versions[package_name] = version or "?.?.?"
return module
Expand Down
4 changes: 2 additions & 2 deletions azure/Kqlmagic/dict_db_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ def restore(self)->str:
value = self._crypto_obj.decrypt(state_encrypted.get("data"))
return value

except:
except: # pylint: disable=bare-except
try:
self.db_key_conflict = True

self._crypto_obj.verify(state_encrypted)
Display.showWarningMessage("Warning: SSO disabled, due to cache_name conflict")

except: # the token has bad form
except: # pylint: disable=bare-except
Display.showWarningMessage("Warning: SSO disabled, due to cache_name conflict (invalid data in db)")
# del self.db[self.db_key]
4 changes: 2 additions & 2 deletions azure/Kqlmagic/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pygments import highlight
from pygments.lexers.data import JsonLexer
from pygments.formatters.terminal import TerminalFormatter
except:
except: # pylint: disable=bare-except
highlight = None
JsonLexer = None
TerminalFormatter = None
Expand All @@ -49,7 +49,7 @@ def __init__(self, item, *args, **kwargs):
if highlight and JsonLexer and TerminalFormatter:
try:
self.colorful_json = highlight(formatted_json.encode("UTF-8"), JsonLexer(), TerminalFormatter())
except:
except: # pylint: disable=bare-except
pass

def get(self, key, default=None):
Expand Down
4 changes: 2 additions & 2 deletions azure/Kqlmagic/draft_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def execute(self, id:str, query:str, accept_partial_results:bool=False, **option
if response.status_code < 200 or response.status_code >= 300: # pylint: disable=E1101
try:
parsed_error = json.loads(response.text)
except:
except: # pylint: disable=bare-except
parsed_error = response.text
# collect this inormation, in case bug report will be generated
self.last_query_info["response"]["error"] = parsed_error # pylint: disable=unsupported-assignment-operation, unsubscriptable-object
Expand All @@ -283,7 +283,7 @@ def execute(self, id:str, query:str, accept_partial_results:bool=False, **option
if kql_response.has_exceptions() and not accept_partial_results:
try:
error_message = json_dumps(kql_response.get_exceptions())
except:
except: # pylint: disable=bare-except
error_message = str(kql_response.get_exceptions())
raise KqlError(error_message, response, kql_response)

Expand Down
30 changes: 15 additions & 15 deletions azure/Kqlmagic/ipython_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
try:
try:
from IPython import display as ipy_display
except:
except: # pylint: disable=bare-except
import IPython.core.display as ipy_display

display = ipy_display.display
HTML = ipy_display.HTML
Javascript = ipy_display.Javascript
JSON = ipy_display.JSON
except:
except: # pylint: disable=bare-except
display = None
HTML = None
Javascript = None
Expand Down Expand Up @@ -57,13 +57,13 @@ def get_notebook_kernel_id(cls)->str:
import re
try:
import ipykernel as kernel
except:
except: # pylint: disable=bare-except
from IPython.lib import kernel

connection_file = kernel.get_connection_file()
cls.kernel_id = re.search('kernel-(.*).json', connection_file).group(1)

except:
except: # pylint: disable=bare-except
import uuid
cls.kernel_id = f"{uuid.uuid4()}"

Expand Down Expand Up @@ -91,13 +91,13 @@ def _get_ipython(cls):
if "IPython" in sys.modules:
try:
from IPython import get_ipython
except:
except: # pylint: disable=bare-except
get_ipython = None

if get_ipython is not None:
try:
cls.ip = get_ipython() # pylint: disable=undefined-variable
except:
except: # pylint: disable=bare-except
pass
return cls.ip

Expand Down Expand Up @@ -136,7 +136,7 @@ def try_kernel_execute(cls, javascript_statement:str, **options)->bool:
try:
ip.run_cell_magic('javascript', '', javascript_statement)
return True
except:
except: # pylint: disable=bare-except
pass

return False
Expand Down Expand Up @@ -203,7 +203,7 @@ def try_register_to_ipython_atexit(cls, func, *args)->bool:
try:
import atexit
atexit.register(func, *args)
except:
except: # pylint: disable=bare-except
return False


Expand All @@ -215,7 +215,7 @@ def try_init_ipython_matplotlib_magic(cls, **options)->bool:
try:
ip.magic(f"matplotlib {matplotlib_magic_command}")
return True
except:
except: # pylint: disable=bare-except
return False


Expand Down Expand Up @@ -248,11 +248,11 @@ def get_notebook_connection_info(cls):
try:
try:
import ipykernel as kernel
except:
except: # pylint: disable=bare-except
from IPython.lib import kernel
conn_info = kernel.get_connection_info(unpack=False)

except:
except: # pylint: disable=bare-except
pass

return conn_info
Expand All @@ -265,7 +265,7 @@ def transform_cell(cls, cell:str)->str:
ip = cls._get_ipython()
if ip is not None:
tr_cell = ip.input_transformer_manager.transform_cell(cell)
except:
except: # pylint: disable=bare-except
pass
return tr_cell

Expand All @@ -276,7 +276,7 @@ def is_in_input_transformers_cleanup(cls, transformer_func:Callable[[Iterable],
ip = cls._get_ipython()
if ip is not None:
return transformer_func in ip.input_transformers_cleanup
except:
except: # pylint: disable=bare-except
pass
return False

Expand All @@ -289,7 +289,7 @@ def try_add_input_transformers_cleanup(cls, transformer_func:Callable[[Iterable]
if ip is not None:
ip.input_transformers_cleanup.append(transformer_func)
return True
except:
except: # pylint: disable=bare-except
pass
return False

Expand All @@ -302,7 +302,7 @@ def try_remove_input_transformers_cleanup(cls, transformer_func:Callable[[Iterab
if cls.is_in_input_transformers_cleanup(transformer_func):
ip.input_transformers_cleanup.remove(transformer_func)
return True
except:
except: # pylint: disable=bare-except
pass
return False

Expand Down
2 changes: 1 addition & 1 deletion azure/Kqlmagic/kql_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def validate_database_name(self, **options)->None:
raise KqlEngineError("Database wasn't found in cluster.")
except NotImplementedError:
pass
except:
except: # pylint: disable=bare-except
raise

self.options["validate_database_name_done"] = True
Expand Down
21 changes: 13 additions & 8 deletions azure/Kqlmagic/kql_magic_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ def _init_options(self)->Dict[str,Any]:
#
# first we do auto detection
#
app = "auto"

app = self.default_options.notebook_app
if app == "auto": # ELECTRON_RUN_AS_NODE
notebook_service_address = self.default_options.notebook_service_address or ""
python_branch = platform.python_branch()
Expand Down Expand Up @@ -495,7 +496,11 @@ def get_app_from_parent(self)->Dict[str,str]:
return {"app": "visualstudiocode", "kernel_location": "local"}
elif item.endswith("vscode_datascience_helpers.jupyter_daemon"):
return {"app": "visualstudiocode", "kernel_location": "local"}
except:

for path in os.get_exec_path():
if path.find("nteract") > 0:
return {"app": "nteract", "kernel_location": "local"}
except: # pylint: disable=bare-except
pass

return {}
Expand All @@ -517,9 +522,9 @@ def get_notebook_host_from_running_processes(self)->str:
return item
elif item.startswith("http://") or found_item is None:
found_item = item
except:
except: # pylint: disable=bare-except
pass
except:
except: # pylint: disable=bare-except
pass

return found_item
Expand Down Expand Up @@ -625,7 +630,7 @@ def _show_magic_latest_version(self, **options)->None:
Display.showWarningMessage(
f"""You are using a {label} {Constants.MAGIC_PACKAGE_NAME} version {__version__}, You should condider to use stable version {pypi_stable_version}."""
)
except:
except: # pylint: disable=bare-except
logger().debug("Kqlmagic_core::_show_magic_latest_version - failed to fetch PyPi Kqlmagic latest version")
pass

Expand Down Expand Up @@ -661,7 +666,7 @@ def _show_what_new(self, options:Dict[str,Any])->None:
palette=Display.info_style,
**options
)
except:
except: # pylint: disable=bare-except
logger().debug("Kqlmagic_core::_show_what_new - failed to fetch HISTORY.md")
pass

Expand Down Expand Up @@ -1003,7 +1008,7 @@ def execute(self, line:str, cell:str=None, local_ns:Dict[str,Any]=None,
body_obj = result._repr_json_() if _repr_json_ is not None and callable(_repr_json_) else result
try:
body = json.dumps(body_obj, indent=4, sort_keys=True)
except:
except: # pylint: disable=bare-except
body = result
html_str = f"""<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -1399,7 +1404,7 @@ def _execute_query(self, parsed:Dict[str,Any], user_ns:Dict[str,Any], result_set
try:
parsed_error = json.loads(err.message)
message = f"query execution error:\n{json_dumps(parsed_error, indent=4, sort_keys=True)}"
except:
except: # pylint: disable=bare-except
message = err.message
Display.showDangerMessage(message)
return None
Expand Down
2 changes: 1 addition & 1 deletion azure/Kqlmagic/kql_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _is_valid_datetime(self, d:str)->bool:
d = dateutil.parser.isoparse(d) if type(d) == str else d
return isinstance(d, datetime) and abs((d - START_EPOCH_DATETIME).total_seconds()) < MAX_DIFF_FROM_EPOCH_IN_SECS

except:
except: # pylint: disable=bare-except
return False


Expand Down
2 changes: 1 addition & 1 deletion azure/Kqlmagic/kql_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _get_endpoint_version(self, json_response):
try:
tables_num = json_response["Tables"].__len__() # pylint: disable=W0612
return "v1"
except:
except: # pylint: disable=bare-except
return "v2"


Expand Down
Loading