Skip to content

Commit

Permalink
chore: move get_version to utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-fs committed Oct 9, 2023
1 parent c1b9496 commit ae92513
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
15 changes: 1 addition & 14 deletions src/pybuild_deps/compile_build_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,9 @@
from pip._internal.req.constructors import install_req_from_req_string
from piptools.repositories import PyPIRepository
from piptools.resolver import BacktrackingResolver
from piptools.utils import (
is_pinned_requirement,
)

from .exceptions import PyBuildDepsError
from .finder import find_build_dependencies


def get_version(ireq: InstallRequirement):
"""Get version string from InstallRequirement."""
if not is_pinned_requirement(ireq):
raise PyBuildDepsError(
f"requirement '{ireq}' is not exact "
"(pybuild-tools only supports pinned dependencies)."
)
return next(iter(ireq.specifier)).version
from .utils import get_version


class BuildDependencyCompiler:
Expand Down
16 changes: 16 additions & 0 deletions src/pybuild_deps/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""utilities module."""

from pip._internal.req import InstallRequirement
from piptools.utils import is_pinned_requirement

from pybuild_deps.exceptions import PyBuildDepsError


def get_version(ireq: InstallRequirement):
"""Get version string from InstallRequirement."""
if not is_pinned_requirement(ireq):
raise PyBuildDepsError(
f"requirement '{ireq}' is not exact "
"(pybuild-tools only supports pinned dependencies)."
)
return next(iter(ireq.specifier)).version

0 comments on commit ae92513

Please sign in to comment.