-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-110932: Fix regrtest for SOURCE_DATE_EPOCH #111143
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
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -129,14 +129,19 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False): | |||||
|
||||||
# Randomize | ||||||
self.randomize: bool = ns.randomize | ||||||
self.random_seed: int | None = ( | ||||||
ns.random_seed | ||||||
if ns.random_seed is not None | ||||||
else random.getrandbits(32) | ||||||
) | ||||||
if 'SOURCE_DATE_EPOCH' in os.environ: | ||||||
if ('SOURCE_DATE_EPOCH' in os.environ | ||||||
# don't use the variable if empty | ||||||
and os.environ['SOURCE_DATE_EPOCH'] | ||||||
): | ||||||
self.randomize = False | ||||||
self.random_seed = None | ||||||
# SOURCE_DATE_EPOCH should be an integer, but use a string to not | ||||||
# fail if it's not integer. random.seed() accepts a string. | ||||||
# https://reproducible-builds.org/docs/source-date-epoch/ | ||||||
self.random_seed: int | str = os.environ['SOURCE_DATE_EPOCH'] | ||||||
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. Myabe we should always use 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. The reason is subtle. It avoids to import hashlib to convert a string to an integer in Random.seed(). Right now, hashlib is always imported, but I have a local branch to reduce the number of imports at Python startup. 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'm talking about the second code path, where we create a random seed as an integer. |
||||||
elif ns.random_seed is None: | ||||||
self.random_seed = random.getrandbits(32) | ||||||
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. If so, it would become:
Suggested change
|
||||||
else: | ||||||
self.random_seed = ns.random_seed | ||||||
|
||||||
# tests | ||||||
self.first_runtests: RunTests | None = None | ||||||
|
@@ -441,7 +446,7 @@ def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int: | |||||
or tests or self.cmdline_args)): | ||||||
display_header(self.use_resources, self.python_cmd) | ||||||
|
||||||
print("Using random seed", self.random_seed) | ||||||
print("Using random seed:", self.random_seed) | ||||||
|
||||||
runtests = self.create_run_tests(selected) | ||||||
self.first_runtests = runtests | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix regrtest if the ``SOURCE_DATE_EPOCH`` environment variable is defined: | ||
use the variable value as the random seed. Patch by Victor Stinner. |
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.
nit