gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _push_pull_grad_async(self, p):
    """Call byteps API to push-pull gradient asynchronously
    Arguments:
        tensor: The tensor to push-pull.
        name: The name of the tensor.
    Returns:
        an push-pull handle and context
    """
    name = self._parameter_names.get(p)
    tensor = p.grad
    tensor_compressed, ctx = self._compression.compress(tensor)

    self._locks[p].acquire()
    handle = byteps_push_pull(tensor_compressed, average=True, name="Gradient." + name)
    self._logger.debug(
        "{} calls byteps_push_pull for {}".format(self._desc, self._parameter_names[p])
    )
    # Add to queue to poll completion
    self._event_queue.put((p, handle, ctx))
    return handle, ctx


# Traceback (RuntimeError)
Traceback (most recent call last):
File "/usr/local/byteps/example/pytorch/benchmark_bytescheduler.py", line 134, in <module>
timeit.timeit(benchmark_step, number=args.num_warmup_batches)
File "/opt/anaconda/lib/python3.7/timeit.py", line 232, in timeit
return Timer(stmt, setup, timer, globals).timeit(number)
File "/opt/anaconda/lib/python3.7/timeit.py", line 176, in timeit
timing = self.inner(it, self.timer)
File "<timeit-src>", line 6, in inner
File "/usr/local/byteps/example/pytorch/benchmark_bytescheduler.py", line 115, in benchmark_step
output = model(data)
File "/opt/anaconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in __call__
result = self.forward(*input, **kwargs)
File "/opt/anaconda/lib/python3.7/site-packages/torchvision/models/resnet.py", line 196, in forward
x = self.conv1(x)
File "/opt/anaconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 533, in __call__
result = hook(self, input)
File "/opt/anaconda/lib/python3.7/site-packages/byteps-0.1.0-py3.7-linux-x86_64.egg/byteps/bytescheduler/torch/optimizer.py", line 206, in pre_forward_hook
self._logger.debug("{} {} is ready.".format(self._desc, self._parameter_names[p]))
RuntimeError: bool value of Tensor with more than one value is ambiguous

# Fixed code
def _push_pull_grad_async(self, p):
    """Call byteps API to push-pull gradient asynchronously
    Arguments:
        tensor: The tensor to push-pull.
        name: The name of the tensor.
    Returns:
        an push-pull handle and context
    """
    name = self._parameter_names.get(id(p))
    tensor = p.grad
    tensor_compressed, ctx = self._compression.compress(tensor)

    self._locks[p].acquire()
    handle = byteps_push_pull(tensor_compressed, average=True, name="Gradient." + name)
    self._logger.debug(
        "{} calls byteps_push_pull for {}".format(
            self._desc, self._parameter_names[id(p)]
        )
    )
    # Add to queue to poll completion
    self._event_queue.put((p, handle, ctx))
    return handle, ctx
# Buggy code
def pre_forward_hook(mod, input):
    for p in mod.parameters():
        if p in self._handles:
            del self._handles[p]
        if p not in self._locks:
            continue
        with self._locks[p]:
            self._logger.debug(
                "{} {} is ready.".format(self._desc, self._parameter_names[p])
            )

    self._logger.debug("{} starts forward {}.".format(self._desc, mod))


# Traceback (RuntimeError)
Traceback (most recent call last):
File "/usr/local/byteps/example/pytorch/benchmark_bytescheduler.py", line 134, in <module>
timeit.timeit(benchmark_step, number=args.num_warmup_batches)
File "/opt/anaconda/lib/python3.7/timeit.py", line 232, in timeit
return Timer(stmt, setup, timer, globals).timeit(number)
File "/opt/anaconda/lib/python3.7/timeit.py", line 176, in timeit
timing = self.inner(it, self.timer)
File "<timeit-src>", line 6, in inner
File "/usr/local/byteps/example/pytorch/benchmark_bytescheduler.py", line 115, in benchmark_step
output = model(data)
File "/opt/anaconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in __call__
result = self.forward(*input, **kwargs)
File "/opt/anaconda/lib/python3.7/site-packages/torchvision/models/resnet.py", line 196, in forward
x = self.conv1(x)
File "/opt/anaconda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 533, in __call__
result = hook(self, input)
File "/opt/anaconda/lib/python3.7/site-packages/byteps-0.1.0-py3.7-linux-x86_64.egg/byteps/bytescheduler/torch/optimizer.py", line 206, in pre_forward_hook
self._logger.debug("{} {} is ready.".format(self._desc, self._parameter_names[p]))
RuntimeError: bool value of Tensor with more than one value is ambiguous

