Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
fix: remove annotations from __future__
Browse files Browse the repository at this point in the history
There's a bug with `typer` when using `annotations` from `__future__`.
So revert to using vanilla python type annotations.

BUG: fastapi/typer#371
  • Loading branch information
wizard-28 committed Mar 17, 2022
1 parent 6af217b commit 7e279da
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 100 deletions.
43 changes: 21 additions & 22 deletions pacup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
# You should have received a copy of the GNU General Public License
# along with PacUp. If not, see <https://www.gnu.org/licenses/>.

from __future__ import annotations

import hashlib
import subprocess
Expand All @@ -37,7 +36,7 @@
from os import get_terminal_size, makedirs
from pathlib import Path
from shutil import rmtree
from typing import Generator, NoReturn
from typing import Dict, Generator, List, NoReturn, Optional

import typer
from httpx import AsyncClient, HTTPStatusError, RequestError
Expand Down Expand Up @@ -108,11 +107,11 @@ async def download(url: str, progress: Progress, task: TaskID) -> str:


async def get_parsed_pacscripts(
pacscripts: list[Path],
pacscripts: List[Path],
task: TaskID,
progress: Progress,
show_filters: bool | None,
) -> list[Pacscript]:
show_filters: Optional[bool],
) -> List[Pacscript]:
"""
Get the parsed pacscripts from a list of pacscript paths.
Expand Down Expand Up @@ -151,7 +150,7 @@ async def get_parsed_pacscripts(
)


def validate_parameters(pacscripts: list[Path]) -> list[Path]:
def validate_parameters(pacscripts: List[Path]) -> List[Path]:
"""
Validate command parameters.
Expand Down Expand Up @@ -220,27 +219,27 @@ def version_callback(value: bool) -> None:

