Skip to content

Commit c598cfb

Browse files
committed
Various small fixups
1 parent 545462d commit c598cfb

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/pip_sync_faster/main.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,30 @@
33
import os
44
import sys
55
from argparse import ArgumentParser
6-
from functools import lru_cache
6+
from functools import cached_property
77
from importlib.metadata import version
88
from pathlib import Path
99
from subprocess import CalledProcessError, run
1010

1111

1212
class SrcFile:
1313
def __init__(self, path):
14-
self._path = path
14+
self.path = path
1515

16-
@property
17-
@lru_cache
18-
def path(self):
19-
return self._path
20-
21-
@property
22-
@lru_cache
16+
@cached_property
2317
def abspath(self):
24-
return os.path.abspath(self._path)
18+
return os.path.abspath(self.path)
2519

26-
@property
27-
@lru_cache
20+
@cached_property
2821
def contents_hash(self):
22+
hash_ = hashlib.sha512()
2923
with open(self.abspath, "rb") as file:
30-
hash_ = hashlib.sha512()
3124
hash_.update(file.read())
32-
return hash_.hexdigest()
25+
return hash_.hexdigest()
3326

3427

3528
def pip_sync_maybe(src_files, args):
36-
virtualenv = Path(os.environ["VIRTUAL_ENV"])
37-
cached_hashes_path = virtualenv / "pip_sync_faster.json"
29+
cached_hashes_path = Path(os.environ["VIRTUAL_ENV"]) / "pip_sync_faster.json"
3830

3931
try:
4032
with open(cached_hashes_path, "r", encoding="utf8") as cached_hashes_file:
@@ -58,15 +50,15 @@ def pip_sync_maybe(src_files, args):
5850
except CalledProcessError as err:
5951
sys.exit(err.returncode)
6052
else:
53+
# pip-sync succeeded so update the cache.
6154
for src_file in src_files:
6255
cached_hashes[src_file.abspath] = src_file.contents_hash
6356

64-
# pip-sync succeeded so update the cache.
6557
with open(cached_hashes_path, "w", encoding="utf8") as cached_hashes_file:
6658
json.dump(cached_hashes, cached_hashes_file)
6759

6860

69-
def entry_point(): # pragma: nocover
61+
def entry_point():
7062
parser = ArgumentParser()
7163
parser.add_argument("--version", action="store_true")
7264
parser.add_argument("src_files", nargs="*")

0 commit comments

Comments
 (0)