# Fixed code
def pre_forward_hook(mod, input):
    for p in mod.parameters():
        if p in self._handles:
            del self._handles[p]
        if p not in self._locks:
            continue
        with self._locks[p]:
            self._logger.debug(
                "{} {} is ready.".format(self._desc, self._parameter_names[id(p)])
            )

    self._logger.debug("{} starts forward {}.".format(self._desc, mod))
# Buggy code
def read_journal(journal_name="default"):
    config = load_config(install.CONFIG_FILE_PATH)
    with open(config["journals"][journal_name]) as journal_file:
        journal = journal_file.read()
    return journal


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def read_journal(context, journal_name="default"):
    configuration = load_config(context.config_path)
    with open(configuration["journals"][journal_name]) as journal_file:
        journal = journal_file.read()
    return journal
# Buggy code
def open_journal(journal_name="default"):
    config = load_config(install.CONFIG_FILE_PATH)
    journal_conf = config["journals"][journal_name]

    # We can override the default config on a by-journal basis
    if type(journal_conf) is dict:
        config.update(journal_conf)
    # But also just give them a string to point to the journal file
    else:
        config["journal"] = journal_conf

    return Journal.open_journal(journal_name, config)


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def open_journal(context, journal_name="default"):
    configuration = load_config(context.config_path)
    journal_conf = configuration["journals"][journal_name]

    # We can override the default config on a by-journal basis
    if type(journal_conf) is dict:
        configuration.update(journal_conf)
    # But also just give them a string to point to the journal file
    else:
        configuration["journal"] = journal_conf

    return Journal.open_journal(journal_name, configuration)
# Buggy code
def set_config(context, config_file):
    full_path = os.path.join("features/configs", config_file)

    install.CONFIG_FILE_PATH = os.path.abspath(full_path)
    if config_file.endswith("yaml") and os.path.exists(full_path):
        # Add jrnl version to file for 2.x journals
        with open(install.CONFIG_FILE_PATH, "a") as cf:
            cf.write("version: {}".format(__version__))


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def set_config(context, config_file):
    full_path = os.path.join("features/configs", config_file)

    context.config_path = os.path.abspath(full_path)

    if config_file.endswith("yaml") and os.path.exists(full_path):
        # Add jrnl version to file for 2.x journals
        with open(context.config_path, "a") as cf:
            cf.write("version: {}".format(__version__))
# Buggy code
def open_editor_and_enter(context, method, text=""):
    text = text or context.text or ""

    if method == "enter":
        file_method = "w+"
    elif method == "append":
        file_method = "a"
    else:
        file_method = "r+"

    def _mock_editor(command):
        context.editor_command = command
        tmpfile = command[-1]
        with open(tmpfile, file_method) as f:
            f.write(text)

        return tmpfile

    if "password" in context:
        password = context.password
    else:
        password = ""

    # fmt: off
    # see: https://github.com/psf/black/issues/664
    with \
        patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \
        patch("getpass.getpass", side_effect=_mock_getpass(password)) as mock_getpass, \
        patch("sys.stdin.isatty", return_value=True) \
    :
        context.editor = mock_editor
        context.getpass = mock_getpass
        cli(["--edit"])


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def open_editor_and_enter(context, method, text=""):
    text = text or context.text or ""

    if method == "enter":
        file_method = "w+"
    elif method == "append":
        file_method = "a"
    else:
        file_method = "r+"

    def _mock_editor(command):
        context.editor_command = command
        tmpfile = command[-1]
        with open(tmpfile, file_method) as f:
            f.write(text)

        return tmpfile

    if "password" in context:
        password = context.password
    else:
        password = ""

    # fmt: off
    # see: https://github.com/psf/black/issues/664
    with \
        patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \
        patch("getpass.getpass", side_effect=_mock_getpass(password)) as mock_getpass, \
        patch("sys.stdin.isatty", return_value=True), \
        patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \
        patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \
    :
        context.editor = mock_editor
        context.getpass = mock_getpass
        try:
            cli(["--edit"])
            context.exit_status = 0
        except SystemExit as e:
            context.exit_status = e.code
