Skip to content

Commit ba57353

Browse files
committed
[GR-43924] Add patches to run hypothesis.
PullRequest: graalpython/2621
2 parents e6abc3b + fbfa4c1 commit ba57353

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
diff --git a/hypothesis/internal/compat.py b/hypothesis/internal/compat.py
2+
index 8732201a0..054da90d8 100644
3+
--- a/hypothesis/internal/compat.py
4+
+++ b/hypothesis/internal/compat.py
5+
@@ -94,6 +94,7 @@ else:
6+
Concatenate, ParamSpec = None, None
7+
8+
PYPY = platform.python_implementation() == "PyPy"
9+
+GRAALPY = platform.python_implementation() == "GraalVM"
10+
WINDOWS = platform.system() == "Windows"
11+
12+
13+
diff --git a/hypothesis/internal/entropy.py b/hypothesis/internal/entropy.py
14+
index bf7f3a9f0..a805062ca 100644
15+
--- a/hypothesis/internal/entropy.py
16+
+++ b/hypothesis/internal/entropy.py
17+
@@ -19,7 +19,7 @@ from weakref import WeakValueDictionary
18+
19+
import hypothesis.core
20+
from hypothesis.errors import HypothesisWarning, InvalidArgument
21+
-from hypothesis.internal.compat import PYPY
22+
+from hypothesis.internal.compat import PYPY, GRAALPY
23+
24+
if TYPE_CHECKING:
25+
if sys.version_info >= (3, 8):
26+
@@ -59,7 +59,7 @@ class NumpyRandomWrapper:
27+
NP_RANDOM = None
28+
29+
30+
-if not PYPY:
31+
+if not (PYPY or GRAALPY):
32+
33+
def _get_platform_base_refcount(r: Any) -> int:
34+
return sys.getrefcount(r)
35+
@@ -68,7 +68,7 @@ if not PYPY:
36+
# the given platform / version of Python.
37+
_PLATFORM_REF_COUNT = _get_platform_base_refcount(object())
38+
else: # pragma: no cover
39+
- # PYPY doesn't have `sys.getrefcount`
40+
+ # PYPY and GRAALPY don't have `sys.getrefcount`
41+
_PLATFORM_REF_COUNT = -1
42+
43+
44+
@@ -118,8 +118,8 @@ def register_random(r: RandomLike) -> None:
45+
if r in RANDOMS_TO_MANAGE.values():
46+
return
47+
48+
- if not PYPY: # pragma: no branch
49+
- # PYPY does not have `sys.getrefcount`
50+
+ if not (PYPY or GRAALPY): # pragma: no branch
51+
+ # PYPY and GRAALPY do not have `sys.getrefcount`
52+
gc.collect()
53+
if not gc.get_referrers(r):
54+
if sys.getrefcount(r) <= _PLATFORM_REF_COUNT:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
diff --git a/hypothesis/internal/compat.py b/hypothesis/internal/compat.py
2+
index 8732201a0..054da90d8 100644
3+
--- a/hypothesis/internal/compat.py
4+
+++ b/hypothesis/internal/compat.py
5+
@@ -94,6 +94,7 @@ else:
6+
Concatenate, ParamSpec = None, None
7+
8+
PYPY = platform.python_implementation() == "PyPy"
9+
+GRAALPY = platform.python_implementation() == "GraalVM"
10+
WINDOWS = platform.system() == "Windows"
11+
12+
13+
diff --git a/hypothesis/internal/entropy.py b/hypothesis/internal/entropy.py
14+
index bf7f3a9f0..a805062ca 100644
15+
--- a/hypothesis/internal/entropy.py
16+
+++ b/hypothesis/internal/entropy.py
17+
@@ -19,7 +19,7 @@ from weakref import WeakValueDictionary
18+
19+
import hypothesis.core
20+
from hypothesis.errors import HypothesisWarning, InvalidArgument
21+
-from hypothesis.internal.compat import PYPY
22+
+from hypothesis.internal.compat import PYPY, GRAALPY
23+
24+
if TYPE_CHECKING:
25+
if sys.version_info >= (3, 8):
26+
@@ -59,7 +59,7 @@ class NumpyRandomWrapper:
27+
NP_RANDOM = None
28+
29+
30+
-if not PYPY:
31+
+if not (PYPY or GRAALPY):
32+
33+
def _get_platform_base_refcount(r: Any) -> int:
34+
return sys.getrefcount(r)
35+
@@ -68,7 +68,7 @@ if not PYPY:
36+
# the given platform / version of Python.
37+
_PLATFORM_REF_COUNT = _get_platform_base_refcount(object())
38+
else: # pragma: no cover
39+
- # PYPY doesn't have `sys.getrefcount`
40+
+ # PYPY and GRAALPY don't have `sys.getrefcount`
41+
_PLATFORM_REF_COUNT = -1
42+
43+
44+
@@ -118,8 +118,8 @@ def register_random(r: RandomLike) -> None:
45+
if r in RANDOMS_TO_MANAGE.values():
46+
return
47+
48+
- if not PYPY: # pragma: no branch
49+
- # PYPY does not have `sys.getrefcount`
50+
+ if not (PYPY or GRAALPY): # pragma: no branch
51+
+ # PYPY and GRAALPY do not have `sys.getrefcount`
52+
gc.collect()
53+
if not gc.get_referrers(r):
54+
if sys.getrefcount(r) <= _PLATFORM_REF_COUNT:

mx.graalpython/mx_graalpython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ def _python_checkpatchfiles():
17801780
allowed_licenses = [
17811781
"MIT", "BSD", "BSD-3-Clause", "BSD 3-Clause License", "BSD or Apache License, Version 2.0",
17821782
"MIT license", "PSF", "BSD-3-Clause OR Apache-2.0", "Apache", "Apache License", "new BSD",
1783-
"(Apache-2.0 OR BSD-3-Clause) AND PSF-2.0", "Apache 2.0",
1783+
"(Apache-2.0 OR BSD-3-Clause) AND PSF-2.0", "Apache 2.0", "MPL-2.0",
17841784
]
17851785
for line in content.split("\n"):
17861786
if not line or os.stat(line).st_size == 0:

0 commit comments

Comments
 (0)