@app.command()
def update(
show_filters: bool
| None = typer.Option(
show_filters: Optional[bool] = typer.Option(
None,
"-s",
"--show-filters",
help="Shows the parsed repology filters and filterate",
),
debug: bool
| None = typer.Option(None, "-d", "--debug", help="Turn on debugging mode"),
verbose: bool
| None = typer.Option(None, "-v", "--verbose", help="Turn on verbose mode"),
version_option: bool
| None = typer.Option(
debug: Optional[bool] = typer.Option(
None, "-d", "--debug", help="Turn on debugging mode"
),
verbose: Optional[bool] = typer.Option(
None, "-v", "--verbose", help="Turn on verbose mode"
),
version_option: Optional[bool] = typer.Option(
None,
"-V",
"--version",
help="Show the version and exit",
callback=version_callback,
is_eager=True,
),
pacscripts: list[Path] = typer.Argument(
pacscripts: List[Path] = typer.Argument(
...,
help="The pacscripts to update.",
exists=True,
Expand Down Expand Up @@ -273,7 +272,7 @@ def update(
"Parsing pacscripts", total=len(pacscripts)
)
loop = get_event_loop()
parsed_pacscripts: list[Pacscript] = loop.run_until_complete(
parsed_pacscripts: List[Pacscript] = loop.run_until_complete(
get_parsed_pacscripts(
pacscripts, task, parsing_pacscripts_progress, show_filters
)
Expand All @@ -286,10 +285,10 @@ def update(
version_statuses_table = Table.grid()
version_statuses_table.add_column()

outdated_pacscripts: list[Pacscript] = []
updated_pacscripts: list[Pacscript] = []
newer_pacscripts: list[Pacscript] = []
unknown_pacscripts: list[Pacscript] = []
outdated_pacscripts: List[Pacscript] = []
updated_pacscripts: List[Pacscript] = []
newer_pacscripts: List[Pacscript] = []
unknown_pacscripts: List[Pacscript] = []
for pacscript in parsed_pacscripts:
if pacscript.version.status == VersionStatuses.OUTDATED:
outdated_pacscripts.append(pacscript)
Expand Down Expand Up @@ -403,8 +402,8 @@ def update(

# Loop through the parsed pacscripts and update them
log.info("Updating pacscripts...")
successfully_updated_pacscripts: list[Pacscript] = []
failed_to_update_pacscripts: dict[Pacscript, str] = {}
successfully_updated_pacscripts: List[Pacscript] = []
failed_to_update_pacscripts: Dict[Pacscript, str] = {}
for pacscript in outdated_pacscripts:
path = pacscript.path
pkgname = pacscript.pkgname
Expand Down
16 changes: 8 additions & 8 deletions pacup/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
# You should have received a copy of the GNU General Public License
# along with PacUp. If not, see <https://www.gnu.org/licenses/>.

from __future__ import annotations

from asyncio.locks import Semaphore
from asyncio.subprocess import PIPE, Process, create_subprocess_shell
from logging import getLogger
from pathlib import Path
from typing import Dict, List, Optional

from httpx import AsyncClient, HTTPStatusError, RequestError
from rich.progress import Progress, TaskID
Expand Down Expand Up @@ -106,9 +106,9 @@ def __init__(
url: Url,
hash_line: int,
maintainer: str,
repology_filters: dict[str, str],
release_notes: dict[str, str],
lines: list[str],
repology_filters: Dict[str, str],
release_notes: Dict[str, str],
lines: List[str],
):
"""
Parameters
Expand Down Expand Up @@ -151,8 +151,8 @@ async def parse(
semaphore: Semaphore,
task: TaskID,
progress: Progress,
show_filters: bool | None,
) -> Pacscript:
show_filters: Optional[bool],
) -> "Pacscript":
"""
Parses a pacscript file.
Expand Down Expand Up @@ -189,7 +189,7 @@ async def parse(
url = Url()
hash_line = -1 # Which line contains the hash
maintainer = ""
repology_filters: dict[str, str] = {}
repology_filters: Dict[str, str] = {}

pacscript_reader_process = await create_subprocess_shell(
"/bin/bash", stdin=PIPE, stdout=PIPE
Expand Down Expand Up @@ -269,7 +269,7 @@ async def parse(
)

# Fetch the release notes
release_notes: dict[str, str] = {}
release_notes: Dict[str, str] = {}
try:
owner = url.value.split("/")[3]
repo = url.value.split("/")[4]
Expand Down
49 changes: 0 additions & 49 deletions pacup/test.py

This file was deleted.

36 changes: 15 additions & 21 deletions pacup/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
# You should have received a copy of the GNU General Public License
# along with PacUp. If not, see <https://www.gnu.org/licenses/>.

from __future__ import annotations

from asyncio.locks import Semaphore
from enum import Enum, auto
from logging import getLogger
from typing import Any, Literal
from typing import Any, Dict, List, Literal, Optional, Union

from httpx import AsyncClient, HTTPStatusError, RequestError
from packaging import version as pkg_version
Expand Down Expand Up @@ -66,18 +65,20 @@ def __init__(self, line_number: int = -1, version: str = "", latest: str = ""):

@staticmethod
async def get_latest_version(
filters: dict[str, str],
filters: Dict[str, str],
client: AsyncClient,
semaphore: Semaphore,
show_filters: bool | None,
show_filters: Optional[bool],
) -> (
str
| Literal[
RepologyErrors.NOT_FOUND,
RepologyErrors.NO_PROJECT_FILTER,
RepologyErrors.NO_FILTERS,
RepologyErrors.HTTP_STATUS_ERROR,
RepologyErrors.REQUEST_ERROR,
Union[
str,
Literal[
RepologyErrors.NOT_FOUND,
RepologyErrors.NO_PROJECT_FILTER,
RepologyErrors.NO_FILTERS,
RepologyErrors.HTTP_STATUS_ERROR,
RepologyErrors.REQUEST_ERROR,
],
]
):
"""
Expand All @@ -96,14 +97,7 @@ async def get_latest_version(
Returns
-------
str
| Literal[
RepologyErrors.NOT_FOUND,
RepologyErrors.NO_PROJECT_FILTER,
RepologyErrors.NO_FILTERS,
RepologyErrors.HTTP_STATUS_ERROR,
RepologyErrors.REQUEST_ERROR,
]
Union[str, Literal[RepologyErrors.NOT_FOUND, RepologyErrors.NO_PROJECT_FILTER, RepologyErrors.NO_FILTERS, RepologyErrors.HTTP_STATUS_ERROR, RepologyErrors.REQUEST_ERROR]]
The latest version of the package.
"""
async with semaphore:
Expand Down Expand Up @@ -142,11 +136,11 @@ async def get_latest_version(
return RepologyErrors.HTTP_STATUS_ERROR

else:
filtered: list[dict[str, Any]] = response.json()
filtered: List[Dict[str, Any]] = response.json()

log.info("Filtering...")
for key, value in filters.items():
new_filtered: list[dict[str, Any]] = []
new_filtered: List[Dict[str, Any]] = []
for packages in filtered:
if packages[key] == value:
new_filtered.append(packages)
Expand Down

0 comments on commit 7e279da

Please sign in to comment.