Skip to content

Commit

Permalink
performance: cache parsed constraints and versions
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Feb 19, 2023
1 parent c218dde commit 42b5daa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/poetry/core/constraints/generic/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import functools
import re

from typing import TYPE_CHECKING
Expand All @@ -17,6 +18,7 @@
BASIC_CONSTRAINT = re.compile(r"^(!?==?)?\s*([^\s]+?)\s*$")


@functools.lru_cache(maxsize=None)
def parse_constraint(constraints: str) -> BaseConstraint:
if constraints == "*":
return AnyConstraint()
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/core/constraints/version/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import functools
import re

from typing import TYPE_CHECKING
Expand All @@ -12,6 +13,7 @@
from poetry.core.constraints.version.version_constraint import VersionConstraint


@functools.lru_cache(maxsize=None)
def parse_constraint(constraints: str) -> VersionConstraint:
if constraints == "*":
from poetry.core.constraints.version.version_range import VersionRange
Expand Down
2 changes: 2 additions & 0 deletions src/poetry/core/version/pep440/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import functools
import re

from typing import TYPE_CHECKING
Expand Down Expand Up @@ -63,6 +64,7 @@ def _get_local(cls, match: Match[str] | None) -> LocalSegmentType | None:
)

@classmethod
@functools.lru_cache(maxsize=None)
def parse(cls, value: str, version_class: type[T]) -> T:
match = cls._regex.search(value) if value else None
if not match:
Expand Down

0 comments on commit 42b5daa

Please sign in to comment.