Skip to content

Commit

Permalink
Update the settings for the preferred reporting system
Browse files Browse the repository at this point in the history
  • Loading branch information
vladpunko committed Oct 9, 2023
1 parent 44960de commit 0e21ca1
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .githooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
repos:
# Set the list of basic git hooks to find and fix common problems in the current working tree.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: f71fa2c1f9cf5cb705f73dffe4b21f7c61470ba9
hooks:
- id: check-executables-have-shebangs
- id: check-yaml
Expand All @@ -12,7 +12,7 @@ repos:

# Use the static code checker to find and fix logical errors in python source code.
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
rev: b9a7794c4f425ef8419081e6993f99419cc667ea
hooks:
- id: flake8
language_version: python3
Empty file added .github/.gitkeep
Empty file.
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
*
*.egg
*.egg-info
*.log
*.py[cod]
*.xml
.*

__pycache__/
build/
dist/
docs/_build
downloads/
eggs/
htmlcov/
lib/
lib64/
parts/
sdist/
var/
wheels/
Empty file added .gitkeep
Empty file.
Binary file modified notebook_environments.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 13 additions & 42 deletions notebook_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import shutil
import subprocess
import sys
import tempfile
import warnings

try:
Expand Down Expand Up @@ -106,39 +105,9 @@
# Create a structure to store information about the location of a kernel on the current machine.
_kernel_info = collections.namedtuple(typename="kernel_info", field_names=("name", "path"))

LOGGING_CONFIG = {
"formatters": {
"default": {
"format": "%(asctime)s - %(levelname)s :: %(name)s :: %(message)s",
# Use this string to format the creation time of the record.
"datefmt": "%Y-%m-%d--%H-%M-%S",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "default",
"stream": "ext://sys.stdout",
},
"logfile": {
"class": "logging.FileHandler",
"encoding": "utf-8",
"filename": os.path.join(tempfile.gettempdir(), "notebook-environments.log"),
"formatter": "default",
"mode": "at",
},
},
"loggers": {
"notebook-environments": {
"handlers": ["console", "logfile"],
},
},
# Set the preferred schema version.
"version": 1,
}
logging.config.dictConfig(config=LOGGING_CONFIG)
logging.basicConfig(format="%(levelname)s :: %(name)s :: %(message)s")
# Create a new instance of the preferred reporting system for this program.
_logger = logging.getLogger("notebook-environments")
_logger = logging.getLogger("notebook_environments")


__all__ = (
Expand All @@ -149,14 +118,15 @@
"show_kernels",
)

__version__ = "0.8.12"
__version__ = "0.8.13"


def _in_virtual_environment():
is_using_venv = (
# Take into consideration user's virtual environments based on standard python packages.
# See information: https://www.python.org/dev/peps/pep-0405
hasattr(sys, "real_prefix") or getattr(sys, "base_prefix", sys.prefix) != sys.prefix
hasattr(sys, "real_prefix")
or getattr(sys, "base_prefix", sys.prefix) != sys.prefix
) # pep 405

# Check a virtual environment of the working python interpreter at this program runtime.
Expand All @@ -167,7 +137,6 @@ def _get_data_path(*subdirs):
paths_spec = {
# Set the main path to store notebook server settings on mac operating systems.
"darwin": os.path.join(os.path.expanduser("~/Library/Jupyter"), *subdirs),

# Set the main path to store notebook server settings on unix operating systems.
"linux": os.path.join(os.path.expanduser("~/.local/share/jupyter"), *subdirs),
}
Expand Down Expand Up @@ -244,11 +213,13 @@ def _provide_required_packages():
stderr=sys.stderr, # use this system stream to show all package errors
)
except subprocess.CalledProcessError as err:
_logger.error((
"It's impossible to install packages on the current machine.\n"
"You are to update setup tools and run the installation process another time.\n"
"python -m pip install --upgrade pip setuptools wheel"
))
_logger.error(
(
"It's impossible to install packages on the current machine.\n"
"You are to update setup tools and run the installation process another time.\n"
"python -m pip install --upgrade pip setuptools wheel"
)
)
_logger.debug("An unexpected error occurred at this program runtime:", exc_info=True)
# Stop this program runtime and return the exit status code.
sys.exit(getattr(err, "errno", errno.EPERM))
Expand Down Expand Up @@ -369,6 +340,7 @@ def initialize_new_notebook_environment():

from jupyter_core.paths import jupyter_path # noqa
except ImportError:

def jupyter_path(subdirs): # this function is to return a list
return [_get_data_path(subdirs)]

Expand All @@ -394,7 +366,6 @@ def show_kernels():


def main(): # pragma: no cover

# Create a new instance of the preferred argument parser.
parser = argparse.ArgumentParser(
description="Manage python virtual environments on the working notebook server."
Expand Down
44 changes: 22 additions & 22 deletions notebook_environments_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


class SysMock(object):

def __init__(self):
self.base_prefix = "/usr/bin"

Expand All @@ -52,7 +51,6 @@ def deactivate(self):

@mock.patch("notebook_environments.sys", new_callable=SysMock)
class NotebookEnvironmentsTest(TestCase):

data_path = "/root/kernels"

# Set the list of fake python kernels.
Expand Down Expand Up @@ -166,26 +164,28 @@ def test_get_kernel_name(self, sys_mock):
def test_get_kernel_name_error(self, logger_mock, basename_mock, sys_mock):
sys_mock.deactivate()

for invalid_character in sorted((
":",
"?",
"[",
"]",
"{",
"}",
"@",
"&",
"#",
"%",
"^",
"+",
"<",
"=",
">",
"|",
"~",
"$",
)):
for invalid_character in sorted(
(
":",
"?",
"[",
"]",
"{",
"}",
"@",
"&",
"#",
"%",
"^",
"+",
"<",
"=",
">",
"|",
"~",
"$",
)
):
basename_mock.return_value = "test{0}test".format(invalid_character)

with self.assertRaises(SystemExit) as system_exit:
Expand Down

0 comments on commit 0e21ca1

Please sign in to comment.