qlever 0.5.15__py3-none-any.whl → 0.5.18__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of qlever might be problematic. Click here for more details.

qlever/commands/stop.py CHANGED
@@ -1,15 +1,40 @@
1
1
  from __future__ import annotations
2
-
3
2
  import re
4
-
5
3
  import psutil
6
-
7
4
  from qlever.command import QleverCommand
8
5
  from qlever.commands.status import StatusCommand
9
6
  from qlever.containerize import Containerize
10
7
  from qlever.log import log
11
8
  from qlever.util import show_process_info
12
9
 
10
+ # try to kill the given process, return true iff it was killed successfully.
11
+ # the process_info is used for logging.
12
+ def stop_process(proc, pinfo):
13
+ try:
14
+ proc.kill()
15
+ log.info(f"Killed process {pinfo['pid']}")
16
+ return True
17
+ except Exception as e:
18
+ log.error(f"Could not kill process with PID "
19
+ f"{pinfo['pid']} ({e}) ... try to kill it "
20
+ f"manually")
21
+ log.info("")
22
+ show_process_info(proc, "", show_heading=True)
23
+ return False
24
+
25
+
26
+ # try to stop and remove container. return True iff it was stopped
27
+ # successfully. Gives log info accordingly.
28
+ def stop_container(server_container):
29
+ for container_system in Containerize.supported_systems():
30
+ if Containerize.stop_and_remove_container(
31
+ container_system, server_container):
32
+ log.info(f"{container_system.capitalize()} container with "
33
+ f"name \"{server_container}\" stopped "
34
+ f" and removed")
35
+ return True
36
+ return False
37
+
13
38
 
14
39
  class StopCommand(QleverCommand):