# Buggy code
def check_journal_content(context, text, journal_name="default"):
    journal = read_journal(journal_name)
    assert text in journal, journal


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def check_journal_content(context, text, journal_name="default"):
    journal = read_journal(context, journal_name)
    assert text in journal, journal
# Buggy code
def check_not_journal_content(context, text, journal_name="default"):
    journal = read_journal(journal_name)
    assert text not in journal, journal


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def check_not_journal_content(context, text, journal_name="default"):
    journal = read_journal(context, journal_name)
    assert text not in journal, journal
# Buggy code
def journal_doesnt_exist(context, journal_name="default"):
    config = load_config(install.CONFIG_FILE_PATH)

    journal_path = config["journals"][journal_name]
    assert not os.path.exists(journal_path)


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def journal_doesnt_exist(context, journal_name="default"):
    configuration = load_config(context.config_path)

    journal_path = configuration["journals"][journal_name]
    assert not os.path.exists(journal_path)
# Buggy code
def journal_exists(context, journal_name="default"):
    config = load_config(install.CONFIG_FILE_PATH)

    journal_path = config["journals"][journal_name]
    assert os.path.exists(journal_path)


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def journal_exists(context, journal_name="default"):
    configuration = load_config(context.config_path)

    journal_path = configuration["journals"][journal_name]
    assert os.path.exists(journal_path)
# Buggy code
def config_var(context, key, value="", journal=None):
    value = read_value_from_string(value or context.text or "")
    config = load_config(install.CONFIG_FILE_PATH)

    if journal:
        config = config["journals"][journal]

    assert key in config
    assert config[key] == value


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def config_var(context, key, value="", journal=None):
    value = read_value_from_string(value or context.text or "")
    configuration = load_config(context.config_path)

    if journal:
        configuration = configuration["journals"][journal]

    assert key in configuration
    assert configuration[key] == value
# Buggy code
def config_no_var(context, key, value="", journal=None):
    config = load_config(install.CONFIG_FILE_PATH)

    if journal:
        config = config["journals"][journal]

    assert key not in config


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def config_no_var(context, key, value="", journal=None):
    configuration = load_config(context.config_path)

    if journal:
        configuration = configuration["journals"][journal]

    assert key not in configuration
# Buggy code
def check_journal_entries(context, number, journal_name="default"):
    journal = open_journal(journal_name)
    assert len(journal.entries) == number


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def check_journal_entries(context, number, journal_name="default"):
    journal = open_journal(context, journal_name)
    assert len(journal.entries) == number
# Buggy code
def list_journal_directory(context, journal="default"):
    with open(install.CONFIG_FILE_PATH) as config_file:
        config = yaml.load(config_file, Loader=yaml.FullLoader)
    journal_path = config["journals"][journal]
    for root, dirnames, f in os.walk(journal_path):
        for file in f:
            print(os.path.join(root, file))


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def list_journal_directory(context, journal="default"):
    with open(context.config_path) as config_file:
        configuration = yaml.load(config_file, Loader=yaml.FullLoader)
    journal_path = configuration["journals"][journal]
    for root, dirnames, f in os.walk(journal_path):
        for file in f:
            print(os.path.join(root, file))
# Buggy code
def cli(manual_args=None):
    try:
        if manual_args is None:
            manual_args = sys.argv[1:]

        args = parse_args(manual_args)
        configure_logger(args.debug)
        logging.debug("Parsed args: %s", args)

        return run(args)

    except KeyboardInterrupt:
        return 1


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def cli(manual_args=None):
    try:
        if manual_args is None:
            manual_args = sys.argv[1:]

        args = parse_args(manual_args)
        configure_logger(args.debug)
        logging.debug("Parsed args: %s", args)

        return run(args)

    except JrnlError as e:
        print(e.message, file=sys.stderr)
        return 1

    except KeyboardInterrupt:
        return 1
