Skip to content
Snippets Groups Projects
Commit b4e52144 authored by Sebastian Mohr's avatar Sebastian Mohr
Browse files

Fixed python package to work with v3.9

parent 994a0b8c
No related branches found
No related tags found
No related merge requests found
Pipeline #510481 failed
...@@ -5,6 +5,7 @@ include: ...@@ -5,6 +5,7 @@ include:
- local: "/.gitlab/lint.yml" - local: "/.gitlab/lint.yml"
- local: "/.gitlab/docker_images.yml" - local: "/.gitlab/docker_images.yml"
- local: "/.gitlab/backup.yml" - local: "/.gitlab/backup.yml"
- local: "/.gitlab/python.yml"
before_script: before_script:
- source $CI_PROJECT_DIR/.gitlab/.gitlab-ci.sh - source $CI_PROJECT_DIR/.gitlab/.gitlab-ci.sh
......
default:
image: docker:26
services:
- docker:26-dind
build: build:
stage: build stage: build
image: docker:26 image: docker:26
script: script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/$APP_NAME:latest || true - docker pull $CI_REGISTRY_IMAGE/$APP_NAME:latest || true
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 - docker build --build-arg BUILDKIT_INLINE_CACHE=1
--cache-from "$CI_REGISTRY_IMAGE/$APP_NAME:latest" --cache-from "$CI_REGISTRY_IMAGE/$APP_NAME:latest"
--tag "$CI_REGISTRY_IMAGE/$APP_NAME:latest" --tag "$CI_REGISTRY_IMAGE/$APP_NAME:latest"
--tag "$CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_SHORT_SHA" --tag "$CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_SHORT_SHA"
--tag "$CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_REF_NAME" --tag "$CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_REF_NAME"
-f Dockerfile_node --target $APP_NAME . -f Dockerfile_node --target $APP_NAME .
- docker push $CI_REGISTRY_IMAGE/$APP_NAME:latest - docker push $CI_REGISTRY_IMAGE/$APP_NAME:latest
- docker push $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_SHORT_SHA - docker push $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_REF_NAME - docker push $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_REF_NAME
parallel: parallel:
matrix: matrix:
- APP_NAME: ["next", "images", "socket", "email"] - APP_NAME: ["next", "images", "socket", "email"]
tags: tags:
- docker - docker
only: only:
refs: refs:
- main - main
services:
- docker:26-dind
release: release:
stage: release stage: release
image: docker:26 image: docker:26
script: script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_SHORT_SHA - docker pull $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_SHORT_SHA
- docker tag $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_TAG - docker tag $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_TAG
- docker push $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_TAG - docker push $CI_REGISTRY_IMAGE/$APP_NAME:$CI_COMMIT_TAG
parallel: parallel:
matrix: matrix:
- APP_NAME: ["next", "images", "socket", "email"] - APP_NAME: ["next", "images", "socket", "email"]
tags: tags:
- docker - docker
only: only:
- tags - tags
except: except:
- branches - branches
\ No newline at end of file services:
- docker:26-dind
test:
stage: test
image: "python:$VERSION"
rules:
- changes:
- "packages/python/**/*.py"
parallel:
matrix:
- VERSION: ["3.9", "3.10", "3.11", "3.12"]
script:
- python -V
from typing import Optional, cast from typing import Optional, Union, cast
import click import click
import typer import typer
...@@ -17,10 +17,10 @@ token_app = typer.Typer( ...@@ -17,10 +17,10 @@ token_app = typer.Typer(
help="Manage your tokens for authentication.", help="Manage your tokens for authentication.",
) )
selected_keyring: KeyringBackend | None = None selected_keyring: Optional[KeyringBackend] = None
def parse_keyring(value: str | KeyringBackend = "default") -> KeyringBackend: def parse_keyring(value: Union[str, KeyringBackend] = "default") -> KeyringBackend:
if isinstance(value, KeyringBackend): if isinstance(value, KeyringBackend):
log.debug(f"No keyring selected. Using default keyring {value.name}") log.debug(f"No keyring selected. Using default keyring {value.name}")
return value return value
...@@ -108,7 +108,7 @@ def list(): ...@@ -108,7 +108,7 @@ def list():
console.print(table) console.print(table)
def valid_name(name: str | None, kr: KeyringBackend) -> str: def valid_name(name: str, kr: KeyringBackend) -> str:
if name is None or name == "": if name is None or name == "":
raise typer.BadParameter("Name cannot be empty.") raise typer.BadParameter("Name cannot be empty.")
if " " in name: if " " in name:
...@@ -122,13 +122,13 @@ def valid_name(name: str | None, kr: KeyringBackend) -> str: ...@@ -122,13 +122,13 @@ def valid_name(name: str | None, kr: KeyringBackend) -> str:
def add( def add(
token: Annotated[str, typer.Argument(help="The token to add to the keyring.")], token: Annotated[str, typer.Argument(help="The token to add to the keyring.")],
name: Annotated[ name: Annotated[
str | None, Optional[str],
typer.Option( typer.Option(
help="The name of the token, should be unique.", help="The name of the token, should be unique.",
), ),
] = None, ] = None,
book_id: Annotated[ book_id: Annotated[
int | None, Optional[int],
typer.Option( typer.Option(
help="The book ID for the token.", help="The book ID for the token.",
), ),
......
...@@ -21,18 +21,18 @@ If not files are given we retrieve the tokens from the default locations. ...@@ -21,18 +21,18 @@ If not files are given we retrieve the tokens from the default locations.
import os import os
from collections import defaultdict from collections import defaultdict
from configparser import ConfigParser from configparser import ConfigParser
from typing import Dict, Sequence from typing import Dict, Optional, Sequence, Union
from snip.logger import log from snip.logger import log
from ..token import Token from ..token import Token
File = str | os.PathLike File = Union[str, os.PathLike]
Files = File | Sequence[File] Files = Union[File, Sequence[File]]
def get_all_tokens( def get_all_tokens(
files: Files | None = None, files: Optional[Files] = None,
) -> tuple[ ) -> tuple[
list[Token], list[Token],
list[File], list[File],
...@@ -105,8 +105,8 @@ def get_all_tokens( ...@@ -105,8 +105,8 @@ def get_all_tokens(
def get_token( def get_token(
name: str, name: str,
files: Files | None = None, files: Optional[Files] = None,
) -> Token | None: ) -> Optional[Token]:
"""Get a token from a file or list of files given its name. """Get a token from a file or list of files given its name.
Parameters Parameters
...@@ -122,7 +122,7 @@ def get_token( ...@@ -122,7 +122,7 @@ def get_token(
def token_exists( def token_exists(
name: str, name: str,
files: Files | None = None, files: Optional[Files] = None,
) -> bool: ) -> bool:
"""Check if a token with a given name exists in a file or list of files. """Check if a token with a given name exists in a file or list of files.
...@@ -137,7 +137,9 @@ def token_exists( ...@@ -137,7 +137,9 @@ def token_exists(
raise NotImplementedError("Not implemented yet.") raise NotImplementedError("Not implemented yet.")
def __parse_files(files: Files | None = None) -> Sequence[File]: def __parse_files(
files: Optional[Files] = None,
) -> Sequence[File]:
"""Parse the files and adds the default locations if None is given. """Parse the files and adds the default locations if None is given.
- local: .sniprc - local: .sniprc
......
...@@ -19,6 +19,8 @@ kr.set_password(SNIP_KR_IDENTIFIER, f"index", f"{name.as_hex},{name2.as_hex},... ...@@ -19,6 +19,8 @@ kr.set_password(SNIP_KR_IDENTIFIER, f"index", f"{name.as_hex},{name2.as_hex},...
""" """
from typing import Optional
from keyring.backend import KeyringBackend from keyring.backend import KeyringBackend
from snip.logger import log from snip.logger import log
...@@ -61,7 +63,7 @@ def get_all_tokens(kr: KeyringBackend) -> list[Token]: ...@@ -61,7 +63,7 @@ def get_all_tokens(kr: KeyringBackend) -> list[Token]:
return tokens return tokens
def get_token(name: str, kr: KeyringBackend) -> Token | None: def get_token(name: str, kr: KeyringBackend) -> Optional[Token]:
"""Get a token from the keyring storage. """Get a token from the keyring storage.
Parameters Parameters
...@@ -79,7 +81,7 @@ def get_token(name: str, kr: KeyringBackend) -> Token | None: ...@@ -79,7 +81,7 @@ def get_token(name: str, kr: KeyringBackend) -> Token | None:
return _get_token(__encode_name(name), kr) return _get_token(__encode_name(name), kr)
def _get_token(hex_name: str, kr: KeyringBackend) -> Token | None: def _get_token(hex_name: str, kr: KeyringBackend) -> Optional[Token]:
"""Get a saved token from the keyring storage. """Get a saved token from the keyring storage.
Parameters Parameters
......
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional
import requests import requests
...@@ -16,7 +17,7 @@ class Token: ...@@ -16,7 +17,7 @@ class Token:
@classmethod @classmethod
def from_unsafe( def from_unsafe(
cls, name: str, book_id: str, token: str, deployment_url: str | None cls, name: str, book_id: str, token: str, deployment_url: Optional[str] = None
) -> "Token": ) -> "Token":
"""Create a token object from unsafe input. """Create a token object from unsafe input.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment