-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.18.0 adding code hash sum #48
Changes from 7 commits
4096eac
2366e1e
e4a06a5
44df822
8856747
e42a67e
490f965
9f7e51c
b9267f9
e4e674e
a1d2e33
63fa681
a666828
30593ef
e588b3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "2.17.1" | ||
__version__ = "2.17.2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
* MassCutHelper | ||
""" | ||
|
||
import subprocess | ||
import math | ||
import string | ||
import re, os | ||
|
@@ -53,6 +54,9 @@ | |
from . import algodist | ||
from . import __version__ | ||
|
||
import hashlib | ||
from glob import glob | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Precompiled regular expressions | ||
# ----------------------------------------------------------------------------- | ||
|
@@ -251,6 +255,30 @@ def bx_encode_4_array(value: int) -> str: | |
""" | ||
return format([2, 1, 0, -1, -2].index(value), 'd') | ||
|
||
def get_files_hash_value(dir_path): | ||
"""Calculate hash value of the content of all .py and .vhd files in 'dir_path'. | ||
""" | ||
py_files = dir_path+"/**/*.py" | ||
vhd_files = dir_path+"/**/*.vhd" | ||
|
||
x = hashlib.sha256() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not understand! Why is "h" better than "x"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
filename = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
for filename_py in glob(py_files, recursive=True): | ||
filename.append(filename_py) | ||
for filename_vhd in glob(vhd_files, recursive=True): | ||
filename.append(filename_vhd) | ||
for i in range(0, len(filename)): | ||
with open(filename[i], 'rb') as f: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need for a range iterator. for filename in filenames:
with open(filename, "rb") as f:
... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
while True: | ||
# Reading is buffered, so we can read smaller chunks. | ||
chunk = f.read(x.block_size) | ||
if not chunk: | ||
break | ||
x.update(chunk) | ||
|
||
return x.hexdigest() | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Factories | ||
|
@@ -355,7 +383,10 @@ def __init__(self, collection): | |
self.scale_set = eventSetup.getScaleSetName() | ||
self.version = VersionHelper(tmEventSetup.__version__) | ||
self.sw_version = VersionHelper(__version__) | ||
|
||
# hash value of all .py and .vhd files in directory "tmVhdlProducer" recursively | ||
file_path = os.path.dirname(__file__) | ||
self.files_hash_value = get_files_hash_value(file_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to avoid calculating the hash multiple times, this gives potential for discrepancies and introduces an overhead. Try to calculate the hash once in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
class ModuleHelper(VhdlHelper): | ||
"""Module template helper. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculating the software hash is not part of the resource distribution, consider moving this into module
vhdlproducer
or__main__
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved get_files_hash_value to constants.py to avoid circular references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
constants
module is not ideal, I moved the code to the__main__
module (entry point for hash calculation).