Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #62. Simple way to specify dependency options #85

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions cruiz/interop/commandparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(
self._time_commands: typing.Optional[bool] = None
self._v2_omit_test_folder: typing.Optional[bool] = None
self._v2_needs_reference: typing.Optional[bool] = None
self._extra_options: typing.Optional[str] = None

def to_args(self) -> typing.List[str]:
"""
Expand Down Expand Up @@ -400,12 +401,18 @@ def options(self) -> typing.Dict[str, str]: # TODO: should this be immutable?
"""
return self._options

def add_option(self, package_name: str, key: str, value: str) -> None:
def add_option(
self, package_name: typing.Optional[str], key: str, value: str
) -> None:
"""
Add an option key-value pair.
If package_name is provided, the option key is prefixed with package_name:
"""
assert key not in self._options
self._options[f"{package_name}:{key}"] = value
if package_name:
self._options[f"{package_name}:{key}"] = value
else:
self._options[key] = value

@property
def force(self) -> typing.Optional[bool]:
Expand Down Expand Up @@ -500,3 +507,15 @@ def v2_need_reference(self) -> typing.Optional[bool]:
@v2_need_reference.setter
def v2_need_reference(self, value: typing.Optional[bool]) -> None:
self._v2_needs_reference = value

@property
def extra_options(self) -> typing.Optional[str]:
"""
Get the extra options string.
May be None.
"""
return self._extra_options

@extra_options.setter
def extra_options(self, value: typing.Optional[str]) -> None:
self._extra_options = value
29 changes: 29 additions & 0 deletions cruiz/recipe/recipewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,23 @@ def __init__(
self._ui.localWorkflowExpressionEditor.clicked.connect(
self._local_workflow_expression_editor
)
extra_option_list_regex = QtCore.QRegularExpression(
# of the form <pkg>:<option>=<value>[,<repeat>]
r"^$|^([^:=,\s]+:[^=,\s]+=[^,\s]+)(\s*,\s*[^:=,\s]+:[^=,\s]+=[^,\s]+)*$"
)
extra_option_list_validator = QtGui.QRegularExpressionValidator(
extra_option_list_regex, self
)
self._ui.configureAdditionalOptions.setValidator(extra_option_list_validator)
rgx = QtCore.QRegularExpression(r"(^$|^@([a-zA-Z]+)\/([a-zA-Z]+)$)")
comValidator = QtGui.QRegularExpressionValidator(rgx, self)
self._ui.configurePkgRefNamespace.setValidator(comValidator)
self._ui.configurePkgRefNamespace.editingFinished.connect(
self._configure_packageref_namespace
)
self._ui.configureAdditionalOptions.editingFinished.connect(
self._configure_additional_options
)
self._ui.configurePackageId.customContextMenuRequested.connect(
self._on_configure_packageid_context_menu
)
Expand Down Expand Up @@ -700,6 +711,9 @@ def _load_configuration_dock(
assert "channel" in attributes
with BlockSignals(self._ui.configurePkgRefNamespace) as blocked_widget:
blocked_widget.setText(f"@{attributes['user']}/{attributes['channel']}")
if "extra_config_options" in attributes:
with BlockSignals(self._ui.configureAdditionalOptions) as blocked_widget:
blocked_widget.setText(attributes["extra_config_options"])
clear_widgets_from_layout(self._ui.optionsLayout)
recipe_options = self._get_options_from_recipe(recipe_attributes)
for i, (key, values, default_value) in enumerate(recipe_options):
Expand Down Expand Up @@ -1020,6 +1034,16 @@ def _configure_packageref_namespace(self) -> None:
RecipeSettingsWriter.from_recipe(self.recipe).sync(settings)
self.configuration_changed.emit()

def _configure_additional_options(self) -> None:
text = self.sender().text()
settings = RecipeSettings()
if text:
settings.append_attribute({"extra_config_options": text}) # type: ignore
else:
settings.append_attribute({"extra_config_options": None}) # type: ignore
RecipeSettingsWriter.from_recipe(self.recipe).sync(settings)
self.configuration_changed.emit()

def _open_recipe_in_editor(self) -> None:
# TODO: make the editor a preference
with GeneralSettingsReader() as settings:
Expand Down Expand Up @@ -1070,6 +1094,11 @@ def _generate_dependency_graph(
for key, value in settings.options.resolve().items():
# TODO: is this the most efficient algorithm?
params.add_option(params.name, key, value) # type: ignore
attributes = settings.attribute_overrides.resolve()
if "extra_config_options" in attributes:
for keyvalue in attributes["extra_config_options"].split(","):
option_name, option_value = keyvalue.split("=")
params.add_option(None, option_name, option_value)
self._dependency_generate_context.conancommand(
params,
None,
Expand Down
5 changes: 5 additions & 0 deletions cruiz/recipe/toolbars/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def _make_common_params(
params.add_option(
recipe_attributes["name"], key, value
) # TODO: is this the most efficient algorithm?
attributes = settings.attribute_overrides.resolve()
if "extra_config_options" in attributes:
for keyvalue in attributes["extra_config_options"].split(","):
option_name, option_value = keyvalue.split("=")
params.add_option(None, option_name, option_value)
self._append_build_features(params, settings)
if with_exclusive_package_folder:
# export-pkg requires
Expand Down
23 changes: 19 additions & 4 deletions cruiz/resources/recipe_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>313</width>
<height>211</height>
<width>312</width>
<height>281</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -351,6 +351,21 @@
<layout class="QGridLayout" name="optionsLayout"/>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="toolTip">
<string>A comma separated list of &lt;pkg&gt;:&lt;option&gt;=&lt;value&gt;</string>
</property>
<property name="title">
<string>Additional options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
<item>
<widget class="QLineEdit" name="configureAdditionalOptions"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
Expand Down Expand Up @@ -418,7 +433,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>328</width>
<width>327</width>
<height>535</height>
</rect>
</property>
Expand Down Expand Up @@ -633,7 +648,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>326</width>
<width>214</width>
<height>531</height>
</rect>
</property>
Expand Down