Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
ytausch committed Feb 13, 2024
1 parent 3b2be38 commit 4666119
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 0 additions & 4 deletions conda_forge_tick/update_prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@

# from conda_forge_tick.profiler import profiling


if typing.TYPE_CHECKING:
from .cli import CLIArgs

logger = logging.getLogger("conda_forge_tick.update_prs")

NUM_GITHUB_THREADS = 2
Expand Down
19 changes: 12 additions & 7 deletions conda_forge_tick/update_upstream_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Dict,
Iterable,
Iterator,
List,
Literal,
Mapping,
Optional,
Expand Down Expand Up @@ -65,7 +66,7 @@ def get_latest_version(
name: str,
attrs: Mapping[str, Any],
sources: Iterable[AbstractSource],
) -> Dict[str, Union[bool, str]]:
) -> Dict[str, Union[Literal[False], str]]:
"""
Given a package, return the new version information to be written into the cf-graph.
:param name: the name of the package.
Expand All @@ -87,19 +88,23 @@ def get_latest_version(
{},
None,
)

sources_to_use: Iterable[AbstractSource]
if version_sources is not None:
version_sources = [vs.lower() for vs in version_sources]
sources_to_use = []
sources_to_use_list = []
for vs in version_sources:
for source in sources:
if source.name.lower() == vs:
sources_to_use.append(source)
sources_to_use_list.append(source)
break
else:
logger.warning(
f"Package {name} requests version source '{vs}' which is not available. Skipping.",
)

sources_to_use = sources_to_use_list

logger.debug(
f"{name} defines the following custom version sources: {[source.name for source in sources_to_use]}",
)
Expand Down Expand Up @@ -215,12 +220,12 @@ def include_node(package_name: str, payload_attrs: Mapping) -> bool:

def _update_upstream_versions_sequential(
to_update: Iterable[Tuple[str, Mapping]],
sources: Iterable[AbstractSource] = None,
sources: Iterable[AbstractSource],
) -> None:
node_count = 0
for node, attrs in to_update:
# checking each node
version_data = {}
version_data: Dict[str, Union[Literal[False], str]] = {}

# New version request
try:
Expand Down Expand Up @@ -273,7 +278,7 @@ def _update_upstream_versions_process_pool(
n_left = len(futures)
start = time.time()
# eta :: elapsed time average
eta = -1
eta = -1.0
for f in as_completed(futures):
n_left -= 1
if n_left % 10 == 0:
Expand Down Expand Up @@ -315,7 +320,7 @@ def _update_upstream_versions_process_pool(

def update_upstream_versions(
gx: nx.DiGraph,
sources: Iterable[AbstractSource] = None,
sources: Optional[Iterable[AbstractSource]] = None,
debug: bool = False,
job=1,
n_jobs=1,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_upstream_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import random
from concurrent.futures import Future
from typing import Mapping
from typing import Dict, Mapping
from unittest import mock
from unittest.mock import MagicMock, Mock, patch

Expand Down Expand Up @@ -1145,7 +1145,7 @@ def test_include_node_parsing_error(caplog):

def test_include_node_no_payload():
package_name = "testpackage"
payload_attrs = {}
payload_attrs: Dict = {}

assert include_node(package_name, payload_attrs)

Expand Down Expand Up @@ -1467,8 +1467,8 @@ def test_update_upstream_versions_process_pool(
("testpackage2", {"version": "1.2.4"}),
]

future_1 = Future()
future_2 = Future()
future_1: Future[Dict[str, str]] = Future()
future_2: Future[Dict[str, str]] = Future()

pool_mock = executor_mock.return_value.__enter__.return_value
pool_mock.submit.side_effect = [future_1, future_2]
Expand Down Expand Up @@ -1518,7 +1518,7 @@ def test_update_upstream_versions_process_pool_exception(
("testpackage", {"version": "2.2.3"}),
]

future = Future()
future: Future[Dict[str, str]] = Future()

pool_mock = executor_mock.return_value.__enter__.return_value
pool_mock.submit.return_value = future
Expand Down Expand Up @@ -1561,7 +1561,7 @@ def test_update_upstream_versions_process_pool_exception_repr_exception(
("testpackage", {"version": "2.2.3"}),
]

future = Future()
future: Future[Dict[str, str]] = Future()

pool_mock = executor_mock.return_value.__enter__.return_value
pool_mock.submit.return_value = future
Expand Down

0 comments on commit 4666119

Please sign in to comment.