# Buggy code
def get_journal_name(args, config):
    from . import install

    args.journal_name = install.DEFAULT_JOURNAL_KEY
    if args.text and args.text[0] in config["journals"]:
        args.journal_name = args.text[0]
        args.text = args.text[1:]
    elif install.DEFAULT_JOURNAL_KEY not in config["journals"]:
        print("No default journal configured.", file=sys.stderr)
        print(list_journals(config), file=sys.stderr)
        sys.exit(1)

    logging.debug("Using journal name: %s", args.journal_name)
    return args


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def get_journal_name(args, config):
    args.journal_name = DEFAULT_JOURNAL_KEY
    if args.text and args.text[0] in config["journals"]:
        args.journal_name = args.text[0]
        args.text = args.text[1:]
    elif DEFAULT_JOURNAL_KEY not in config["journals"]:
        print("No default journal configured.", file=sys.stderr)
        print(list_journals(config), file=sys.stderr)
        sys.exit(1)

    logging.debug("Using journal name: %s", args.journal_name)
    return args
# Buggy code
def upgrade_config(config):
    """Checks if there are keys missing in a given config dict, and if so, updates the config file accordingly.
    This essentially automatically ports jrnl installations if new config parameters are introduced in later
    versions."""
    missing_keys = set(default_config).difference(config)
    if missing_keys:
        for key in missing_keys:
            config[key] = default_config[key]
        save_config(config)
        print(
            f"[Configuration updated to newest version at {CONFIG_FILE_PATH}]",
            file=sys.stderr,
        )


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def upgrade_config(config):
    """Checks if there are keys missing in a given config dict, and if so, updates the config file accordingly.
    This essentially automatically ports jrnl installations if new config parameters are introduced in later
    versions."""
    default_config = get_default_config()
    missing_keys = set(default_config).difference(config)
    if missing_keys:
        for key in missing_keys:
            config[key] = default_config[key]
        save_config(config)
        print(
            f"[Configuration updated to newest version at {get_config_path()}]",
            file=sys.stderr,
        )
# Buggy code
def install():
    _initialize_autocomplete()

    # Where to create the journal?
    path_query = f"Path to your journal file (leave blank for {JOURNAL_FILE_PATH}): "
    journal_path = os.path.abspath(input(path_query).strip() or JOURNAL_FILE_PATH)
    default_config["journals"][DEFAULT_JOURNAL_KEY] = os.path.expanduser(
        os.path.expandvars(journal_path)
    )

    # If the folder doesn't exist, create it
    path = os.path.split(default_config["journals"][DEFAULT_JOURNAL_KEY])[0]
    try:
        os.makedirs(path)
    except OSError:
        pass

    # Encrypt it?
    encrypt = yesno(
        "Do you want to encrypt your journal? You can always change this later",
        default=False,
    )
    if encrypt:
        default_config["encrypt"] = True
        print("Journal will be encrypted.", file=sys.stderr)

    save_config(default_config)
    return default_config


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def install():
    _initialize_autocomplete()

    # Where to create the journal?
    default_journal_path = get_default_journal_path()
    path_query = f"Path to your journal file (leave blank for {default_journal_path}): "
    journal_path = os.path.abspath(input(path_query).strip() or default_journal_path)
    default_config = get_default_config()
    default_config["journals"][DEFAULT_JOURNAL_KEY] = os.path.expanduser(
        os.path.expandvars(journal_path)
    )

    # If the folder doesn't exist, create it
    path = os.path.split(default_config["journals"][DEFAULT_JOURNAL_KEY])[0]
    try:
        os.makedirs(path)
    except OSError:
        pass

    # Encrypt it?
    encrypt = yesno(
        "Do you want to encrypt your journal? You can always change this later",
        default=False,
    )
    if encrypt:
        default_config["encrypt"] = True
        print("Journal will be encrypted.", file=sys.stderr)

    save_config(default_config)
    return default_config
