Skip to content

Commit

Permalink
Fix file_target._md4 (close #1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoPeng committed Feb 16, 2024
1 parent 2c976c7 commit dccf067
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/sos/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
import fasteners
import pkg_resources

from .controller import (request_answer_from_controller,
send_message_to_controller)
from .controller import (request_answer_from_controller, send_message_to_controller)
from .eval import get_config, interpolate
from .pattern import extract_pattern
from .utils import (Error, env, fileMD5, objectMD5, pickleable, short_repr,
stable_repr, textMD5)
from .utils import (Error, env, fileMD5, objectMD5, pickleable, short_repr, stable_repr, textMD5)

__all__ = ["dynamic", "executable", "env_variable", "sos_variable"]

Expand Down Expand Up @@ -533,10 +531,12 @@ def __init__(self, *args, **kwargs):
# this is path segments
super().__init__(*args, **kwargs)
if len(args) == 1 and isinstance(args[0], file_target):
self._md5 = args[0]._md5
self._md5 = args[0]._md5 if hasattr(args[0], '_md5') else None
else:
self._md5 = None

# this only works for Python 3.9. Starting from 3.10, newly constructed file_target
# from calls such as file_target().with_suffix() will not have _md5
def _init(self, template=None):
super()._init(template)
self._md5 = None
Expand Down Expand Up @@ -574,6 +574,8 @@ def target_name(self):

def target_signature(self):
"""Return file signature"""
if not hasattr(self, '_md5'):
self._md5 = None
full_md5 = env.config['sig_type'] == 'md5'
if self.exists():
if full_md5:
Expand Down Expand Up @@ -602,6 +604,8 @@ def sig_file(self):

def validate(self, sig=None):
"""Check if file matches its signature"""
if not hasattr(self, '_md5'):
self._md5 = None
if env.config['sig_type'] == 'md5':
md5_file = self + '.md5'
if md5_file.exists():
Expand Down Expand Up @@ -632,6 +636,8 @@ def validate(self, sig=None):

def write_sig(self):
"""Write signature to sig store"""
if not hasattr(self, '_md5'):
self._md5 = None
if not self._md5:
self._md5 = fileMD5(self)
with open(self.sig_file(), "w") as sig:
Expand All @@ -657,7 +663,7 @@ def __reduce__(self):
self.__class__,
super().__reduce__()[1],
{
"_md5": self._md5,
"_md5": self._md5 if hasattr(self, '_md5') else None,
"_dict": self._dict
},
])
Expand Down Expand Up @@ -1245,7 +1251,6 @@ def remove_targets(self, type, kept=None):
).set(**grp._dict)
return self


def group_with(self, name, properties):
if not self._groups:
self._group(by="all")
Expand Down

0 comments on commit dccf067

Please sign in to comment.