Skip to content
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
12 changes: 3 additions & 9 deletions src/qlever/commands/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
binary_exists,
get_existing_index_files,
get_total_file_size,
input_files_exist,
run_command,
)

Expand Down Expand Up @@ -282,15 +283,8 @@ def execute(self, args) -> bool:
return False

# Check if all of the input files exist.
for pattern in shlex.split(args.input_files):
if len(glob.glob(pattern)) == 0:
log.error(f'No file matching "{pattern}" found')
log.info("")
log.info(
"Did you call `qlever get-data`? If you did, check "
"GET_DATA_CMD and INPUT_FILES in the QLeverfile"
)
return False
if not input_files_exist(args.input_files):
return False

# Check if index files (name.index.*) already exist.
existing_index_files = get_existing_index_files(args.name)
Expand Down
4 changes: 2 additions & 2 deletions src/qlever/commands/index_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def execute(self, args) -> bool:
# missing timestamps (duration is None).
for heading, (duration, time_unit) in durations.items():
if duration is not None:
if heading == "TOTAL time":
if heading == "TOTAL time" and len(durations) != 1:
log.info("")
log.info(
f"{heading:<25} : {duration:>6.1f} {time_unit}"
Expand All @@ -400,7 +400,7 @@ def execute(self, args) -> bool:
sizes = self.execute_space(args)
# Display the disk space used by each group of index files.
for heading, (size, size_unit) in sizes.items():
if heading == "TOTAL size":
if heading == "TOTAL size" and len(sizes) != 1:
log.info("")
if size_unit == "B":
log.info(f"{heading:<25} : {size:,} {size_unit}")
Expand Down
74 changes: 52 additions & 22 deletions src/qlever/commands/setup_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from os import environ
from pathlib import Path

import qlever.util as util
from qlever.command import QleverCommand
from qlever.log import log
from qlever.util import get_random_string


class SetupConfigCommand(QleverCommand):
Expand All @@ -15,9 +15,19 @@ class SetupConfigCommand(QleverCommand):
"""

def __init__(self):
self.qleverfiles_path = Path(__file__).parent.parent / "Qleverfiles"
self.qleverfiles_path = (
Path(__file__).parent.parent.parent / "qlever/Qleverfiles"
)
self.qleverfile_names = [
p.name.split(".")[1] for p in self.qleverfiles_path.glob("Qleverfile.*")
p.name.split(".")[1]
for p in self.qleverfiles_path.glob("Qleverfile.*")
]
# Arguments that can be overridden when generating a Qleverfile,
# as (section, arg_name) pairs.
self.override_args = [
("server", "port"),
("server", "timeout"),
("runtime", "system"),
]

def description(self) -> str:
Expand All @@ -27,7 +37,10 @@ def should_have_qleverfile(self) -> bool:
return False

def relevant_qleverfile_arguments(self) -> dict[str, list[str]]:
return {}
result = {}
for section, arg_name in self.override_args:
result.setdefault(section, []).append(arg_name)
return result

def additional_arguments(self, subparser) -> None:
subparser.add_argument(
Expand All @@ -37,9 +50,24 @@ def additional_arguments(self, subparser) -> None:
help="The name of the pre-configured Qleverfile to create",
)

def check_qleverfile_exists(self) -> bool:
"""Return True if a Qleverfile already exists (and log an error)."""
if Path("Qleverfile").exists():
log.error("`Qleverfile` already exists in current directory")
log.info("")
log.info(
"If you want to create a new Qleverfile using "
"`qlever setup-config`, delete the existing Qleverfile "
"first"
)
return True
return False

def execute(self, args) -> bool:
# Show a warning if `QLEVER_OVERRIDE_SYSTEM_NATIVE` is set.
qlever_is_running_in_container = environ.get("QLEVER_IS_RUNNING_IN_CONTAINER")
qlever_is_running_in_container = environ.get(
"QLEVER_IS_RUNNING_IN_CONTAINER"
)
if qlever_is_running_in_container:
log.warning(
"The environment variable `QLEVER_IS_RUNNING_IN_CONTAINER` is set, "
Expand All @@ -48,30 +76,33 @@ def execute(self, args) -> bool:
)
log.info("")
# Construct the command line and show it.
qleverfile_path = self.qleverfiles_path / f"Qleverfile.{args.config_name}"
setup_config_cmd = (
f"cat {qleverfile_path}"
f" | sed -E 's/(^ACCESS_TOKEN.*)/\\1_{get_random_string(12)}/'"
qleverfile_path = (
self.qleverfiles_path / f"Qleverfile.{args.config_name}"
)
setup_config_cmd = f"cat {qleverfile_path} | {
util.get_ini_sed_cmd(
'server', 'ACCESS_TOKEN', util.get_random_string(12), True
)
}"
if qlever_is_running_in_container:
setup_config_cmd += (
" | sed -E 's/(^SYSTEM[[:space:]]*=[[:space:]]*).*/\\1native/'"
f" | {util.get_ini_sed_cmd('runtime', 'SYSTEM', 'native')}"
)
else:
for section, arg_name in self.override_args:
if arg_value := getattr(args, arg_name, None):
setup_config_cmd += f" | {
util.get_ini_sed_cmd(
section, arg_name.upper(), arg_value
)
}"

setup_config_cmd += "> Qleverfile"
self.show(setup_config_cmd, only_show=args.show)
if args.show:
return True

# If there is already a Qleverfile in the current directory, exit.
qleverfile_path = Path("Qleverfile")
if qleverfile_path.exists():
log.error("`Qleverfile` already exists in current directory")
log.info("")
log.info(
"If you want to create a new Qleverfile using "
"`qlever setup-config`, delete the existing Qleverfile "
"first"
)
if self.check_qleverfile_exists():
return False

# Copy the Qleverfile to the current directory.
Expand All @@ -85,11 +116,10 @@ def execute(self, args) -> bool:
)
except Exception as e:
log.error(
f'Could not copy "{qleverfile_path}"' f" to current directory: {e}"
f'Could not copy "{qleverfile_path}" to current directory: {e}'
)
return False

# If we get here, everything went well.
log.info(
f'Created Qleverfile for config "{args.config_name}"'
f" in current directory"
Expand Down
4 changes: 4 additions & 0 deletions src/qlever/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def argument_error(prefix):
f"`{section}` not found")
args, kwargs = all_qleverfile_args[section][arg_name]
kwargs_copy = kwargs.copy()
action_type = kwargs_copy.get("action", "store")
if action_type == "store" and "metavar" not in kwargs_copy:
metavar = arg_name.upper()
kwargs_copy["metavar"] = f"(in Qleverfile: [{section}] {metavar})"
# If `qleverfile_config` is given, add info about default
# values to the help string.
if qleverfile_config is not None:
Expand Down
9 changes: 9 additions & 0 deletions src/qlever/qleverfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import socket
import subprocess
from configparser import ConfigParser, ExtendedInterpolation, RawConfigParser
from importlib import import_module
from pathlib import Path

from qlever import script_name
Expand Down Expand Up @@ -415,6 +416,14 @@ def arg(*args, **kwargs):
help="The name of the container used for `qlever ui`",
)

engine_args_module_path = f"{script_name}.qleverfile"
try:
if script_name != "qlever":
module = import_module(engine_args_module_path)
module.qleverfile_args(all_args)
except (ImportError, AttributeError) as e:
log.debug(f"Could not import module {engine_args_module_path}: {e}")

return all_args

@staticmethod
Expand Down
Loading
Loading