# Buggy code
def _edit_search_results(config, journal, old_entries, **kwargs):
    """
    1. Send the given journal entries to the user-configured editor
    2. Print out stats on any modifications to journal
    3. Write modifications to journal
    """
    if not config["editor"]:
        print(
            f"""
            [{ERROR_COLOR}ERROR{RESET_COLOR}: There is no editor configured.]

            Please specify an editor in config file ({install.CONFIG_FILE_PATH})
            to use the --edit option.
            """,
            file=sys.stderr,
        )
        sys.exit(1)

    # separate entries we are not editing
    other_entries = [e for e in old_entries if e not in journal.entries]

    # Get stats now for summary later
    old_stats = _get_predit_stats(journal)

    # Send user to the editor
    edited = get_text_from_editor(config, journal.editable_str())
    journal.parse_editable_str(edited)

    # Print summary if available
    _print_edited_summary(journal, old_stats)

    # Put back entries we separated earlier, sort, and write the journal
    journal.entries += other_entries
    journal.sort()
    journal.write()


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def _edit_search_results(config, journal, old_entries, **kwargs):
    """
    1. Send the given journal entries to the user-configured editor
    2. Print out stats on any modifications to journal
    3. Write modifications to journal
    """
    if not config["editor"]:
        print(
            f"""
            [{ERROR_COLOR}ERROR{RESET_COLOR}: There is no editor configured.]

            Please specify an editor in config file ({get_config_path()})
            to use the --edit option.
            """,
            file=sys.stderr,
        )
        sys.exit(1)

    # separate entries we are not editing
    other_entries = [e for e in old_entries if e not in journal.entries]

    # Get stats now for summary later
    old_stats = _get_predit_stats(journal)

    # Send user to the editor
    edited = get_text_from_editor(config, journal.editable_str())
    journal.parse_editable_str(edited)

    # Print summary if available
    _print_edited_summary(journal, old_stats)

    # Put back entries we separated earlier, sort, and write the journal
    journal.entries += other_entries
    journal.sort()
    journal.write()
# Buggy code
def list_journals(config):
    from . import install

    """List the journals specified in the configuration file"""
    result = f"Journals defined in {install.CONFIG_FILE_PATH}\n"
    ml = min(max(len(k) for k in config["journals"]), 20)
    for journal, cfg in config["journals"].items():
        result += " * {:{}} -> {}\n".format(
            journal, ml, cfg["journal"] if isinstance(cfg, dict) else cfg
        )
    return result


# Traceback (FileExistsError)
Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 6, in <module>
from jrnl.cli import run
File "/usr/local/lib/python3.7/site-packages/jrnl/cli.py", line 14, in <module>
from . import install
File "/usr/local/lib/python3.7/site-packages/jrnl/install.py", line 25, in <module>
CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
File "/usr/local/lib/python3.7/site-packages/xdg/BaseDirectory.py", line 58, in save_config_path
os.makedirs(path, 0o700)
File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/Users/jonathanwren/.config/jrnl'

# Fixed code
def list_journals(configuration):
    from . import config

    """List the journals specified in the configuration file"""
    result = f"Journals defined in {config.get_config_path()}\n"
    ml = min(max(len(k) for k in configuration["journals"]), 20)
    for journal, cfg in configuration["journals"].items():
        result += " * {:{}} -> {}\n".format(
            journal, ml, cfg["journal"] if isinstance(cfg, dict) else cfg
        )
    return result
# Buggy code
def set_password(self, servicename, username, password):
    self.keys[servicename][username] = password


# Traceback (keyring.errors.KeyringLocked)
$ jrnl -from yesterday

