我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用platform.python_implementation()。
def default_environment(): if hasattr(sys, 'implementation'): iver = format_full_version(sys.implementation.version) implementation_name = sys.implementation.name else: iver = '0' implementation_name = '' return { "implementation_name": implementation_name, "implementation_version": iver, "os_name": os.name, "platform_machine": platform.machine(), "platform_release": platform.release(), "platform_system": platform.system(), "platform_version": platform.version(), "python_full_version": platform.python_version(), "platform_python_implementation": platform.python_implementation(), "python_version": platform.python_version()[:3], "sys_platform": sys.platform, }
def _called_from_setup(run_frame): """ Attempt to detect whether run() was called from setup() or by another command. If called by setup(), the parent caller will be the 'run_command' method in 'distutils.dist', and *its* caller will be the 'run_commands' method. If called any other way, the immediate caller *might* be 'run_command', but it won't have been called by 'run_commands'. Return True in that case or if a call stack is unavailable. Return False otherwise. """ if run_frame is None: msg = "Call stack not available. bdist_* commands may fail." warnings.warn(msg) if platform.python_implementation() == 'IronPython': msg = "For best results, pass -X:Frames to enable call stack." warnings.warn(msg) return True res = inspect.getouterframes(run_frame)[2] caller, = res[:1] info = inspect.getframeinfo(caller) caller_module = caller.f_globals.get('__name__', '') return ( caller_module == 'distutils.dist' and info.function == 'run_commands' )
def test_large_read_until(self): # Performance test: read_until used to have a quadratic component # so a read_until of 4MB would take 8 seconds; now it takes 0.25 # seconds. server, client = self.make_iostream_pair() try: # This test fails on pypy with ssl. I think it's because # pypy's gc defeats moves objects, breaking the # "frozen write buffer" assumption. if (isinstance(server, SSLIOStream) and platform.python_implementation() == 'PyPy'): raise unittest.SkipTest( "pypy gc causes problems with openssl") NUM_KB = 4096 for i in range(NUM_KB): client.write(b"A" * 1024) client.write(b"\r\n") server.read_until(b"\r\n", self.stop) data = self.wait() self.assertEqual(len(data), NUM_KB * 1024 + 2) finally: server.close() client.close()
def setUp(self): if self._should_be_skipped_due_to_version(): pytest.skip('Test cannot run with Python %s.' % (sys.version.split(' ')[0],)) missing = [] for req in self._test_file.options['requires']: try: __import__(req) except ImportError: missing.append(req) if missing: pytest.skip('Requires %s to be present.' % (','.join(missing),)) if self._test_file.options['except_implementations']: implementations = [ item.strip() for item in self._test_file.options['except_implementations'].split(",") ] implementation = platform.python_implementation() if implementation in implementations: pytest.skip( 'Test cannot run with Python implementation %r' % (implementation, ))
def check_ast(argv=None): files = added_files() retval = 0 for filename in files: try: ast.parse(open(filename, 'rb').read(), filename=filename) except SyntaxError: print('{}: failed parsing with {} {}:'.format( filename, platform.python_implementation(), sys.version.partition(' ')[0], )) print('\n{}'.format( ' ' + traceback.format_exc().replace('\n', '\n '), )) retval = 1 return retval
def gc_collect(): """Run enough GC collections to make object finalizers run.""" # XXX Tests of GC and cleanup behavior are generally flaky and icky, # especially when you target all of Python 2.7, 3.3+ and PyPy. Their result # quickly depends on other tests, the arguments to the test runner and the # computer running the tests. This skips them all for now. raise unittest.SkipTest if platform.python_implementation() == 'PyPy': # Since PyPy use garbage collection instead of reference counting # objects are not finalized before the next major GC collection. # Currently, the best way we have to ensure a major GC collection has # run is to call gc.collect() a number of times. [gc.collect() for _ in range(10)] else: gc.collect()