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 Aug 31, 2024
1 parent e8ed56d commit 5ce8bc9
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(

Check warning on line 98 in hatch_pip_compile/lock.py

View check run for this annotation

Codecov / codecov/patch

hatch_pip_compile/lock.py#L98

Added line #L98 was not covered by tests
"[hatch-pip-compile] Non hatch-pip-compile lock file detected (%s)",
self.environment.piptools_lock_file.name,
)
return None

Check warning on line 102 in hatch_pip_compile/lock.py

View check run for this annotation

Codecov / codecov/patch

hatch_pip_compile/lock.py#L102

Added line #L102 was not covered by tests
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

Check warning on line 117 in hatch_pip_compile/lock.py

View check run for this annotation

Codecov / codecov/patch

hatch_pip_compile/lock.py#L117

Added line #L117 was not covered by tests
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 5ce8bc9

Please sign in to comment.