1
0
Fork 0
mirror of https://github.com/YunoHost/apps.git synced 2024-09-03 20:06:07 +02:00

Use optional[] for python compat

This commit is contained in:
Salamandar 2024-08-19 16:42:27 +02:00
parent 2d1403330b
commit a5cb6919fb

View file

@ -5,6 +5,7 @@ import argparse
import tempfile import tempfile
import logging import logging
from pathlib import Path from pathlib import Path
from typing import Optional
from git import Repo from git import Repo
@ -24,7 +25,7 @@ class TemporaryPath(Path):
return Path(*pathsegments) return Path(*pathsegments)
APPS_REPO_DIR: TemporaryPath | None = None APPS_REPO_DIR: Optional[TemporaryPath] = None
def add_args(parser: argparse.ArgumentParser, required: bool = False, allow_temp: bool = True) -> None: def add_args(parser: argparse.ArgumentParser, required: bool = False, allow_temp: bool = True) -> None:
env_apps_dir_str = os.environ.get("YNH_APPS_DIR") env_apps_dir_str = os.environ.get("YNH_APPS_DIR")
@ -37,7 +38,7 @@ def add_args(parser: argparse.ArgumentParser, required: bool = False, allow_temp
repo_group.add_argument("-d", "--apps-dir", type=Path, help="Path to an existing 'apps' repository", default=env_apps_dir) repo_group.add_argument("-d", "--apps-dir", type=Path, help="Path to an existing 'apps' repository", default=env_apps_dir)
def from_args(args: argparse.Namespace | None) -> Path: def from_args(args: Optional[argparse.Namespace]) -> Path:
global APPS_REPO_DIR global APPS_REPO_DIR
if APPS_REPO_DIR is not None: if APPS_REPO_DIR is not None:
return APPS_REPO_DIR return APPS_REPO_DIR
@ -45,6 +46,7 @@ def from_args(args: argparse.Namespace | None) -> Path:
assert args is not None assert args is not None
if args.apps_dir is not None: if args.apps_dir is not None:
APPS_REPO_DIR = args.apps_dir APPS_REPO_DIR = args.apps_dir
assert APPS_REPO_DIR is not None
return APPS_REPO_DIR return APPS_REPO_DIR
if args.apps_repo is not None: if args.apps_repo is not None: