prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  docker: Enable WEBLATE_GITLAB_CREDENTIALS environment variable
  ### Describe the problem
  
  Right now it seems I can use gitlab_username and gitlab_token variables. But when I try to use gitlab_credentials:
  
  >       WEBLATE_GITLAB_CREDENTIALS: "git.duniter.org": {username: weblate,token: XXXXXXXXXXXXXXX}
  
  I get this error:
  
  > ERROR: yaml.scanner.ScannerError: mapping values are not allowed here
  >   in "./docker-compose.override.yml", line 17, column 52
  
  
  ### Describe the solution you'd like
  
  Add weblate_gitlab_credentials support
  
  ### Describe alternatives you've considered
  
  _No response_
  
  ### Screenshots
  
  _No response_
  
  ### Additional context
  
  _No response_
  
  </issue>
  <code>
  [start of weblate/utils/environment.py]
  1 # Copyright © Michal Čihař <michal@weblate.org>
  2 #
  3 # SPDX-License-Identifier: GPL-3.0-or-later
  4 
  5 from __future__ import annotations
  6 
  7 import os
  8 
  9 
  10 def get_env_str(
  11     name: str,
  12     default: str | None = None,
  13     required: bool = False,
  14     fallback_name: str | None = None,
  15 ) -> str:
  16     file_env = f"{name}_FILE"
  17     if filename := os.environ.get(file_env):
  18         try:
  19             with open(filename) as handle:
  20                 result = handle.read()
  21         except OSError as error:
  22             raise ValueError(
  23                 f"Failed to open {filename} as specified by {file_env}: {error}"
  24             ) from error
  25     else:
  26         if fallback_name and name not in os.environ:
  27             name = fallback_name
  28         result = os.environ.get(name, default)
  29     if required and not result:
  30         raise ValueError(f"{name} has to be configured!")
  31     return result
  32 
  33 
  34 def get_env_list(name: str, default: list[str] | None = None) -> list[str]:
  35     """Helper to get list from environment."""
  36     if name not in os.environ:
  37         return default or []
  38     return os.environ[name].split(",")
  39 
  40 
  41 def get_env_map(name: str, default: dict[str, str] | None = None) -> dict[str, str]:
  42     """
  43     Helper to get mapping from environment.
  44 
  45     parses 'full_name:name,email:mail' into {'email': 'mail', 'full_name': 'name'}
  46     """
  47     if os.environ.get(name):
  48         return dict(e.split(":") for e in os.environ[name].split(","))
  49     return default or {}
  50 
  51 
  52 def get_env_int(name: str, default: int = 0) -> int:
  53     """Helper to get integer value from environment."""
  54     if name not in os.environ:
  55         return default
  56     try:
  57         return int(os.environ[name])
  58     except ValueError as error:
  59         raise ValueError(f"{name} is not an integer: {error}") from error
  60 
  61 
  62 def get_env_float(name: str, default: float = 0.0) -> float:
  63     """Helper to get float value from environment."""
  64     if name not in os.environ:
  65         return default
  66     try:
  67         return float(os.environ[name])
  68     except ValueError as error:
  69         raise ValueError(f"{name} is not an float: {error}") from error
  70 
  71 
  72 def get_env_bool(name: str, default: bool = False) -> bool:
  73     """Helper to get boolean value from environment."""
  74     if name not in os.environ:
  75         return default
  76     true_values = {"true", "yes", "1"}
  77     return os.environ[name].lower() in true_values
  78 
  79 
  80 def modify_env_list(current: list[str], name: str) -> list[str]:
  81     """Helper to modify list (for example checks)."""
  82     for item in reversed(get_env_list(f"WEBLATE_ADD_{name}")):
  83         current.insert(0, item)
  84     for item in get_env_list(f"WEBLATE_REMOVE_{name}"):
  85         current.remove(item)
  86     return current
  87 
  88 
  89 def get_env_credentials(
  90     name: str,
  91 ) -> dict[str, dict[str, str]]:
  92     """Parses VCS integration credentials."""
  93     username = os.environ.get(f"WEBLATE_{name}_USERNAME")
  94     token = os.environ.get(f"WEBLATE_{name}_TOKEN")
  95     host = os.environ.get(f"WEBLATE_{name}_HOST")
  96 
  97     if not host and (username or token):
  98         raise ValueError(
  99             f"Incomplete {name}_CREDENTIALS configuration: missing WEBLATE_{name}_HOST"
  100         )
  101     return {host: {"username": username, "token": token}}
  102 
  103 
  104 def get_env_ratelimit(name: str, default: str) -> str:
  105     value = os.environ.get(name, default)
  106 
  107     # Taken from rest_framework.throttling.SimpleRateThrottle.parse_rate
  108     # it can not be imported here as that breaks config loading for
  109     # rest_framework
  110 
  111     try:
  112         num, period = value.split("/")
  113     except ValueError as error:
  114         raise ValueError(f"Could not parse {name}: {error}") from error
  115     if not num.isdigit():
  116         raise ValueError(f"Could not parse {name}: rate is not numeric: {num}")
  117     if period[0] not in ("s", "m", "h", "d"):
  118         raise ValueError(f"Could not parse {name}: unknown period: {period}")
  119 
  120     return value
  121
  [end of weblate/utils/environment.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/weblate/utils/environment.py b/weblate/utils/environment.py
  --- a/weblate/utils/environment.py
  +++ b/weblate/utils/environment.py
  @@ -4,6 +4,7 @@
   
   from __future__ import annotations
   
  +import ast
   import os
   
   
  @@ -90,6 +91,8 @@
       name: str,
   ) -> dict[str, dict[str, str]]:
       """Parses VCS integration credentials."""
  +    if credentials := get_env_str(f"WEBLATE_{name}_CREDENTIALS"):
  +        return ast.literal_eval(credentials)
       username = os.environ.get(f"WEBLATE_{name}_USERNAME")
       token = os.environ.get(f"WEBLATE_{name}_TOKEN")
       host = os.environ.get(f"WEBLATE_{name}_HOST")
  
