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

Miscellaneous fixes #7173

Merged
merged 6 commits into from
Dec 18, 2022
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
524 changes: 247 additions & 277 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ crashtest = "^0.4.1"
dulwich = "^0.20.46"
filelock = "^3.8.0"
html5lib = "^1.0"
importlib-metadata = { version = "^4.4", python = "<3.10" }
importlib-metadata = { version = ">=4.4,<6", python = "<3.10" }
jsonschema = "^4.10.0"
keyring = "^23.9.0"
lockfile = "^0.12.2"
Expand Down Expand Up @@ -88,14 +88,14 @@ pre-commit = "^2.6"
[tool.poetry.group.test.dependencies]
# Cachy frozen to test backwards compatibility for `poetry.utils.cache`.
cachy = "0.3.0"
deepdiff = "^5.0"
deepdiff = "^6.2"
flatdict = "^4.0.1"
httpretty = "^1.0"
pytest = "^7.1"
pytest-cov = "^4.0"
pytest-mock = "^3.9"
pytest-randomly = "^3.12"
pytest-xdist = { version = "^2.5", extras = ["psutil"] }
pytest-xdist = { version = "^3.1", extras = ["psutil"] }
zipp = { version = "^3.4", python = "<3.8" }

[tool.poetry.group.typing.dependencies]
Expand Down Expand Up @@ -163,8 +163,6 @@ enable_error_code = [
[[tool.mypy.overrides]]
module = [
'poetry.console.commands.self.show.plugins',
'poetry.installation.executor',
'poetry.mixology.version_solver',
'poetry.plugins.plugin_manager',
'poetry.repositories.installed_repository',
'poetry.utils.env',
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _find_best_version_for_package(
# TODO: find similar
raise ValueError(f"Could not find a matching version of package {name}")

return package.pretty_name, selector.find_recommended_require_version(package)
return package.pretty_name, f"^{package.version.to_string()}"

def _parse_requirements(self, requirements: list[str]) -> list[dict[str, Any]]:
from poetry.core.pyproject.exceptions import PyProjectException
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/console/commands/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cleo.helpers import argument
from cleo.helpers import option
from poetry.core.version.exceptions import InvalidVersion
from tomlkit.toml_document import TOMLDocument

from poetry.console.commands.command import Command
Expand Down Expand Up @@ -95,7 +96,7 @@ def increment_version(self, version: str, rule: str) -> Version:

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

if rule in {"major", "premajor"}:
Expand Down
19 changes: 13 additions & 6 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from poetry.core.utils.helpers import parse_requires
from poetry.core.utils.helpers import temporary_directory
from poetry.core.version.markers import InvalidMarker
from poetry.core.version.requirements import InvalidRequirement

from poetry.utils.env import EnvCommandError
from poetry.utils.env import ephemeral_environment
Expand All @@ -40,7 +41,7 @@
PEP517_META_BUILD = """\
import build
import build.env
import pep517
import pyproject_hooks

source = '{source}'
dest = '{dest}'
Expand All @@ -50,14 +51,14 @@
srcdir=source,
scripts_dir=env.scripts_dir,
python_executable=env.executable,
runner=pep517.quiet_subprocess_runner,
runner=pyproject_hooks.quiet_subprocess_runner,
)
env.install(builder.build_system_requires)
env.install(builder.get_requires_for_build('wheel'))
builder.metadata_path(dest)
"""

PEP517_META_BUILD_DEPS = ["build===0.7.0", "pep517==0.12.0"]
PEP517_META_BUILD_DEPS = ["build==0.9.0", "pyproject_hooks==1.0.0"]


class PackageInfoError(ValueError):
Expand Down Expand Up @@ -201,12 +202,18 @@ def to_package(
dependency = Dependency.create_from_pep_508(req, relative_to=root_dir)
except InvalidMarker:
# Invalid marker, We strip the markers hoping for the best
logger.warning(
"Stripping invalid marker (%s) found in %s-%s dependencies",
req,
package.name,
package.version,
)
req = req.split(";")[0]
dependency = Dependency.create_from_pep_508(req, relative_to=root_dir)
except ValueError:
# Likely unable to parse constraint so we skip it
except InvalidRequirement:
# Unable to parse requirement so we skip it
logger.warning(
"Invalid constraint (%s) found in %s-%s dependencies, skipping",
"Invalid requirement (%s) found in %s-%s dependencies, skipping",
req,
package.name,
package.version,
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/installation/chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _get_links(self, package: Package) -> list[Link]:
repository = self._pool.repository("pypi")
links = repository.find_links_for_package(package)

hashes = [f["hash"] for f in package.files]
hashes = {f["hash"] for f in package.files}
if not hashes:
return links

Expand Down
12 changes: 4 additions & 8 deletions src/poetry/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ def validate_object(obj: dict[str, Any]) -> list[str]:
Path(CORE_SCHEMA_DIR, "poetry-schema.json").read_text(encoding="utf-8")
)

if core_schema["additionalProperties"]:
# TODO: make this un-conditional once core update to >1.1.0b2
properties = {*schema["properties"].keys(), *core_schema["properties"].keys()}
additional_properties = set(obj.keys()) - properties
for key in additional_properties:
errors.append(
f"Additional properties are not allowed ('{key}' was unexpected)"
)
properties = {*schema["properties"].keys(), *core_schema["properties"].keys()}
additional_properties = set(obj.keys()) - properties
for key in additional_properties:
errors.append(f"Additional properties are not allowed ('{key}' was unexpected)")

return errors
3 changes: 2 additions & 1 deletion src/poetry/repositories/link_sources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from poetry.core.constraints.version import Version
from poetry.core.packages.package import Package
from poetry.core.version.exceptions import InvalidVersion

from poetry.utils._compat import cached_property
from poetry.utils.patterns import sdist_file_re
Expand Down Expand Up @@ -84,7 +85,7 @@ def link_package_data(cls, link: Link) -> Package | None:
if version_string:
try:
version = Version.parse(version_string)
except ValueError:
except InvalidVersion:
logger.debug(
"Skipping url (%s) due to invalid version (%s)", link.url, version
)
Expand Down
13 changes: 0 additions & 13 deletions src/poetry/version/version_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from typing import TYPE_CHECKING

from poetry.core.constraints.version import Version


if TYPE_CHECKING:
from poetry.core.packages.package import Package
Expand Down Expand Up @@ -56,14 +54,3 @@ def find_best_candidate(
package = candidate

return package

def find_recommended_require_version(self, package: Package) -> str:
version = package.version

return self._transform_version(version.text, package.pretty_version)

def _transform_version(self, version: str, pretty_version: str) -> str:
try:
return f"^{Version.parse(version).to_string()}"
except ValueError:
return pretty_version