15
40
  """
@@ -20,7 +45,7 @@ class StopCommand(QleverCommand):
20
45
  pass
21
46
 
22
47
  def description(self) -> str:
23
- return ("Stop QLever server for a given datasedataset or port")
48
+ return "Stop QLever server for a given datasedataset or port"
24
49
 
25
50
  def should_have_qleverfile(self) -> bool:
26
51
  return True
@@ -54,46 +79,34 @@ class StopCommand(QleverCommand):
54
79
  # First check if there is container running and if yes, stop and remove
55
80
  # it (unless the user has specified `--no-containers`).
56
81
  if not args.no_containers:
57
- for container_system in Containerize.supported_systems():
58
- if Containerize.stop_and_remove_container(
59
- container_system, args.server_container):
60
- log.info(f"{container_system.capitalize()} container with "
61
- f"name \"{args.server_container}\" stopped "
62
- f" and removed")
63
- return True
82
+ if stop_container(args.server_container):
83
+ return True
64
84
 
65
85
  # Check if there is a process running on the server port using psutil.
66
- #
67
86
  # NOTE: On MacOS, some of the proc's returned by psutil.process_iter()
68
87
  # no longer exist when we try to access them, so we just skip them.
88
+ stop_process_results = []
69
89
  for proc in psutil.process_iter():
70
90
  try:
71
91
  pinfo = proc.as_dict(
72
- attrs=['pid', 'username', 'create_time',
73
- 'memory_info', 'cmdline'])
92
+ attrs=['pid', 'username', 'create_time',
93
+ 'memory_info', 'cmdline'])
74
94
  cmdline = " ".join(pinfo['cmdline'])
75
95
  except Exception as e:
76
96
  log.debug(f"Error getting process info: {e}")
97
+ return False
77
98
  if re.search(cmdline_regex, cmdline):
78
99
  log.info(f"Found process {pinfo['pid']} from user "
79
100
  f"{pinfo['username']} with command line: {cmdline}")
80
101
  log.info("")
81
- try:
82
- proc.kill()
83
- log.info(f"Killed process {pinfo['pid']}")
84
- except Exception as e:
85
- log.error(f"Could not kill process with PID "
86
- f"{pinfo['pid']} ({e}) ... try to kill it "
87
- f"manually")
88
- log.info("")
89
- show_process_info(proc, "", show_heading=True)
90
- return False
91
- return True
102
+ stop_process_results.append(stop_process(proc, pinfo))
103
+ if len(stop_process_results) > 0:
104
+ return all(stop_process_results)
92
105
 
93
106
  # If no matching process found, show a message and the output of the
94
107
  # status command.
95
108
  message = "No matching process found" if args.no_containers else \
96
- "No matching process or container found"
109
+ "No matching process or container found"
97
110
  log.error(message)
98
111
  args.cmdline_regex = "^ServerMain.* -i [^ ]*"
99
112
  log.info("")
@@ -56,7 +56,9 @@ class SystemInfoCommand(QleverCommand):
56
56
 
57
57
  def execute(self, args) -> bool:
58
58
  # Say what the command is doing.
59
- self.show("Show system information and Qleverfile", only_show=args.show)
59
+ self.show(
60
+ "Show system information and Qleverfile", only_show=args.show
61
+ )
60
62
  if args.show:
61
63
  return True
62
64
 
@@ -80,13 +82,15 @@ class SystemInfoCommand(QleverCommand):
80
82
  memory_total = psutil.virtual_memory().total / (1024.0**3)
81
83
  memory_available = psutil.virtual_memory().available / (1024.0**3)
82
84
  log.info(
83
- f"RAM: {memory_total:.1f} GB total, " f"{memory_available:.1f} GB available"
85
+ f"RAM: {memory_total:.1f} GB total, "
86
+ f"{memory_available:.1f} GB available"
84
87
  )
85
88
  num_cores = psutil.cpu_count(logical=False)
86
89
  num_threads = psutil.cpu_count(logical=True)
87
90
  cpu_freq = psutil.cpu_freq().max / 1000
88
91
  log.info(
89
- f"CPU: {num_cores} Cores, " f"{num_threads} Threads @ {cpu_freq:.2f} GHz"
92
+ f"CPU: {num_cores} Cores, "
93
+ f"{num_threads} Threads @ {cpu_freq:.2f} GHz"
90
94
  )
91
95
 
92
96
  cwd = Path.cwd()
qlever/commands/ui.py CHANGED
@@ -27,7 +27,13 @@ class UiCommand(QleverCommand):
27
27
  return {
28
28
  "data": ["name"],
29
29
  "server": ["host_name", "port"],
30
- "ui": ["ui_port", "ui_config", "ui_system", "ui_image", "ui_container"],
30
+ "ui": [
31
+ "ui_port",
32
+ "ui_config",
33
+ "ui_system",
34
+ "ui_image",
35
+ "ui_container",
36
+ ],
31
37
  }
32
38
 
33
39
  def additional_arguments(self, subparser) -> None:
@@ -35,7 +41,9 @@ class UiCommand(QleverCommand):
35
41
 
36
42
  def execute(self, args) -> bool:
37
43
  # If QLEVER_OVERRIDE_DISABLE_UI is set, this command is disabled.
38
- qlever_is_running_in_container = environ.get("QLEVER_IS_RUNNING_IN_CONTAINER")
44
+ qlever_is_running_in_container = environ.get(
45
+ "QLEVER_IS_RUNNING_IN_CONTAINER"
46
+ )
39
47
  if qlever_is_running_in_container:
40
48
  log.error(
41
49
  "The environment variable `QLEVER_OVERRIDE_DISABLE_UI` is set, "
@@ -67,7 +75,9 @@ class UiCommand(QleverCommand):
67
75
  f'{args.ui_config} {server_url}"'
68
76
  )
69
77
  self.show(
70
- "\n".join(["Stop running containers", pull_cmd, run_cmd, exec_cmd]),
78
+ "\n".join(
79
+ ["Stop running containers", pull_cmd, run_cmd, exec_cmd]
80
+ ),
71
81
  only_show=args.show,
72
82
  )
73
83
  if qlever_is_running_in_container:
@@ -77,7 +87,9 @@ class UiCommand(QleverCommand):
77
87
 
78
88
  # Stop running containers.
79
89
  for container_system in Containerize.supported_systems():
80
- Containerize.stop_and_remove_container(container_system, args.ui_container)
90
+ Containerize.stop_and_remove_container(
91
+ container_system, args.ui_container
92
+ )
81
93
 
82
94
  # Check if the UI port is already being used.
83
95
  if is_port_used(args.ui_port):
qlever/log.py CHANGED
@@ -10,6 +10,7 @@ class QleverLogFormatter(logging.Formatter):
10
10
  """
11
11
  Custom formatter for logging.
12
12
  """
13
+
13
14
  def format(self, record):
14
15
  message = record.getMessage()
15
16
  if record.levelno == logging.DEBUG:
@@ -34,7 +35,7 @@ log_levels = {
34
35
  "WARNING": logging.WARNING,
35
36
  "ERROR": logging.ERROR,
36
37
  "CRITICAL": logging.CRITICAL,
37
- "NO_LOG": logging.CRITICAL + 1
38
+ "NO_LOG": logging.CRITICAL + 1,
38
39
  }
39
40
 
40
41