Skip to content

Commit

Permalink
Fixes #98. Linting. Enabling mypy's warn_unreachable
Browse files Browse the repository at this point in the history
- removes a commented out streaming class that I thought I could use, but never did
- fixes some logic errors
- in _get_options_from_recipe, the logic has changed when iterating over possible option values. As I recall it used to work, but the if...else ordering would never have been executed, so mypy is right
  • Loading branch information
markfinal committed Jul 15, 2023
1 parent 9f27cac commit 9de29a7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 87 deletions.
2 changes: 1 addition & 1 deletion cruiz/load_recipe/pages/packageversionpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _get_versions_from_conandata(
assert conandata
with ConanSettingsReader() as settings:
path_segments = settings.conandata_version_yaml_pathsegment.resolve()
if path_segments is None:
if not path_segments:
QtWidgets.QMessageBox.information(
self,
"Cannot identify recipe version numbers from conandata.yml file",
Expand Down
2 changes: 1 addition & 1 deletion cruiz/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _rebuild_recent_recipe_menu(self) -> None:
for uuid in uuids:
with RecipeSettingsReader.from_uuid(uuid) as settings:
path = settings.path.resolve()
if path is None:
if not path:
has_recipe_settings_issue = True
continue
recipe_path = pathlib.Path(path)
Expand Down
42 changes: 23 additions & 19 deletions cruiz/recipe/recipewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,17 @@ def get_recipe_attributes(
)

def _get_options_from_recipe(
self, attrs: typing.Dict[str, str]
) -> typing.List[typing.Tuple[str, typing.List[typing.Any], typing.Any]]:
if cruiz.globals.CONAN_MAJOR_VERSION == 1:
# this lists the possible values for the option
options = attrs.get("options")
else:
# don't use the 'options' key, as that has been assigned the value
# options_definitions is where the possible values are
options = attrs.get("options_definitions")
self, attrs: typing.Dict[str, typing.Any]
) -> typing.List[
typing.Tuple[str, typing.Union[str, typing.List[typing.Any]], typing.Any]
]:
# this lists the possible values for the option
# in Conan 2, don't use the 'options' key, as that has been assigned the value
options: typing.Optional[typing.Dict[str, typing.Any]] = (
attrs.get("options")
if cruiz.globals.CONAN_MAJOR_VERSION == 1
else attrs.get("options_definitions")
)
if not options:
return []
default_options = attrs["default_options"]
Expand All @@ -420,7 +422,9 @@ def _get_options_from_recipe(
assert isinstance(
default_options, dict
), "Expected default_options to be a dict"
values: typing.List[typing.Tuple[str, typing.List[typing.Any], typing.Any]] = []
values: typing.List[
typing.Tuple[str, typing.Union[str, typing.List[typing.Any]], typing.Any]
] = []
assert isinstance(options, dict)
for key, value in options.items():
if default_options:
Expand All @@ -439,15 +443,15 @@ def _get_options_from_recipe(
f"Cannot find default value '{default_value}' in possible "
f"values {value}"
)
elif (isinstance(value, str) and value == "ANY") or (
isinstance(value, list) and "ANY" in value
):
pass
else:
raise TypeError(
f"Don't know how to convert '{default_value}' to type "
f"'{type(value[0])}'"
)
elif (isinstance(value, str) and value == "ANY") or (
isinstance(value, list) and "ANY" in value
):
pass
else:
raise TypeError(
f"Don't know how to convert '{default_value}' to type "
f"'{type(value[0])}'"
)
values.append((key, value, default_value))
else:
values.append((key, value, None))
Expand Down
5 changes: 2 additions & 3 deletions cruiz/recipe/toolbars/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,8 @@ def _make_common_params(
params.source_folder = recipe_widget.resolve_expression(source_folder)
if fudge_source_folder:
source_folder = settings.local_workflow_source_folder.resolve()
if (
source_folder is None
and not recipe_widget.cwd_is_relative_to_recipe(workflow_cwd)
if not source_folder and not recipe_widget.cwd_is_relative_to_recipe(
workflow_cwd
):
# fudge due to the default source_folder changing between
# 'conan source' and 'conan build'
Expand Down
2 changes: 1 addition & 1 deletion cruiz/settings/managers/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self) -> None:
self._recipe: typing.Optional[Recipe] = None

if self._recipe:
default_profile = self._recipe.context.default_profile_filename()
default_profile = self._recipe.context.default_profile_filename() # type: ignore[unreachable] # noqa: E501
else:
try:
context = self.settings_reader.recipe.context # type: ignore
Expand Down
60 changes: 0 additions & 60 deletions cruiz/workers/utils/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,6 @@
from cruiz.interop.message import Message


if False:
import io

# Conan 1.30.0+ changed the assumptions on the base-class of streams used in their
# runner output to be based from six, so this Python 3 implementation is no longer
# valid it may come back in future Conan versions that are Python 3 only
class QueuedStreamPy3(io.RawIOBase):
"""
A stream class that uses multiprocessing.Queue to send messages
"""

def __init__(self, queue: multiprocessing.Queue[Message], message_type):
super().__init__()
self._queue = queue
self._message_type = message_type

# configure the IOBase
def seekable(self):
"""
Stream is not seekable
"""
return False

def writeable(self):
"""
Stream is writeable
"""
# pylint: disable=no-self-use
return True

def readable(self):
"""
Stream is not readable
"""
return False

def isatty(self):
"""
Stream is not interactive
"""
# TODO: could this be True, which asks the queue for info?
return False

# implement functions of interest
def write(self, message):
"""
Write a message.
"""
lines = message.split("\n")
for line in lines:
if not line:
continue
self._queue.put(self._message_type(convert_from_colorama_to_html(line)))

def flush(self):
"""
Flush the stream.
"""


class QueuedStreamSix(six.StringIO):
"""
A stream class that uses multiprocessing.Queue to send messages.
Expand Down
2 changes: 1 addition & 1 deletion cruiz/workers/utils/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __enter__(self) -> None:
if isinstance(self._params, (CommandParameters, CommonParameters)):
set_env(self._params.added_environment, self._params.removed_environment)
else:
with contextlib.suppress(TypeError):
with contextlib.suppress(TypeError): # type: ignore[unreachable]
# can happen for other types of *Parameters classes
if "env" in self._params:
set_env(self._params["env"], [])
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ warn_unused_ignores = True
warn_no_return = True
# TODO: warn_return_any requires some more work
warn_return_any = False
warn_unreachable = False
warn_unreachable = True

# strictness flags
allow_untyped_globals = False
Expand Down

0 comments on commit 9de29a7

Please sign in to comment.