Python cleanup v2#17
Merged
wouterl merged 8 commits intoDP-3T:masterfrom Apr 28, 2020
Merged
Conversation
There is no 'test_requires' argument to setuptools.setup(). Instead, pass extras_require with appropriate keys for the other kinds of dependencies. Add the development dependencies outlined in README.md. All dependencies can now be installed with: pip install -e .[dev,test]
The example code under examples/ also function as valuable tests. This adds a tests/test_examples.py file that runs each example script under examples/ as a separate test case. For the examples, we simply consider a zero exit code to signal that the examples completed successfully. A non-zero exit causes a test failure.
…nd line With pre-commit, flake8 is automatically run only on the diff to be committed. However, when invoking `flake8` from the command line, the current config covers all python files found in the entire repository, including third-party packages in venv. This patch teaches flake8 to exclude the venv directory as well as any dotfiles when run from the command line.
We need to provide cryptographically secure random shuffling.
Looking at Python's implementation of random.shuffle()[1], we see that
(a) it is a straightforward implementation of Durstenfeld's shuffle
algorithm[2] (which is as unbiased as its random number source), and
(b) it allows for a custom `random` function to be passed in.
Hence, AFAICS, we should get a cryptographically secure shuffle as long
as we pass in a `random` function that itself is cryptographically
secure.
Quoting the documentation of the secrets module:
The secrets module provides access to the most secure source of
randomness that your operating system provides.
class secrets.SystemRandom
A class for generating random numbers using the highest-quality
sources provided by the operating system.
Therefore, the best we can do is AFAICS to simply use the `random`
function available from secrets.SystemRandom class.
[1]: https://github.com/python/cpython/blob/v3.6.10rc1/Lib/random.py#L263
[2]: https://en.wikipedia.org/wiki/Fisher–Yates_shuffle#The_modern_algorithm
[3]: https://docs.python.org/3.6/library/secrets.html#random-numbers
wouterl
reviewed
Apr 28, 2020
Requested-by: Wouter Lueks <wouter.lueks@epfl.ch>
Collaborator
|
Fantastic!! Many thanks for the nice code and cleanups. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resubmit some initial cleanup patches on top of the rewritten codebase.