verification_info: {"golden_diff": "diff --git a/weblate/utils/environment.py b/weblate/utils/environment.py\n--- a/weblate/utils/environment.py\n+++ b/weblate/utils/environment.py\n@@ -4,6 +4,7 @@\n \n from __future__ import annotations\n \n+import ast\n import os\n \n \n@@ -90,6 +91,8 @@\n     name: str,\n ) -> dict[str, dict[str, str]]:\n     \"\"\"Parses VCS integration credentials.\"\"\"\n+    if credentials := get_env_str(f\"WEBLATE_{name}_CREDENTIALS\"):\n+        return ast.literal_eval(credentials)\n     username = os.environ.get(f\"WEBLATE_{name}_USERNAME\")\n     token = os.environ.get(f\"WEBLATE_{name}_TOKEN\")\n     host = os.environ.get(f\"WEBLATE_{name}_HOST\")\n", "issue": "docker: Enable WEBLATE_GITLAB_CREDENTIALS environment variable\n### Describe the problem\n\nRight now it seems I can use gitlab_username and gitlab_token variables. But when I try to use gitlab_credentials:\r\n\r\n>       WEBLATE_GITLAB_CREDENTIALS: \"git.duniter.org\": {username: weblate,token: XXXXXXXXXXXXXXX}\r\n\r\nI get this error:\r\n\r\n> ERROR: yaml.scanner.ScannerError: mapping values are not allowed here\r\n>   in \"./docker-compose.override.yml\", line 17, column 52\r\n\n\n### Describe the solution you'd like\n\nAdd weblate_gitlab_credentials support\n\n### Describe alternatives you've considered\n\n_No response_\n\n### Screenshots\n\n_No response_\n\n### Additional context\n\n_No response_\n", "before_files": [{"content": "# Copyright \u00a9 Michal \u010ciha\u0159 <michal@weblate.org>\n#\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import annotations\n\nimport os\n\n\ndef get_env_str(\n    name: str,\n    default: str | None = None,\n    required: bool = False,\n    fallback_name: str | None = None,\n) -> str:\n    file_env = f\"{name}_FILE\"\n    if filename := os.environ.get(file_env):\n        try:\n            with open(filename) as handle:\n                result = handle.read()\n        except OSError as error:\n            raise ValueError(\n                f\"Failed to open {filename} as specified by {file_env}: {error}\"\n            ) from error\n    else:\n        if fallback_name and name not in os.environ:\n            name = fallback_name\n        result = os.environ.get(name, default)\n    if required and not result:\n        raise ValueError(f\"{name} has to be configured!\")\n    return result\n\n\ndef get_env_list(name: str, default: list[str] | None = None) -> list[str]:\n    \"\"\"Helper to get list from environment.\"\"\"\n    if name not in os.environ:\n        return default or []\n    return os.environ[name].split(\",\")\n\n\ndef get_env_map(name: str, default: dict[str, str] | None = None) -> dict[str, str]:\n    \"\"\"\n    Helper to get mapping from environment.\n\n    parses 'full_name:name,email:mail' into {'email': 'mail', 'full_name': 'name'}\n    \"\"\"\n    if os.environ.get(name):\n        return dict(e.split(\":\") for e in os.environ[name].split(\",\"))\n    return default or {}\n\n\ndef get_env_int(name: str, default: int = 0) -> int:\n    \"\"\"Helper to get integer value from environment.\"\"\"\n    if name not in os.environ:\n        return default\n    try:\n        return int(os.environ[name])\n    except ValueError as error:\n        raise ValueError(f\"{name} is not an integer: {error}\") from error\n\n\ndef get_env_float(name: str, default: float = 0.0) -> float:\n    \"\"\"Helper to get float value from environment.\"\"\"\n    if name not in os.environ:\n        return default\n    try:\n        return float(os.environ[name])\n    except ValueError as error:\n        raise ValueError(f\"{name} is not an float: {error}\") from error\n\n\ndef get_env_bool(name: str, default: bool = False) -> bool:\n    \"\"\"Helper to get boolean value from environment.\"\"\"\n    if name not in os.environ:\n        return default\n    true_values = {\"true\", \"yes\", \"1\"}\n    return os.environ[name].lower() in true_values\n\n\ndef modify_env_list(current: list[str], name: str) -> list[str]:\n    \"\"\"Helper to modify list (for example checks).\"\"\"\n    for item in reversed(get_env_list(f\"WEBLATE_ADD_{name}\")):\n        current.insert(0, item)\n    for item in get_env_list(f\"WEBLATE_REMOVE_{name}\"):\n        current.remove(item)\n    return current\n\n\ndef get_env_credentials(\n    name: str,\n) -> dict[str, dict[str, str]]:\n    \"\"\"Parses VCS integration credentials.\"\"\"\n    username = os.environ.get(f\"WEBLATE_{name}_USERNAME\")\n    token = os.environ.get(f\"WEBLATE_{name}_TOKEN\")\n    host = os.environ.get(f\"WEBLATE_{name}_HOST\")\n\n    if not host and (username or token):\n        raise ValueError(\n            f\"Incomplete {name}_CREDENTIALS configuration: missing WEBLATE_{name}_HOST\"\n        )\n    return {host: {\"username\": username, \"token\": token}}\n\n\ndef get_env_ratelimit(name: str, default: str) -> str:\n    value = os.environ.get(name, default)\n\n    # Taken from rest_framework.throttling.SimpleRateThrottle.parse_rate\n    # it can not be imported here as that breaks config loading for\n    # rest_framework\n\n    try:\n        num, period = value.split(\"/\")\n    except ValueError as error:\n        raise ValueError(f\"Could not parse {name}: {error}\") from error\n    if not num.isdigit():\n        raise ValueError(f\"Could not parse {name}: rate is not numeric: {num}\")\n    if period[0] not in (\"s\", \"m\", \"h\", \"d\"):\n        raise ValueError(f\"Could not parse {name}: unknown period: {period}\")\n\n    return value\n", "path": "weblate/utils/environment.py"}]}