-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move get_version to utils module
- Loading branch information
Showing
2 changed files
with
17 additions
and
14 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
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 |