-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sources: deprecate
default
option and introduce possibility to disa…
…ble the implicit default source PyPI explicitly
- Loading branch information
Showing
18 changed files
with
277 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
from cleo.helpers import option | ||
|
||
from poetry.console.commands.command import Command | ||
|
||
|
||
class SourceDefaultCommand(Command): | ||
name = "source default" | ||
description = "Enable or disable the implicit default source PyPI for the project." | ||
|
||
options = [ | ||
option("enable-pypi", None, "Enable PyPI as implicit default source."), | ||
option("disable-pypi", None, "Disable PyPI as implicit default source."), | ||
] | ||
|
||
def handle(self) -> int: | ||
enable_pypi = self.option("enable-pypi") | ||
disable_pypi = self.option("disable-pypi") | ||
|
||
if enable_pypi and disable_pypi: | ||
self.line_error("Cannot enable and disable PyPI.") | ||
return 1 | ||
|
||
if enable_pypi or disable_pypi: | ||
self.poetry.pyproject.poetry_config["default-source-pypi"] = enable_pypi | ||
self.poetry.pyproject.save() | ||
|
||
else: | ||
state = ( | ||
"enabled" | ||
if self.poetry.pyproject.poetry_config.get("default-source-pypi", True) | ||
else "disabled" | ||
) | ||
self.line(f"PyPI is {state} as implicit default source.") | ||
|
||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
|
||
if TYPE_CHECKING: | ||
from cleo.testers.command_tester import CommandTester | ||
|
||
from poetry.config.source import Source | ||
from poetry.poetry import Poetry | ||
from tests.types import CommandTesterFactory | ||
|
||
|
||
@pytest.fixture | ||
def tester( | ||
command_tester_factory: CommandTesterFactory, poetry_with_source: Poetry | ||
) -> CommandTester: | ||
return command_tester_factory("source default", poetry=poetry_with_source) | ||
|
||
|
||
def test_source_default_enabled_by_default( | ||
tester: CommandTester, | ||
source_existing: Source, | ||
source_default: Source, | ||
poetry_with_source: Poetry, | ||
) -> None: | ||
tester.execute("") | ||
assert "enabled" in tester.io.fetch_output() | ||
poetry_with_source.pyproject.reload() | ||
assert "default-source-pypi" not in poetry_with_source.pyproject.poetry_config | ||
|
||
|
||
@pytest.mark.parametrize("enable", [True, False]) | ||
def test_source_default_disable( | ||
tester: CommandTester, | ||
source_existing: Source, | ||
source_default: Source, | ||
poetry_with_source: Poetry, | ||
enable: bool, | ||
) -> None: | ||
tester.execute("--enable-pypi" if enable else "--disable-pypi") | ||
poetry_with_source.pyproject.reload() | ||
assert poetry_with_source.pyproject.poetry_config["default-source-pypi"] is enable | ||
|
||
tester.execute("") | ||
output = tester.io.fetch_output() | ||
assert ("enabled" in output) is enable | ||
assert ("disabled" in output) is not enable | ||
poetry_with_source.pyproject.reload() | ||
assert poetry_with_source.pyproject.poetry_config["default-source-pypi"] is enable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.