Skip to content

Commit

Permalink
🐛 allow pre-existing lockfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Sep 5, 2024
1 parent e8ed56d commit ab7177e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hatch_pip_compile/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from piptools._compat.pip_compat import PipSession, parse_requirements

from hatch_pip_compile.base import HatchPipCompileBase
from hatch_pip_compile.exceptions import LockFileError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -87,7 +86,7 @@ def current_python_version(self) -> Version:
raise NotImplementedError(msg)

@property
def lock_file_version(self) -> Version:
def lock_file_version(self) -> Version | None:
"""
Get lock file version
"""
Expand All @@ -96,8 +95,11 @@ def lock_file_version(self) -> Version:
r"# This file is autogenerated by hatch-pip-compile with Python (.*)", lock_file_text
)
if match is None:
msg = "Could not find lock file python version"
raise LockFileError(msg)
logger.error(
"[hatch-pip-compile] Non hatch-pip-compile lock file detected (%s)",
self.environment.piptools_lock_file.name,
)
return None
return Version(match.group(1))

def compare_python_versions(self, verbose: bool | None = None) -> bool:
Expand All @@ -111,6 +113,8 @@ def compare_python_versions(self, verbose: bool | None = None) -> bool:
which will print the warning. Used as a plugin flag.
"""
lock_version = self.lock_file_version
if lock_version is None:
return False
current_version = self.current_python_version
match = (current_version.major == lock_version.major) and (
current_version.minor == lock_version.minor
Expand Down

0 comments on commit ab7177e

Please sign in to comment.