WARNING: Python versions below 3.7 will no longer be supported as of jrnl v2.5
(the next release). You are currently on Python 3.6.9. Please update to
Python 3.7 (or higher) soon.

Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.6/dist-packages/jrnl/cli.py", line 387, in run
journal = open_journal(journal_name, config)
File "/usr/local/lib/python3.6/dist-packages/jrnl/Journal.py", line 405, in open_journal
return EncryptedJournal.EncryptedJournal(name, **config).open()
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 55, in open
text = self._load(filename)
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 82, in _load
return util.decrypt_content(keychain=self.name, decrypt_func=decrypt_journal)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 70, in decrypt_content
pwd_from_keychain = keychain and get_keychain(keychain)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 93, in get_keychain
return keyring.get_password("jrnl", journal_name)
File "/usr/local/lib/python3.6/dist-packages/keyring/core.py", line 56, in get_password
return _keyring_backend.get_password(service_name, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/chainer.py", line 51, in get_password
password = keyring.get_password(service, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 75, in get_password
collection = self.get_preferred_collection()
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 63, in get_preferred_collection
raise KeyringLocked("Failed to unlock the collection!")
keyring.errors.KeyringLocked: Failed to unlock the collection!

# Fixed code
def set_password(self, servicename, username, password):
    raise keyring.errors.KeyringError
# Buggy code
def get_password(self, servicename, username):
    raise keyring.errors.NoKeyringError


# Traceback (keyring.errors.KeyringLocked)
$ jrnl -from yesterday

WARNING: Python versions below 3.7 will no longer be supported as of jrnl v2.5
(the next release). You are currently on Python 3.6.9. Please update to
Python 3.7 (or higher) soon.

Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.6/dist-packages/jrnl/cli.py", line 387, in run
journal = open_journal(journal_name, config)
File "/usr/local/lib/python3.6/dist-packages/jrnl/Journal.py", line 405, in open_journal
return EncryptedJournal.EncryptedJournal(name, **config).open()
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 55, in open
text = self._load(filename)
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 82, in _load
return util.decrypt_content(keychain=self.name, decrypt_func=decrypt_journal)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 70, in decrypt_content
pwd_from_keychain = keychain and get_keychain(keychain)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 93, in get_keychain
return keyring.get_password("jrnl", journal_name)
File "/usr/local/lib/python3.6/dist-packages/keyring/core.py", line 56, in get_password
return _keyring_backend.get_password(service_name, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/chainer.py", line 51, in get_password
password = keyring.get_password(service, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 75, in get_password
collection = self.get_preferred_collection()
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 63, in get_preferred_collection
raise KeyringLocked("Failed to unlock the collection!")
keyring.errors.KeyringLocked: Failed to unlock the collection!

# Fixed code
def get_password(self, servicename, username):
    raise keyring.errors.KeyringError
# Buggy code
def delete_password(self, servicename, username):
    self.keys[servicename][username] = None


# Traceback (keyring.errors.KeyringLocked)
$ jrnl -from yesterday

WARNING: Python versions below 3.7 will no longer be supported as of jrnl v2.5
(the next release). You are currently on Python 3.6.9. Please update to
Python 3.7 (or higher) soon.

Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.6/dist-packages/jrnl/cli.py", line 387, in run
journal = open_journal(journal_name, config)
File "/usr/local/lib/python3.6/dist-packages/jrnl/Journal.py", line 405, in open_journal
return EncryptedJournal.EncryptedJournal(name, **config).open()
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 55, in open
text = self._load(filename)
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 82, in _load
return util.decrypt_content(keychain=self.name, decrypt_func=decrypt_journal)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 70, in decrypt_content
pwd_from_keychain = keychain and get_keychain(keychain)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 93, in get_keychain
return keyring.get_password("jrnl", journal_name)
File "/usr/local/lib/python3.6/dist-packages/keyring/core.py", line 56, in get_password
return _keyring_backend.get_password(service_name, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/chainer.py", line 51, in get_password
password = keyring.get_password(service, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 75, in get_password
collection = self.get_preferred_collection()
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 63, in get_preferred_collection
raise KeyringLocked("Failed to unlock the collection!")
keyring.errors.KeyringLocked: Failed to unlock the collection!

# Fixed code
def delete_password(self, servicename, username):
    raise keyring.errors.KeyringError
# Buggy code
def set_keyring(context):
    keyring.set_keyring(TestKeyring())


# Traceback (keyring.errors.KeyringLocked)
$ jrnl -from yesterday

WARNING: Python versions below 3.7 will no longer be supported as of jrnl v2.5
(the next release). You are currently on Python 3.6.9. Please update to
Python 3.7 (or higher) soon.

Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.6/dist-packages/jrnl/cli.py", line 387, in run
journal = open_journal(journal_name, config)
File "/usr/local/lib/python3.6/dist-packages/jrnl/Journal.py", line 405, in open_journal
return EncryptedJournal.EncryptedJournal(name, **config).open()
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 55, in open
text = self._load(filename)
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 82, in _load
return util.decrypt_content(keychain=self.name, decrypt_func=decrypt_journal)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 70, in decrypt_content
pwd_from_keychain = keychain and get_keychain(keychain)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 93, in get_keychain
return keyring.get_password("jrnl", journal_name)
File "/usr/local/lib/python3.6/dist-packages/keyring/core.py", line 56, in get_password
return _keyring_backend.get_password(service_name, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/chainer.py", line 51, in get_password
password = keyring.get_password(service, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 75, in get_password
collection = self.get_preferred_collection()
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 63, in get_preferred_collection
raise KeyringLocked("Failed to unlock the collection!")
keyring.errors.KeyringLocked: Failed to unlock the collection!

# Fixed code
def set_keyring(context, type=""):
    if type == "failed":
        keyring.set_keyring(FailedKeyring())
    else:
        keyring.set_keyring(TestKeyring())
# Buggy code
def get_keychain(journal_name):
    import keyring

    try:
        return keyring.get_password("jrnl", journal_name)
    except RuntimeError:
        return ""


# Traceback (keyring.errors.KeyringLocked)
$ jrnl -from yesterday

WARNING: Python versions below 3.7 will no longer be supported as of jrnl v2.5
(the next release). You are currently on Python 3.6.9. Please update to
Python 3.7 (or higher) soon.

Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.6/dist-packages/jrnl/cli.py", line 387, in run
journal = open_journal(journal_name, config)
File "/usr/local/lib/python3.6/dist-packages/jrnl/Journal.py", line 405, in open_journal
return EncryptedJournal.EncryptedJournal(name, **config).open()
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 55, in open
text = self._load(filename)
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 82, in _load
return util.decrypt_content(keychain=self.name, decrypt_func=decrypt_journal)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 70, in decrypt_content
pwd_from_keychain = keychain and get_keychain(keychain)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 93, in get_keychain
return keyring.get_password("jrnl", journal_name)
File "/usr/local/lib/python3.6/dist-packages/keyring/core.py", line 56, in get_password
return _keyring_backend.get_password(service_name, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/chainer.py", line 51, in get_password
password = keyring.get_password(service, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 75, in get_password
collection = self.get_preferred_collection()
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 63, in get_preferred_collection
raise KeyringLocked("Failed to unlock the collection!")
keyring.errors.KeyringLocked: Failed to unlock the collection!

# Fixed code
def get_keychain(journal_name):
    import keyring

    try:
        return keyring.get_password("jrnl", journal_name)
    except keyring.errors.KeyringError as e:
        if not isinstance(e, keyring.errors.NoKeyringError):
            print("Failed to retrieve keyring", file=sys.stderr)
        return ""
# Buggy code
def set_keychain(journal_name, password):
    import keyring

    if password is None:
        try:
            keyring.delete_password("jrnl", journal_name)
        except keyring.errors.PasswordDeleteError:
            pass
    else:
        try:
            keyring.set_password("jrnl", journal_name, password)
        except keyring.errors.NoKeyringError:
            print(
                "Keyring backend not found. Please install one of the supported backends by visiting: https://pypi.org/project/keyring/",
                file=sys.stderr,
            )


# Traceback (keyring.errors.KeyringLocked)
$ jrnl -from yesterday

WARNING: Python versions below 3.7 will no longer be supported as of jrnl v2.5
(the next release). You are currently on Python 3.6.9. Please update to
Python 3.7 (or higher) soon.

Traceback (most recent call last):
File "/usr/local/bin/jrnl", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.6/dist-packages/jrnl/cli.py", line 387, in run
journal = open_journal(journal_name, config)
File "/usr/local/lib/python3.6/dist-packages/jrnl/Journal.py", line 405, in open_journal
return EncryptedJournal.EncryptedJournal(name, **config).open()
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 55, in open
text = self._load(filename)
File "/usr/local/lib/python3.6/dist-packages/jrnl/EncryptedJournal.py", line 82, in _load
return util.decrypt_content(keychain=self.name, decrypt_func=decrypt_journal)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 70, in decrypt_content
pwd_from_keychain = keychain and get_keychain(keychain)
File "/usr/local/lib/python3.6/dist-packages/jrnl/util.py", line 93, in get_keychain
return keyring.get_password("jrnl", journal_name)
File "/usr/local/lib/python3.6/dist-packages/keyring/core.py", line 56, in get_password
return _keyring_backend.get_password(service_name, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/chainer.py", line 51, in get_password
password = keyring.get_password(service, username)
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 75, in get_password
collection = self.get_preferred_collection()
File "/usr/local/lib/python3.6/dist-packages/keyring/backends/SecretService.py", line 63, in get_preferred_collection
raise KeyringLocked("Failed to unlock the collection!")
keyring.errors.KeyringLocked: Failed to unlock the collection!

# Fixed code
def set_keychain(journal_name, password):
    import keyring

    if password is None:
        try:
            keyring.delete_password("jrnl", journal_name)
        except keyring.errors.KeyringError:
            pass
    else:
        try:
            keyring.set_password("jrnl", journal_name, password)
        except keyring.errors.KeyringError as e:
            if isinstance(e, keyring.errors.NoKeyringError):
                print(
                    "Keyring backend not found. Please install one of the supported backends by visiting: https://pypi.org/project/keyring/",
                    file=sys.stderr,
                )
            else:
                print("Failed to retrieve keyring", file=sys.stderr)