Python-checkins
Threads by month
- ----- 2026 -----
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
October 2021
- 1 participants
- 537 discussions
Revert "Revert "bpo-45229: Make datetime tests discoverable (GH-28615). (GH-28645)" (GH-28660)" (GH-28666)
by serhiy-storchaka Oct. 1, 2021
by serhiy-storchaka Oct. 1, 2021
Oct. 1, 2021
https://github.com/python/cpython/commit/e9d5cdda1ffa369550a634a3ec220db934…
commit: e9d5cdda1ffa369550a634a3ec220db93433e0f4
branch: 3.9
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2021-10-01T10:58:59+03:00
summary:
Revert "Revert "bpo-45229: Make datetime tests discoverable (GH-28615). (GH-28645)" (GH-28660)" (GH-28666)
This reverts commit 2cf76cf4ccd177b8d6d2bf21b5462258ae87522d.
files:
M Lib/test/test_datetime.py
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index d659f369d54e4..c26dbe1063f41 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -1,57 +1,57 @@
import unittest
import sys
-from test.support import import_fresh_module, run_unittest
+from test.support import import_fresh_module
+
TESTS = 'test.datetimetester'
-try:
- pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
- blocked=['_datetime'])
- fast_tests = import_fresh_module(TESTS, fresh=['datetime',
- '_datetime', '_strptime'])
-finally:
- # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
- # XXX: but it does not, so we have to cleanup ourselves.
- for modname in ['datetime', '_datetime', '_strptime']:
- sys.modules.pop(modname, None)
-test_modules = [pure_tests, fast_tests]
-test_suffixes = ["_Pure", "_Fast"]
-# XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
-# not believe this, but in spite of all the sys.modules trickery running a _Pure
-# test last will leave a mix of pure and native datetime stuff lying around.
-all_test_classes = []
+def load_tests(loader, tests, pattern):
+ try:
+ pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
+ blocked=['_datetime'])
+ fast_tests = import_fresh_module(TESTS, fresh=['datetime',
+ '_datetime', '_strptime'])
+ finally:
+ # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
+ # XXX: but it does not, so we have to cleanup ourselves.
+ for modname in ['datetime', '_datetime', '_strptime']:
+ sys.modules.pop(modname, None)
-for module, suffix in zip(test_modules, test_suffixes):
- test_classes = []
- for name, cls in module.__dict__.items():
- if not isinstance(cls, type):
- continue
- if issubclass(cls, unittest.TestCase):
- test_classes.append(cls)
- elif issubclass(cls, unittest.TestSuite):
- suit = cls()
- test_classes.extend(type(test) for test in suit)
- test_classes = sorted(set(test_classes), key=lambda cls: cls.__qualname__)
- for cls in test_classes:
- cls.__name__ += suffix
- cls.__qualname__ += suffix
- @classmethod
- def setUpClass(cls_, module=module):
- cls_._save_sys_modules = sys.modules.copy()
- sys.modules[TESTS] = module
- sys.modules['datetime'] = module.datetime_module
- sys.modules['_strptime'] = module._strptime
- @classmethod
- def tearDownClass(cls_):
- sys.modules.clear()
- sys.modules.update(cls_._save_sys_modules)
- cls.setUpClass = setUpClass
- cls.tearDownClass = tearDownClass
- all_test_classes.extend(test_classes)
+ test_modules = [pure_tests, fast_tests]
+ test_suffixes = ["_Pure", "_Fast"]
+ # XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
+ # not believe this, but in spite of all the sys.modules trickery running a _Pure
+ # test last will leave a mix of pure and native datetime stuff lying around.
+ for module, suffix in zip(test_modules, test_suffixes):
+ test_classes = []
+ for name, cls in module.__dict__.items():
+ if not isinstance(cls, type):
+ continue
+ if issubclass(cls, unittest.TestCase):
+ test_classes.append(cls)
+ elif issubclass(cls, unittest.TestSuite):
+ suit = cls()
+ test_classes.extend(type(test) for test in suit)
+ test_classes = sorted(set(test_classes), key=lambda cls: cls.__qualname__)
+ for cls in test_classes:
+ cls.__name__ += suffix
+ cls.__qualname__ += suffix
+ @classmethod
+ def setUpClass(cls_, module=module):
+ cls_._save_sys_modules = sys.modules.copy()
+ sys.modules[TESTS] = module
+ sys.modules['datetime'] = module.datetime_module
+ sys.modules['_strptime'] = module._strptime
+ @classmethod
+ def tearDownClass(cls_):
+ sys.modules.clear()
+ sys.modules.update(cls_._save_sys_modules)
+ cls.setUpClass = setUpClass
+ cls.tearDownClass = tearDownClass
+ tests.addTests(loader.loadTestsFromTestCase(cls))
+ return tests
-def test_main():
- run_unittest(*all_test_classes)
if __name__ == "__main__":
- test_main()
+ unittest.main()
1
0
Revert "Revert "bpo-45229: Make datetime tests discoverable (GH-28615)" (GH-28650)" (GH-28667)
by serhiy-storchaka Oct. 1, 2021
by serhiy-storchaka Oct. 1, 2021
Oct. 1, 2021
https://github.com/python/cpython/commit/2f205920127bd93eebed044cb1b6183476…
commit: 2f205920127bd93eebed044cb1b61834764478ba
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2021-10-01T10:57:58+03:00
summary:
Revert "Revert "bpo-45229: Make datetime tests discoverable (GH-28615)" (GH-28650)" (GH-28667)
This reverts commit b07fddd527efe67174ce6b0fdbe8dac390b16e4e.
files:
M Lib/test/test_datetime.py
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index bdb9f02e5756a..7f9094fa7bd4e 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -1,59 +1,57 @@
import unittest
import sys
-from test.support import run_unittest
from test.support.import_helper import import_fresh_module
TESTS = 'test.datetimetester'
-try:
- pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
- blocked=['_datetime'])
- fast_tests = import_fresh_module(TESTS, fresh=['datetime',
- '_datetime', '_strptime'])
-finally:
- # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
- # XXX: but it does not, so we have to cleanup ourselves.
- for modname in ['datetime', '_datetime', '_strptime']:
- sys.modules.pop(modname, None)
-test_modules = [pure_tests, fast_tests]
-test_suffixes = ["_Pure", "_Fast"]
-# XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
-# not believe this, but in spite of all the sys.modules trickery running a _Pure
-# test last will leave a mix of pure and native datetime stuff lying around.
-all_test_classes = []
+def load_tests(loader, tests, pattern):
+ try:
+ pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
+ blocked=['_datetime'])
+ fast_tests = import_fresh_module(TESTS, fresh=['datetime',
+ '_datetime', '_strptime'])
+ finally:
+ # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
+ # XXX: but it does not, so we have to cleanup ourselves.
+ for modname in ['datetime', '_datetime', '_strptime']:
+ sys.modules.pop(modname, None)
-for module, suffix in zip(test_modules, test_suffixes):
- test_classes = []
- for name, cls in module.__dict__.items():
- if not isinstance(cls, type):
- continue
- if issubclass(cls, unittest.TestCase):
- test_classes.append(cls)
- elif issubclass(cls, unittest.TestSuite):
- suit = cls()
- test_classes.extend(type(test) for test in suit)
- test_classes = sorted(set(test_classes), key=lambda cls: cls.__qualname__)
- for cls in test_classes:
- cls.__name__ += suffix
- cls.__qualname__ += suffix
- @classmethod
- def setUpClass(cls_, module=module):
- cls_._save_sys_modules = sys.modules.copy()
- sys.modules[TESTS] = module
- sys.modules['datetime'] = module.datetime_module
- sys.modules['_strptime'] = module._strptime
- @classmethod
- def tearDownClass(cls_):
- sys.modules.clear()
- sys.modules.update(cls_._save_sys_modules)
- cls.setUpClass = setUpClass
- cls.tearDownClass = tearDownClass
- all_test_classes.extend(test_classes)
+ test_modules = [pure_tests, fast_tests]
+ test_suffixes = ["_Pure", "_Fast"]
+ # XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
+ # not believe this, but in spite of all the sys.modules trickery running a _Pure
+ # test last will leave a mix of pure and native datetime stuff lying around.
+ for module, suffix in zip(test_modules, test_suffixes):
+ test_classes = []
+ for name, cls in module.__dict__.items():
+ if not isinstance(cls, type):
+ continue
+ if issubclass(cls, unittest.TestCase):
+ test_classes.append(cls)
+ elif issubclass(cls, unittest.TestSuite):
+ suit = cls()
+ test_classes.extend(type(test) for test in suit)
+ test_classes = sorted(set(test_classes), key=lambda cls: cls.__qualname__)
+ for cls in test_classes:
+ cls.__name__ += suffix
+ cls.__qualname__ += suffix
+ @classmethod
+ def setUpClass(cls_, module=module):
+ cls_._save_sys_modules = sys.modules.copy()
+ sys.modules[TESTS] = module
+ sys.modules['datetime'] = module.datetime_module
+ sys.modules['_strptime'] = module._strptime
+ @classmethod
+ def tearDownClass(cls_):
+ sys.modules.clear()
+ sys.modules.update(cls_._save_sys_modules)
+ cls.setUpClass = setUpClass
+ cls.tearDownClass = tearDownClass
+ tests.addTests(loader.loadTestsFromTestCase(cls))
+ return tests
-def test_main():
- run_unittest(*all_test_classes)
if __name__ == "__main__":
- test_main()
+ unittest.main()
1
0
Oct. 1, 2021
https://github.com/python/cpython/commit/eb4495e8e275c83d691add116c4f2b74e7…
commit: eb4495e8e275c83d691add116c4f2b74e73e3cc8
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2021-10-01T10:56:32+03:00
summary:
bpo-45310: Fix parrallel shared memory tests (GH-28661)
Add a PID to names of POSIX shared memory objects to allow
running multiprocessing tests (test_multiprocessing_fork,
test_multiprocessing_spawn, etc) in parallel.
files:
M Lib/test/_test_multiprocessing.py
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 125e8906d8abc..9e0d18da50f6e 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3773,12 +3773,19 @@ def _attach_existing_shmem_then_write(shmem_name_or_obj, binary_data):
local_sms.buf[:len(binary_data)] = binary_data
local_sms.close()
+ def _new_shm_name(self, prefix):
+ # Add a PID to the name of a POSIX shared memory object to allow
+ # running multiprocessing tests (test_multiprocessing_fork,
+ # test_multiprocessing_spawn, etc) in parallel.
+ return prefix + str(os.getpid())
+
def test_shared_memory_basics(self):
- sms = shared_memory.SharedMemory('test01_tsmb', create=True, size=512)
+ name_tsmb = self._new_shm_name('test01_tsmb')
+ sms = shared_memory.SharedMemory(name_tsmb, create=True, size=512)
self.addCleanup(sms.unlink)
# Verify attributes are readable.
- self.assertEqual(sms.name, 'test01_tsmb')
+ self.assertEqual(sms.name, name_tsmb)
self.assertGreaterEqual(sms.size, 512)
self.assertGreaterEqual(len(sms.buf), sms.size)
@@ -3798,12 +3805,12 @@ def test_shared_memory_basics(self):
self.assertEqual(sms.buf[0], 42)
# Attach to existing shared memory segment.
- also_sms = shared_memory.SharedMemory('test01_tsmb')
+ also_sms = shared_memory.SharedMemory(name_tsmb)
self.assertEqual(also_sms.buf[0], 42)
also_sms.close()
# Attach to existing shared memory segment but specify a new size.
- same_sms = shared_memory.SharedMemory('test01_tsmb', size=20*sms.size)
+ same_sms = shared_memory.SharedMemory(name_tsmb, size=20*sms.size)
self.assertLess(same_sms.size, 20*sms.size) # Size was ignored.
same_sms.close()
@@ -3821,7 +3828,7 @@ def test_shared_memory_basics(self):
'multiprocessing.shared_memory._make_filename') as mock_make_filename:
NAME_PREFIX = shared_memory._SHM_NAME_PREFIX
- names = ['test01_fn', 'test02_fn']
+ names = [self._new_shm_name('test01_fn'), self._new_shm_name('test02_fn')]
# Prepend NAME_PREFIX which can be '/psm_' or 'wnsm_', necessary
# because some POSIX compliant systems require name to start with /
names = [NAME_PREFIX + name for name in names]
@@ -3843,17 +3850,17 @@ def test_shared_memory_basics(self):
# manages unlinking on its own and unlink() does nothing).
# True release of shared memory segment does not necessarily
# happen until process exits, depending on the OS platform.
+ name_dblunlink = self._new_shm_name('test01_dblunlink')
+ sms_uno = shared_memory.SharedMemory(
+ name_dblunlink,
+ create=True,
+ size=5000
+ )
with self.assertRaises(FileNotFoundError):
- sms_uno = shared_memory.SharedMemory(
- 'test01_dblunlink',
- create=True,
- size=5000
- )
-
try:
self.assertGreaterEqual(sms_uno.size, 5000)
- sms_duo = shared_memory.SharedMemory('test01_dblunlink')
+ sms_duo = shared_memory.SharedMemory(name_dblunlink)
sms_duo.unlink() # First shm_unlink() call.
sms_duo.close()
sms_uno.close()
@@ -3865,7 +3872,7 @@ def test_shared_memory_basics(self):
# Attempting to create a new shared memory segment with a
# name that is already in use triggers an exception.
there_can_only_be_one_sms = shared_memory.SharedMemory(
- 'test01_tsmb',
+ name_tsmb,
create=True,
size=512
)
@@ -3879,7 +3886,7 @@ def test_shared_memory_basics(self):
# case of MacOS/darwin, requesting a smaller size is disallowed.
class OptionalAttachSharedMemory(shared_memory.SharedMemory):
_flags = os.O_CREAT | os.O_RDWR
- ok_if_exists_sms = OptionalAttachSharedMemory('test01_tsmb')
+ ok_if_exists_sms = OptionalAttachSharedMemory(name_tsmb)
self.assertEqual(ok_if_exists_sms.size, sms.size)
ok_if_exists_sms.close()
@@ -4084,10 +4091,11 @@ def test_shared_memory_ShareableList_basics(self):
self.assertEqual(sl.count(b'adios'), 0)
# Exercise creating a duplicate.
- sl_copy = shared_memory.ShareableList(sl, name='test03_duplicate')
+ name_duplicate = self._new_shm_name('test03_duplicate')
+ sl_copy = shared_memory.ShareableList(sl, name=name_duplicate)
try:
self.assertNotEqual(sl.shm.name, sl_copy.shm.name)
- self.assertEqual('test03_duplicate', sl_copy.shm.name)
+ self.assertEqual(name_duplicate, sl_copy.shm.name)
self.assertEqual(list(sl), list(sl_copy))
self.assertEqual(sl.format, sl_copy.format)
sl_copy[-1] = 77
1
0
Oct. 1, 2021
https://github.com/python/cpython/commit/1ee0f94d16f150356a4b9b0a39d44ba1d2…
commit: 1ee0f94d16f150356a4b9b0a39d44ba1d2d5b9fc
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2021-10-01T09:55:28+02:00
summary:
bpo-41710: PyThread_acquire_lock_timed() uses sem_clockwait() (GH-28662)
On Unix, if the sem_clockwait() function is available in the C
library (glibc 2.30 and newer), the threading.Lock.acquire() method
now uses the monotonic clock (time.CLOCK_MONOTONIC) for the timeout,
rather than using the system clock (time.CLOCK_REALTIME), to not be
affected by system clock changes.
configure now checks if the sem_clockwait() function is available.
files:
A Misc/NEWS.d/next/Library/2021-09-30-23-00-18.bpo-41710.svuloZ.rst
M Doc/whatsnew/3.11.rst
M Python/thread_pthread.h
M configure
M configure.ac
M pyconfig.h.in
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index d01d2e263199a..ff376d231bafa 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -239,6 +239,16 @@ sqlite3
(Contributed by Aviv Palivoda, Daniel Shahaf, and Erlend E. Aasland in
:issue:`16379`.)
+threading
+---------
+
+* On Unix, if the ``sem_clockwait()`` function is available in the C library
+ (glibc 2.30 and newer), the :meth:`threading.Lock.acquire` method now uses
+ the monotonic clock (:data:`time.CLOCK_MONOTONIC`) for the timeout, rather
+ than using the system clock (:data:`time.CLOCK_REALTIME`), to not be affected
+ by system clock changes.
+ (Contributed by Livius and Victor Stinner in :issue:`41710`.)
+
time
----
diff --git a/Misc/NEWS.d/next/Library/2021-09-30-23-00-18.bpo-41710.svuloZ.rst b/Misc/NEWS.d/next/Library/2021-09-30-23-00-18.bpo-41710.svuloZ.rst
new file mode 100644
index 0000000000000..d8a4f9507c189
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-09-30-23-00-18.bpo-41710.svuloZ.rst
@@ -0,0 +1,5 @@
+On Unix, if the ``sem_clockwait()`` function is available in the C library
+(glibc 2.30 and newer), the :meth:`threading.Lock.acquire` method now uses the
+monotonic clock (:data:`time.CLOCK_MONOTONIC`) for the timeout, rather than
+using the system clock (:data:`time.CLOCK_REALTIME`), to not be affected by
+system clock changes. Patch by Victor Stinner.
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
index 3815ffae20c01..9b5e273f1a8ba 100644
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -92,7 +92,7 @@
* mutexes and condition variables:
*/
#if (defined(_POSIX_SEMAPHORES) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES) && \
- defined(HAVE_SEM_TIMEDWAIT))
+ (defined(HAVE_SEM_TIMEDWAIT) || defined(HAVE_SEM_CLOCKWAIT)))
# define USE_SEMAPHORES
#else
# undef USE_SEMAPHORES
@@ -461,17 +461,34 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
timeout = _PyTime_FromNanoseconds(-1);
}
+#ifdef HAVE_SEM_CLOCKWAIT
+ struct timespec abs_timeout;
+ // Local scope for deadline
+ {
+ _PyTime_t deadline = _PyTime_GetMonotonicClock() + timeout;
+ _PyTime_AsTimespec_clamp(deadline, &abs_timeout);
+ }
+#else
_PyTime_t deadline = 0;
- if (timeout > 0 && !intr_flag) {
+ if (timeout > 0
+ && !intr_flag
+ )
+ {
deadline = _PyTime_GetMonotonicClock() + timeout;
}
+#endif
while (1) {
if (timeout > 0) {
- _PyTime_t t = _PyTime_GetSystemClock() + timeout;
+#ifdef HAVE_SEM_CLOCKWAIT
+ status = fix_status(sem_clockwait(thelock, CLOCK_MONOTONIC,
+ &abs_timeout));
+#else
+ _PyTime_t abs_timeout = _PyTime_GetSystemClock() + timeout;
struct timespec ts;
- _PyTime_AsTimespec_clamp(t, &ts);
+ _PyTime_AsTimespec_clamp(abs_timeout, &ts);
status = fix_status(sem_timedwait(thelock, &ts));
+#endif
}
else if (timeout == 0) {
status = fix_status(sem_trywait(thelock));
@@ -486,6 +503,9 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
break;
}
+ // sem_clockwait() uses an absolute timeout, there is no need
+ // to recompute the relative timeout.
+#ifndef HAVE_SEM_CLOCKWAIT
if (timeout > 0) {
/* wait interrupted by a signal (EINTR): recompute the timeout */
_PyTime_t timeout = deadline - _PyTime_GetMonotonicClock();
@@ -494,17 +514,24 @@ PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds,
break;
}
}
+#endif
}
/* Don't check the status if we're stopping because of an interrupt. */
if (!(intr_flag && status == EINTR)) {
if (timeout > 0) {
- if (status != ETIMEDOUT)
+ if (status != ETIMEDOUT) {
+#ifdef HAVE_SEM_CLOCKWAIT
+ CHECK_STATUS("sem_clockwait");
+#else
CHECK_STATUS("sem_timedwait");
+#endif
+ }
}
else if (timeout == 0) {
- if (status != EAGAIN)
+ if (status != EAGAIN) {
CHECK_STATUS("sem_trywait");
+ }
}
else {
CHECK_STATUS("sem_wait");
diff --git a/configure b/configure
index 4acf91f22107f..75e2e296f10b1 100755
--- a/configure
+++ b/configure
@@ -9764,7 +9764,7 @@ then
BLDSHARED="$LDSHARED"
fi
;;
- Linux*|GNU*|QNX*|VxWorks*)
+ Linux*|GNU*|QNX*|VxWorks*|Haiku*)
LDSHARED='$(CC) -shared'
LDCXXSHARED='$(CXX) -shared';;
FreeBSD*)
@@ -9835,6 +9835,7 @@ then
Linux-android*) ;;
Linux*|GNU*) CCSHARED="-fPIC";;
FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) CCSHARED="-fPIC";;
+ Haiku*) CCSHARED="-fPIC";;
OpenUNIX*|UnixWare*)
if test "$GCC" = "yes"
then CCSHARED="-fPIC"
@@ -10562,6 +10563,48 @@ if test "x$ac_cv_lib_socket_socket" = xyes; then :
fi
# SVR4 sockets
+# Haiku system library
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket in -lnetwork" >&5
+$as_echo_n "checking for socket in -lnetwork... " >&6; }
+if ${ac_cv_lib_network_socket+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lnetwork $LIBS $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char socket ();
+int
+main ()
+{
+return socket ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_network_socket=yes
+else
+ ac_cv_lib_network_socket=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_network_socket" >&5
+$as_echo "$ac_cv_lib_network_socket" >&6; }
+if test "x$ac_cv_lib_network_socket" = xyes; then :
+ LIBS="-lnetwork $LIBS"
+fi
+
+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-libs" >&5
$as_echo_n "checking for --with-libs... " >&6; }
@@ -11774,7 +11817,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
posix_fallocate posix_fadvise posix_spawn posix_spawnp pread preadv preadv2 \
pthread_condattr_setclock pthread_init pthread_kill pwrite pwritev pwritev2 \
readlink readlinkat readv realpath renameat \
- sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
+ sem_open sem_timedwait sem_clockwait sem_getvalue sem_unlink sendfile setegid seteuid \
setgid sethostname \
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \
sched_get_priority_max sched_setaffinity sched_setscheduler sched_setparam \
@@ -13252,19 +13295,19 @@ fi
done
-for ac_func in clock_nanosleep
+for ac_func in clock_getres
do :
- ac_fn_c_check_func "$LINENO" "clock_nanosleep" "ac_cv_func_clock_nanosleep"
-if test "x$ac_cv_func_clock_nanosleep" = xyes; then :
+ ac_fn_c_check_func "$LINENO" "clock_getres" "ac_cv_func_clock_getres"
+if test "x$ac_cv_func_clock_getres" = xyes; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_CLOCK_NANOSLEEP 1
+#define HAVE_CLOCK_GETRES 1
_ACEOF
else
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_nanosleep in -lrt" >&5
-$as_echo_n "checking for clock_nanosleep in -lrt... " >&6; }
-if ${ac_cv_lib_rt_clock_nanosleep+:} false; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_getres in -lrt" >&5
+$as_echo_n "checking for clock_getres in -lrt... " >&6; }
+if ${ac_cv_lib_rt_clock_getres+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
@@ -13278,29 +13321,29 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
#ifdef __cplusplus
extern "C"
#endif
-char clock_nanosleep ();
+char clock_getres ();
int
main ()
{
-return clock_nanosleep ();
+return clock_getres ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_rt_clock_nanosleep=yes
+ ac_cv_lib_rt_clock_getres=yes
else
- ac_cv_lib_rt_clock_nanosleep=no
+ ac_cv_lib_rt_clock_getres=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_nanosleep" >&5
-$as_echo "$ac_cv_lib_rt_clock_nanosleep" >&6; }
-if test "x$ac_cv_lib_rt_clock_nanosleep" = xyes; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_getres" >&5
+$as_echo "$ac_cv_lib_rt_clock_getres" >&6; }
+if test "x$ac_cv_lib_rt_clock_getres" = xyes; then :
- $as_echo "#define HAVE_CLOCK_NANOSLEEP 1" >>confdefs.h
+ $as_echo "#define HAVE_CLOCK_GETRES 1" >>confdefs.h
fi
@@ -13310,19 +13353,19 @@ fi
done
-for ac_func in nanosleep
+for ac_func in clock_settime
do :
- ac_fn_c_check_func "$LINENO" "nanosleep" "ac_cv_func_nanosleep"
-if test "x$ac_cv_func_nanosleep" = xyes; then :
+ ac_fn_c_check_func "$LINENO" "clock_settime" "ac_cv_func_clock_settime"
+if test "x$ac_cv_func_clock_settime" = xyes; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_NANOSLEEP 1
+#define HAVE_CLOCK_SETTIME 1
_ACEOF
else
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nanosleep in -lrt" >&5
-$as_echo_n "checking for nanosleep in -lrt... " >&6; }
-if ${ac_cv_lib_rt_nanosleep+:} false; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_settime in -lrt" >&5
+$as_echo_n "checking for clock_settime in -lrt... " >&6; }
+if ${ac_cv_lib_rt_clock_settime+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
@@ -13336,29 +13379,29 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
#ifdef __cplusplus
extern "C"
#endif
-char nanosleep ();
+char clock_settime ();
int
main ()
{
-return nanosleep ();
+return clock_settime ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_rt_nanosleep=yes
+ ac_cv_lib_rt_clock_settime=yes
else
- ac_cv_lib_rt_nanosleep=no
+ ac_cv_lib_rt_clock_settime=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_nanosleep" >&5
-$as_echo "$ac_cv_lib_rt_nanosleep" >&6; }
-if test "x$ac_cv_lib_rt_nanosleep" = xyes; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_settime" >&5
+$as_echo "$ac_cv_lib_rt_clock_settime" >&6; }
+if test "x$ac_cv_lib_rt_clock_settime" = xyes; then :
- $as_echo "#define HAVE_NANOSLEEP 1" >>confdefs.h
+ $as_echo "#define HAVE_CLOCK_SETTIME 1" >>confdefs.h
fi
@@ -13368,19 +13411,19 @@ fi
done
-for ac_func in clock_getres
+for ac_func in clock_nanosleep
do :
- ac_fn_c_check_func "$LINENO" "clock_getres" "ac_cv_func_clock_getres"
-if test "x$ac_cv_func_clock_getres" = xyes; then :
+ ac_fn_c_check_func "$LINENO" "clock_nanosleep" "ac_cv_func_clock_nanosleep"
+if test "x$ac_cv_func_clock_nanosleep" = xyes; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_CLOCK_GETRES 1
+#define HAVE_CLOCK_NANOSLEEP 1
_ACEOF
else
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_getres in -lrt" >&5
-$as_echo_n "checking for clock_getres in -lrt... " >&6; }
-if ${ac_cv_lib_rt_clock_getres+:} false; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_nanosleep in -lrt" >&5
+$as_echo_n "checking for clock_nanosleep in -lrt... " >&6; }
+if ${ac_cv_lib_rt_clock_nanosleep+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
@@ -13394,29 +13437,29 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
#ifdef __cplusplus
extern "C"
#endif
-char clock_getres ();
+char clock_nanosleep ();
int
main ()
{
-return clock_getres ();
+return clock_nanosleep ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_rt_clock_getres=yes
+ ac_cv_lib_rt_clock_nanosleep=yes
else
- ac_cv_lib_rt_clock_getres=no
+ ac_cv_lib_rt_clock_nanosleep=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_getres" >&5
-$as_echo "$ac_cv_lib_rt_clock_getres" >&6; }
-if test "x$ac_cv_lib_rt_clock_getres" = xyes; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_nanosleep" >&5
+$as_echo "$ac_cv_lib_rt_clock_nanosleep" >&6; }
+if test "x$ac_cv_lib_rt_clock_nanosleep" = xyes; then :
- $as_echo "#define HAVE_CLOCK_GETRES 1" >>confdefs.h
+ $as_echo "#define HAVE_CLOCK_NANOSLEEP 1" >>confdefs.h
fi
@@ -13426,19 +13469,19 @@ fi
done
-for ac_func in clock_settime
+for ac_func in nanosleep
do :
- ac_fn_c_check_func "$LINENO" "clock_settime" "ac_cv_func_clock_settime"
-if test "x$ac_cv_func_clock_settime" = xyes; then :
+ ac_fn_c_check_func "$LINENO" "nanosleep" "ac_cv_func_nanosleep"
+if test "x$ac_cv_func_nanosleep" = xyes; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_CLOCK_SETTIME 1
+#define HAVE_NANOSLEEP 1
_ACEOF
else
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_settime in -lrt" >&5
-$as_echo_n "checking for clock_settime in -lrt... " >&6; }
-if ${ac_cv_lib_rt_clock_settime+:} false; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nanosleep in -lrt" >&5
+$as_echo_n "checking for nanosleep in -lrt... " >&6; }
+if ${ac_cv_lib_rt_nanosleep+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
@@ -13452,29 +13495,29 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
#ifdef __cplusplus
extern "C"
#endif
-char clock_settime ();
+char nanosleep ();
int
main ()
{
-return clock_settime ();
+return nanosleep ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_rt_clock_settime=yes
+ ac_cv_lib_rt_nanosleep=yes
else
- ac_cv_lib_rt_clock_settime=no
+ ac_cv_lib_rt_nanosleep=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_settime" >&5
-$as_echo "$ac_cv_lib_rt_clock_settime" >&6; }
-if test "x$ac_cv_lib_rt_clock_settime" = xyes; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_nanosleep" >&5
+$as_echo "$ac_cv_lib_rt_nanosleep" >&6; }
+if test "x$ac_cv_lib_rt_nanosleep" = xyes; then :
- $as_echo "#define HAVE_CLOCK_SETTIME 1" >>confdefs.h
+ $as_echo "#define HAVE_NANOSLEEP 1" >>confdefs.h
fi
diff --git a/configure.ac b/configure.ac
index 48d86ef79199e..908dd28e7aaca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3744,7 +3744,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
posix_fallocate posix_fadvise posix_spawn posix_spawnp pread preadv preadv2 \
pthread_condattr_setclock pthread_init pthread_kill pwrite pwritev pwritev2 \
readlink readlinkat readv realpath renameat \
- sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \
+ sem_open sem_timedwait sem_clockwait sem_getvalue sem_unlink sendfile setegid seteuid \
setgid sethostname \
setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \
sched_get_priority_max sched_setaffinity sched_setscheduler sched_setparam \
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 23d7111b9f77e..862c083604ee4 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -136,15 +136,15 @@
/* Define to 1 if you have the `clock' function. */
#undef HAVE_CLOCK
-/* Define to 1 if you have the `clock_nanosleep' function. */
-#undef HAVE_CLOCK_NANOSLEEP
-
/* Define to 1 if you have the `clock_getres' function. */
#undef HAVE_CLOCK_GETRES
/* Define to 1 if you have the `clock_gettime' function. */
#undef HAVE_CLOCK_GETTIME
+/* Define to 1 if you have the `clock_nanosleep' function. */
+#undef HAVE_CLOCK_NANOSLEEP
+
/* Define to 1 if you have the `clock_settime' function. */
#undef HAVE_CLOCK_SETTIME
@@ -908,6 +908,9 @@
/* Define to 1 if you have the `sched_setscheduler' function. */
#undef HAVE_SCHED_SETSCHEDULER
+/* Define to 1 if you have the `sem_clockwait' function. */
+#undef HAVE_SEM_CLOCKWAIT
+
/* Define to 1 if you have the `sem_getvalue' function. */
#undef HAVE_SEM_GETVALUE
1
0
https://github.com/python/cpython/commit/ef7c7294e8404d844c1add892a8f6684e6…
commit: ef7c7294e8404d844c1add892a8f6684e6cf4f31
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2021-10-01T00:36:17-07:00
summary:
bpo-45229: Make datetime tests discoverable (GH-28615)
(cherry picked from commit d441437ee71ae174c008c23308b749b91020ba77)
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
files:
M Lib/test/test_datetime.py
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index bdb9f02e5756a2..7f9094fa7bd4e6 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -1,59 +1,57 @@
import unittest
import sys
-from test.support import run_unittest
from test.support.import_helper import import_fresh_module
TESTS = 'test.datetimetester'
-try:
- pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
- blocked=['_datetime'])
- fast_tests = import_fresh_module(TESTS, fresh=['datetime',
- '_datetime', '_strptime'])
-finally:
- # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
- # XXX: but it does not, so we have to cleanup ourselves.
- for modname in ['datetime', '_datetime', '_strptime']:
- sys.modules.pop(modname, None)
-test_modules = [pure_tests, fast_tests]
-test_suffixes = ["_Pure", "_Fast"]
-# XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
-# not believe this, but in spite of all the sys.modules trickery running a _Pure
-# test last will leave a mix of pure and native datetime stuff lying around.
-all_test_classes = []
+def load_tests(loader, tests, pattern):
+ try:
+ pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
+ blocked=['_datetime'])
+ fast_tests = import_fresh_module(TESTS, fresh=['datetime',
+ '_datetime', '_strptime'])
+ finally:
+ # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
+ # XXX: but it does not, so we have to cleanup ourselves.
+ for modname in ['datetime', '_datetime', '_strptime']:
+ sys.modules.pop(modname, None)
-for module, suffix in zip(test_modules, test_suffixes):
- test_classes = []
- for name, cls in module.__dict__.items():
- if not isinstance(cls, type):
- continue
- if issubclass(cls, unittest.TestCase):
- test_classes.append(cls)
- elif issubclass(cls, unittest.TestSuite):
- suit = cls()
- test_classes.extend(type(test) for test in suit)
- test_classes = sorted(set(test_classes), key=lambda cls: cls.__qualname__)
- for cls in test_classes:
- cls.__name__ += suffix
- cls.__qualname__ += suffix
- @classmethod
- def setUpClass(cls_, module=module):
- cls_._save_sys_modules = sys.modules.copy()
- sys.modules[TESTS] = module
- sys.modules['datetime'] = module.datetime_module
- sys.modules['_strptime'] = module._strptime
- @classmethod
- def tearDownClass(cls_):
- sys.modules.clear()
- sys.modules.update(cls_._save_sys_modules)
- cls.setUpClass = setUpClass
- cls.tearDownClass = tearDownClass
- all_test_classes.extend(test_classes)
+ test_modules = [pure_tests, fast_tests]
+ test_suffixes = ["_Pure", "_Fast"]
+ # XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
+ # not believe this, but in spite of all the sys.modules trickery running a _Pure
+ # test last will leave a mix of pure and native datetime stuff lying around.
+ for module, suffix in zip(test_modules, test_suffixes):
+ test_classes = []
+ for name, cls in module.__dict__.items():
+ if not isinstance(cls, type):
+ continue
+ if issubclass(cls, unittest.TestCase):
+ test_classes.append(cls)
+ elif issubclass(cls, unittest.TestSuite):
+ suit = cls()
+ test_classes.extend(type(test) for test in suit)
+ test_classes = sorted(set(test_classes), key=lambda cls: cls.__qualname__)
+ for cls in test_classes:
+ cls.__name__ += suffix
+ cls.__qualname__ += suffix
+ @classmethod
+ def setUpClass(cls_, module=module):
+ cls_._save_sys_modules = sys.modules.copy()
+ sys.modules[TESTS] = module
+ sys.modules['datetime'] = module.datetime_module
+ sys.modules['_strptime'] = module._strptime
+ @classmethod
+ def tearDownClass(cls_):
+ sys.modules.clear()
+ sys.modules.update(cls_._save_sys_modules)
+ cls.setUpClass = setUpClass
+ cls.tearDownClass = tearDownClass
+ tests.addTests(loader.loadTestsFromTestCase(cls))
+ return tests
-def test_main():
- run_unittest(*all_test_classes)
if __name__ == "__main__":
- test_main()
+ unittest.main()
1
0
https://github.com/python/cpython/commit/3e1c5d989a884cfbeb427b6fc86012b03c…
commit: 3e1c5d989a884cfbeb427b6fc86012b03cb95f62
branch: main
author: Eric Snow <ericsnowcurrently(a)gmail.com>
committer: ericsnowcurrently <ericsnowcurrently(a)gmail.com>
date: 2021-09-30T20:23:32-06:00
summary:
Install the __phello__ package too. (#28665)
I broke some buildbots by not adding __phello__ to the list of installed packages.
https://bugs.python.org/issue45020
files:
M Makefile.pre.in
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 7ad634ac01162..670887437360c 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1544,7 +1544,8 @@ LIBSUBDIRS= asyncio \
wsgiref \
$(XMLLIBSUBDIRS) \
xmlrpc \
- zoneinfo
+ zoneinfo \
+ __phello__
TESTSUBDIRS= ctypes/test \
distutils/tests \
idlelib/idle_test \
1
0
Oct. 1, 2021
https://github.com/python/cpython/commit/7e5c107541726b90d3f2e6e69ef37180cf…
commit: 7e5c107541726b90d3f2e6e69ef37180cf58335d
branch: main
author: Eric Snow <ericsnowcurrently(a)gmail.com>
committer: ericsnowcurrently <ericsnowcurrently(a)gmail.com>
date: 2021-09-30T18:38:52-06:00
summary:
bpo-45020: Add more test cases for frozen modules. (gh-28664)
I've added a number of test-only modules. Some of those cases are covered by the recently frozen stdlib modules (and some will be once we add encodings back in). However, I figured we'd play it safe by having a set of modules guaranteed to be there during tests.
https://bugs.python.org/issue45020
files:
A Lib/__phello__/__init__.py
A Lib/__phello__/ham/__init__.py
A Lib/__phello__/ham/eggs.py
A Lib/__phello__/spam.py
D Lib/__phello__.foo.py
M Lib/test/test_frozen.py
M Lib/test/test_importlib/frozen/test_finder.py
M Makefile.pre.in
M PCbuild/_freeze_module.vcxproj
M PCbuild/_freeze_module.vcxproj.filters
M Python/frozen.c
M Tools/scripts/freeze_modules.py
M Tools/scripts/generate_stdlib_module_names.py
diff --git a/Lib/__phello__.foo.py b/Lib/__phello__.foo.py
deleted file mode 100644
index 8e8623ee1daac..0000000000000
--- a/Lib/__phello__.foo.py
+++ /dev/null
@@ -1 +0,0 @@
-# This file exists as a helper for the test.test_frozen module.
diff --git a/Lib/__phello__/__init__.py b/Lib/__phello__/__init__.py
new file mode 100644
index 0000000000000..d37bd2766ac1c
--- /dev/null
+++ b/Lib/__phello__/__init__.py
@@ -0,0 +1,7 @@
+initialized = True
+
+def main():
+ print("Hello world!")
+
+if __name__ == '__main__':
+ main()
diff --git a/Lib/__phello__/ham/__init__.py b/Lib/__phello__/ham/__init__.py
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/Lib/__phello__/ham/eggs.py b/Lib/__phello__/ham/eggs.py
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/Lib/__phello__/spam.py b/Lib/__phello__/spam.py
new file mode 100644
index 0000000000000..d37bd2766ac1c
--- /dev/null
+++ b/Lib/__phello__/spam.py
@@ -0,0 +1,7 @@
+initialized = True
+
+def main():
+ print("Hello world!")
+
+if __name__ == '__main__':
+ main()
diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py
index 3d212b9202f90..029fd068793c3 100644
--- a/Lib/test/test_frozen.py
+++ b/Lib/test/test_frozen.py
@@ -10,6 +10,7 @@
# Invalid marshalled data in frozen.c could case the interpreter to
# crash when __hello__ is imported.
+import importlib.machinery
import sys
import unittest
from test.support import captured_stdout, import_helper
@@ -26,6 +27,33 @@ def test_frozen(self):
__hello__.main()
self.assertEqual(out.getvalue(), 'Hello world!\n')
+ def test_frozen_submodule_in_unfrozen_package(self):
+ with import_helper.CleanImport('__phello__', '__phello__.spam'):
+ with import_helper.frozen_modules(enabled=False):
+ import __phello__
+ with import_helper.frozen_modules(enabled=True):
+ import __phello__.spam as spam
+ self.assertIs(spam, __phello__.spam)
+ self.assertIsNot(__phello__.__spec__.loader,
+ importlib.machinery.FrozenImporter)
+ self.assertIs(spam.__spec__.loader,
+ importlib.machinery.FrozenImporter)
+
+ # This is not possible until frozen packages have __path__ set properly.
+ # See https://bugs.python.org/issue21736.
+ @unittest.expectedFailure
+ def test_unfrozen_submodule_in_frozen_package(self):
+ with import_helper.CleanImport('__phello__', '__phello__.spam'):
+ with import_helper.frozen_modules(enabled=True):
+ import __phello__
+ with import_helper.frozen_modules(enabled=False):
+ import __phello__.spam as spam
+ self.assertIs(spam, __phello__.spam)
+ self.assertIs(__phello__.__spec__.loader,
+ importlib.machinery.FrozenImporter)
+ self.assertIsNot(spam.__spec__.loader,
+ importlib.machinery.FrozenImporter)
+
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/test/test_importlib/frozen/test_finder.py b/Lib/test/test_importlib/frozen/test_finder.py
index fbc3fc0d547ff..7d43fb0ff3e11 100644
--- a/Lib/test/test_importlib/frozen/test_finder.py
+++ b/Lib/test/test_importlib/frozen/test_finder.py
@@ -1,4 +1,5 @@
from .. import abc
+import os.path
from .. import util
machinery = util.import_importlib('importlib.machinery')
@@ -13,34 +14,86 @@ class FindSpecTests(abc.FinderTests):
"""Test finding frozen modules."""
- def find(self, name, path=None):
+ def find(self, name, **kwargs):
finder = self.machinery.FrozenImporter
with import_helper.frozen_modules():
- return finder.find_spec(name, path)
+ return finder.find_spec(name, **kwargs)
- def test_module(self):
- name = '__hello__'
- spec = self.find(name)
+ def check(self, spec, name):
+ self.assertEqual(spec.name, name)
+ self.assertIs(spec.loader, self.machinery.FrozenImporter)
self.assertEqual(spec.origin, 'frozen')
+ self.assertFalse(spec.has_location)
- def test_package(self):
- spec = self.find('__phello__')
- self.assertIsNotNone(spec)
-
- def test_module_in_package(self):
- spec = self.find('__phello__.spam', ['__phello__'])
- self.assertIsNotNone(spec)
+ def test_module(self):
+ names = [
+ '__hello__',
+ '__hello_alias__',
+ '__hello_only__',
+ '__phello__.__init__',
+ '__phello__.spam',
+ '__phello__.ham.__init__',
+ '__phello__.ham.eggs',
+ ]
+ for name in names:
+ with self.subTest(name):
+ spec = self.find(name)
+ self.check(spec, name)
+ self.assertEqual(spec.submodule_search_locations, None)
- # No frozen package within another package to test with.
+ def test_package(self):
+ names = [
+ '__phello__',
+ '__phello__.ham',
+ '__phello_alias__',
+ ]
+ for name in names:
+ with self.subTest(name):
+ spec = self.find(name)
+ self.check(spec, name)
+ self.assertEqual(spec.submodule_search_locations, [])
+
+ # These are covered by test_module() and test_package().
+ test_module_in_package = None
test_package_in_package = None
# No easy way to test.
test_package_over_module = None
+ def test_path_ignored(self):
+ for name in ('__hello__', '__phello__', '__phello__.spam'):
+ actual = self.find(name)
+ for path in (None, object(), '', 'eggs', [], [''], ['eggs']):
+ with self.subTest((name, path)):
+ spec = self.find(name, path=path)
+ self.assertEqual(spec, actual)
+
+ def test_target_ignored(self):
+ imported = ('__hello__', '__phello__')
+ with import_helper.CleanImport(*imported, usefrozen=True):
+ import __hello__ as match
+ import __phello__ as nonmatch
+ name = '__hello__'
+ actual = self.find(name)
+ for target in (None, match, nonmatch, object(), 'not-a-module-object'):
+ with self.subTest(target):
+ spec = self.find(name, target=target)
+ self.assertEqual(spec, actual)
+
def test_failure(self):
spec = self.find('<not real>')
self.assertIsNone(spec)
+ def test_not_using_frozen(self):
+ finder = self.machinery.FrozenImporter
+ with import_helper.frozen_modules(enabled=False):
+ # both frozen and not frozen
+ spec1 = finder.find_spec('__hello__')
+ # only frozen
+ spec2 = finder.find_spec('__hello_only__')
+ self.assertIsNone(spec1)
+ self.assertIsNone(spec2)
+
(Frozen_FindSpecTests,
Source_FindSpecTests
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 5564c1bae1ce2..7ad634ac01162 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -752,7 +752,12 @@ FROZEN_FILES_IN = \
Lib/os.py \
Lib/site.py \
Lib/stat.py \
- Lib/__hello__.py
+ Lib/__hello__.py \
+ Lib/__phello__/__init__.py \
+ Lib/__phello__/ham/__init__.py \
+ Lib/__phello__/ham/eggs.py \
+ Lib/__phello__/spam.py \
+ Tools/freeze/flag.py
# End FROZEN_FILES_IN
FROZEN_FILES_OUT = \
Python/frozen_modules/importlib._bootstrap.h \
@@ -769,7 +774,12 @@ FROZEN_FILES_OUT = \
Python/frozen_modules/os.h \
Python/frozen_modules/site.h \
Python/frozen_modules/stat.h \
- Python/frozen_modules/__hello__.h
+ Python/frozen_modules/__hello__.h \
+ Python/frozen_modules/__phello__.h \
+ Python/frozen_modules/__phello__.ham.h \
+ Python/frozen_modules/__phello__.ham.eggs.h \
+ Python/frozen_modules/__phello__.spam.h \
+ Python/frozen_modules/frozen_only.h
# End FROZEN_FILES_OUT
Programs/_freeze_module.o: Programs/_freeze_module.c Makefile
@@ -824,6 +834,21 @@ Python/frozen_modules/stat.h: Programs/_freeze_module Lib/stat.py
Python/frozen_modules/__hello__.h: Programs/_freeze_module Lib/__hello__.py
Programs/_freeze_module __hello__ $(srcdir)/Lib/__hello__.py $(srcdir)/Python/frozen_modules/__hello__.h
+Python/frozen_modules/__phello__.h: Programs/_freeze_module Lib/__phello__/__init__.py
+ Programs/_freeze_module __phello__ $(srcdir)/Lib/__phello__/__init__.py $(srcdir)/Python/frozen_modules/__phello__.h
+
+Python/frozen_modules/__phello__.ham.h: Programs/_freeze_module Lib/__phello__/ham/__init__.py
+ Programs/_freeze_module __phello__.ham $(srcdir)/Lib/__phello__/ham/__init__.py $(srcdir)/Python/frozen_modules/__phello__.ham.h
+
+Python/frozen_modules/__phello__.ham.eggs.h: Programs/_freeze_module Lib/__phello__/ham/eggs.py
+ Programs/_freeze_module __phello__.ham.eggs $(srcdir)/Lib/__phello__/ham/eggs.py $(srcdir)/Python/frozen_modules/__phello__.ham.eggs.h
+
+Python/frozen_modules/__phello__.spam.h: Programs/_freeze_module Lib/__phello__/spam.py
+ Programs/_freeze_module __phello__.spam $(srcdir)/Lib/__phello__/spam.py $(srcdir)/Python/frozen_modules/__phello__.spam.h
+
+Python/frozen_modules/frozen_only.h: Programs/_freeze_module Tools/freeze/flag.py
+ Programs/_freeze_module frozen_only $(srcdir)/Tools/freeze/flag.py $(srcdir)/Python/frozen_modules/frozen_only.h
+
# END: freezing modules
Tools/scripts/freeze_modules.py: Programs/_freeze_module
diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj
index ea6532d10d8cc..12bdde2af84d9 100644
--- a/PCbuild/_freeze_module.vcxproj
+++ b/PCbuild/_freeze_module.vcxproj
@@ -305,6 +305,31 @@
<IntFile>$(IntDir)__hello__.g.h</IntFile>
<OutFile>$(PySourcePath)Python\frozen_modules\__hello__.h</OutFile>
</None>
+ <None Include="..\Lib\__phello__\__init__.py">
+ <ModName>__phello__</ModName>
+ <IntFile>$(IntDir)__phello__.g.h</IntFile>
+ <OutFile>$(PySourcePath)Python\frozen_modules\__phello__.h</OutFile>
+ </None>
+ <None Include="..\Lib\__phello__\ham\__init__.py">
+ <ModName>__phello__.ham</ModName>
+ <IntFile>$(IntDir)__phello__.ham.g.h</IntFile>
+ <OutFile>$(PySourcePath)Python\frozen_modules\__phello__.ham.h</OutFile>
+ </None>
+ <None Include="..\Lib\__phello__\ham\eggs.py">
+ <ModName>__phello__.ham.eggs</ModName>
+ <IntFile>$(IntDir)__phello__.ham.eggs.g.h</IntFile>
+ <OutFile>$(PySourcePath)Python\frozen_modules\__phello__.ham.eggs.h</OutFile>
+ </None>
+ <None Include="..\Lib\__phello__\spam.py">
+ <ModName>__phello__.spam</ModName>
+ <IntFile>$(IntDir)__phello__.spam.g.h</IntFile>
+ <OutFile>$(PySourcePath)Python\frozen_modules\__phello__.spam.h</OutFile>
+ </None>
+ <None Include="..\Tools\freeze\flag.py">
+ <ModName>frozen_only</ModName>
+ <IntFile>$(IntDir)frozen_only.g.h</IntFile>
+ <OutFile>$(PySourcePath)Python\frozen_modules\frozen_only.h</OutFile>
+ </None>
<!-- END frozen modules -->
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/PCbuild/_freeze_module.vcxproj.filters b/PCbuild/_freeze_module.vcxproj.filters
index 4a1c90f668e64..5894909e0fbe1 100644
--- a/PCbuild/_freeze_module.vcxproj.filters
+++ b/PCbuild/_freeze_module.vcxproj.filters
@@ -61,6 +61,21 @@
<None Include="..\Lib\__hello__.py">
<Filter>Python Files</Filter>
</None>
+ <None Include="..\Lib\__phello__\__init__.py">
+ <Filter>Python Files</Filter>
+ </None>
+ <None Include="..\Lib\__phello__\ham\__init__.py">
+ <Filter>Python Files</Filter>
+ </None>
+ <None Include="..\Lib\__phello__\ham\eggs.py">
+ <Filter>Python Files</Filter>
+ </None>
+ <None Include="..\Lib\__phello__\spam.py">
+ <Filter>Python Files</Filter>
+ </None>
+ <None Include="..\Tools\freeze\flag.py">
+ <Filter>Python Files</Filter>
+ </None>
<!-- END frozen modules -->
</ItemGroup>
</Project>
diff --git a/Python/frozen.c b/Python/frozen.c
index f9ad07c0b49e1..b4f7121fda35f 100644
--- a/Python/frozen.c
+++ b/Python/frozen.c
@@ -53,6 +53,11 @@
#include "frozen_modules/site.h"
#include "frozen_modules/stat.h"
#include "frozen_modules/__hello__.h"
+#include "frozen_modules/__phello__.h"
+#include "frozen_modules/__phello__.ham.h"
+#include "frozen_modules/__phello__.ham.eggs.h"
+#include "frozen_modules/__phello__.spam.h"
+#include "frozen_modules/frozen_only.h"
/* End includes */
/* Note that a negative size indicates a package. */
@@ -84,8 +89,19 @@ static const struct _frozen _PyImport_FrozenModules[] = {
/* Test module */
{"__hello__", _Py_M____hello__, (int)sizeof(_Py_M____hello__)},
- {"__phello__", _Py_M____hello__, -(int)sizeof(_Py_M____hello__)},
- {"__phello__.spam", _Py_M____hello__, (int)sizeof(_Py_M____hello__)},
+ {"__hello_alias__", _Py_M____hello__, (int)sizeof(_Py_M____hello__)},
+ {"__phello_alias__", _Py_M____hello__, -(int)sizeof(_Py_M____hello__)},
+ {"__phello_alias__.spam", _Py_M____hello__, (int)sizeof(_Py_M____hello__)},
+ {"__phello__", _Py_M____phello__, -(int)sizeof(_Py_M____phello__)},
+ {"__phello__.__init__", _Py_M____phello__, (int)sizeof(_Py_M____phello__)},
+ {"__phello__.ham", _Py_M____phello___ham, -(int)sizeof(_Py_M____phello___ham)},
+ {"__phello__.ham.__init__", _Py_M____phello___ham,
+ (int)sizeof(_Py_M____phello___ham)},
+ {"__phello__.ham.eggs", _Py_M____phello___ham_eggs,
+ (int)sizeof(_Py_M____phello___ham_eggs)},
+ {"__phello__.spam", _Py_M____phello___spam,
+ (int)sizeof(_Py_M____phello___spam)},
+ {"__hello_only__", _Py_M__frozen_only, (int)sizeof(_Py_M__frozen_only)},
{0, 0, 0} /* sentinel */
};
diff --git a/Tools/scripts/freeze_modules.py b/Tools/scripts/freeze_modules.py
index ea96253df3e49..6091d831a8d31 100644
--- a/Tools/scripts/freeze_modules.py
+++ b/Tools/scripts/freeze_modules.py
@@ -19,6 +19,7 @@
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
ROOT_DIR = os.path.abspath(ROOT_DIR)
+FROZEN_ONLY = os.path.join(ROOT_DIR, 'Tools', 'freeze', 'flag.py')
STDLIB_DIR = os.path.join(ROOT_DIR, 'Lib')
# If MODULES_DIR is changed then the .gitattributes and .gitignore files
@@ -53,7 +54,6 @@ def find_tool():
MAKEFILE = os.path.join(ROOT_DIR, 'Makefile.pre.in')
PCBUILD_PROJECT = os.path.join(ROOT_DIR, 'PCbuild', '_freeze_module.vcxproj')
PCBUILD_FILTERS = os.path.join(ROOT_DIR, 'PCbuild', '_freeze_module.vcxproj.filters')
-TEST_CTYPES = os.path.join(STDLIB_DIR, 'ctypes', 'test', 'test_values.py')
OS_PATH = 'ntpath' if os.name == 'nt' else 'posixpath'
@@ -95,8 +95,11 @@ def find_tool():
]),
('Test module', [
'__hello__',
- '__hello__ : <__phello__>',
- '__hello__ : __phello__.spam',
+ '__hello__ : __hello_alias__',
+ '__hello__ : <__phello_alias__>',
+ '__hello__ : __phello_alias__.spam',
+ '<__phello__.**.*>',
+ f'frozen_only : __hello_only__ = {FROZEN_ONLY}',
]),
]
ESSENTIAL = {
@@ -135,14 +138,15 @@ def parse_frozen_specs(sectionalspecs=FROZEN, destdir=None):
seen = {}
for section, specs in sectionalspecs:
parsed = _parse_specs(specs, section, seen)
- for frozenid, pyfile, modname, ispkg, section in parsed:
+ for item in parsed:
+ frozenid, pyfile, modname, ispkg, section = item
try:
source = seen[frozenid]
except KeyError:
source = FrozenSource.from_id(frozenid, pyfile, destdir)
seen[frozenid] = source
else:
- assert not pyfile
+ assert not pyfile or pyfile == source.pyfile, item
yield FrozenModule(modname, ispkg, section, source)
@@ -224,7 +228,6 @@ def _parse_spec(spec, knownids=None, section=None):
pkgfiles = {pyfile: pkgid}
def iter_subs():
for frozenid, pyfile, ispkg in resolved:
- assert not knownids or frozenid not in knownids, (frozenid, spec)
if pkgname:
modname = frozenid.replace(pkgid, pkgname, 1)
else:
diff --git a/Tools/scripts/generate_stdlib_module_names.py b/Tools/scripts/generate_stdlib_module_names.py
index 325ae202b1d8c..50042f14fb62e 100644
--- a/Tools/scripts/generate_stdlib_module_names.py
+++ b/Tools/scripts/generate_stdlib_module_names.py
@@ -21,6 +21,9 @@
# Test modules and packages
'__hello__',
'__phello__',
+ '__hello_alias__',
+ '__phello_alias__',
+ '__hello_only__',
'_ctypes_test',
'_testbuffer',
'_testcapi',
1
0