-
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
Conversation
This is a significant change, consider incrementing the minor version for this feature, e.g. |
tmVhdlProducer/__init__.py
Outdated
@@ -1 +1 @@ | |||
__version__ = "2.17.1" | |||
__version__ = "2.17.2" |
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.
A proper version would be 2.18.0
as this is a new feature and not a bug fix.
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.
changed
tmVhdlProducer/algodist.py
Outdated
file_path = os.path.dirname(__file__) | ||
files_hash_value = vhdlhelper.get_files_hash_value(file_path) |
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).
tmVhdlProducer/vhdlhelper.py
Outdated
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 comment
The 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 __main__
and pass it like the __version__
variable.
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.
done
tmVhdlProducer/vhdlhelper.py
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
done
tmVhdlProducer/vhdlhelper.py
Outdated
|
||
x = hashlib.sha256() | ||
|
||
filename = [] |
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.
filenames = []
(plural for lists)
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.
done
tmVhdlProducer/vhdlhelper.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
h = hashlib.sha256()
or sha256_hash = hashlib.sha256()
would increase code readability (note hash
is a built in function, so try to avoid hash = hashlib.sha256()
).
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.
I do not understand! Why is "h" better than "x"?
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.
h
for hash. While x
is a perfectly valid variable name, it is quite generic and provides no hints about the variable's intended use. In contrast, h
or sha256_hash
offers immediate context. See also the Zen of Python's "Explicit is better than implicit" principle (PEP 20), https://peps.python.org/pep-0020/
added optional config dict to vhdlproducer
To enhance the hash calculation I moved the calculation to the To provide a flexible solution the value is passed in form of a generic tm-vhdlproducer/tmVhdlProducer/__main__.py Lines 234 to 235 in 30593ef
|
Adding hash of source and VHDL templates as additional meta tag.