Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent committed Jan 27, 2022
1 parent f382f68 commit f084dff
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
8 changes: 5 additions & 3 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import List
from typing import Optional
from typing import Tuple
from typing import Union
from typing import cast

from cleo.helpers import argument
Expand Down Expand Up @@ -145,6 +146,7 @@ def handle(self) -> Optional[int]:
# show the value if no value is provided
if not self.argument("value") and not self.option("unset"):
m = re.match(r"^repos?(?:itories)?(?:\.(.+))?", self.argument("key"))
value: Union[str, Dict[str, Any]]
if m:
if not m.group(1):
value = {}
Expand All @@ -165,9 +167,9 @@ def handle(self) -> Optional[int]:
value = config.get(setting_key)

if not isinstance(value, str):
self.line(json.dumps(value))
else:
self.line(value)
value = json.dumps(value)

self.line(value)

return 0

Expand Down
11 changes: 6 additions & 5 deletions src/poetry/console/commands/plugin/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,19 @@ def handle(self) -> int:
root_package = ProjectPackage(package.name, package.version)
for dependency in package.requires:
root_package.add_dependency(dependency)
break

if not root_package:
raise RuntimeError("Failed to find Poetry package")
break

root_package.python_versions = ".".join(
root_package.python_versions = ".".join( # type: ignore[union-attr]
str(v) for v in system_env.version_info[:3]
)
# We create a `pyproject.toml` file based on all the information
# we have about the current environment.
if not env_dir.joinpath("pyproject.toml").exists():
Factory.create_pyproject_from_package(root_package, env_dir)
Factory.create_pyproject_from_package(
root_package, # type: ignore[arg-type]
env_dir,
)

# We add the plugins to the dependencies section of the previously
# created `pyproject.toml` file
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/console/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def handle(self) -> int:
if "group" in poetry_content and not poetry_content["group"]:
del poetry_content["group"]

removed_ = set(removed)
not_found = set(packages).difference(removed_)
removed_set = set(removed)
not_found = set(packages).difference(removed_set)
if not_found:
raise ValueError(
"The following packages were not found: " + ", ".join(sorted(not_found))
Expand All @@ -104,7 +104,7 @@ def handle(self) -> int:
self._installer.dry_run(self.option("dry-run"))
self._installer.verbose(self._io.is_verbose())
self._installer.update(True)
self._installer.whitelist(removed_)
self._installer.whitelist(removed_set)

status = self._installer.run()

Expand Down
6 changes: 1 addition & 5 deletions src/poetry/console/commands/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class ShellCommand(EnvCommand):
"""

def handle(self) -> None:
from poetry.utils.env import VirtualEnv
from poetry.utils.shell import Shell

# Check if it's already activated or doesn't exist and won't be created
Expand All @@ -33,11 +32,8 @@ def handle(self) -> None:

self.line(f"Spawning shell within <info>{self.env.path}</>")

if not isinstance(self.env, VirtualEnv):
raise RuntimeError("Failed to find virtual environment to activate")

# Setting this to avoid spawning unnecessary nested shells
environ["POETRY_ACTIVE"] = "1"
shell = Shell.get()
shell.activate(self.env)
shell.activate(self.env) # type: ignore[arg-type]
environ.pop("POETRY_ACTIVE")
14 changes: 7 additions & 7 deletions src/poetry/console/commands/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,27 @@ def increment_version(self, version: str, rule: str) -> "Version":
from poetry.core.semver.version import Version

try:
version_ = Version.parse(version)
parsed = Version.parse(version)
except ValueError:
raise ValueError("The project's version doesn't seem to follow semver")

if rule in {"major", "premajor"}:
new = version_.next_major()
new = parsed.next_major()
if rule == "premajor":
new = new.first_prerelease()
elif rule in {"minor", "preminor"}:
new = version_.next_minor()
new = parsed.next_minor()
if rule == "preminor":
new = new.first_prerelease()
elif rule in {"patch", "prepatch"}:
new = version_.next_patch()
new = parsed.next_patch()
if rule == "prepatch":
new = new.first_prerelease()
elif rule == "prerelease":
if version_.is_unstable():
new = Version(version_.epoch, version_.release, version_.pre.next())
if parsed.is_unstable():
new = Version(parsed.epoch, parsed.release, parsed.pre.next())
else:
new = version_.next_patch().first_prerelease()
new = parsed.next_patch().first_prerelease()
else:
new = Version.parse(rule)

Expand Down

0 comments on commit f084dff

Please sign in to comment.