SlideShare uma empresa Scribd logo
1 de 17
Customising PyPy ,[object Object]
Custom Executable ,[object Object],[object Object],[object Object],[object Object]
Executable Module in PyPy ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Interface in __init__.py Exposes symbols to the "user" from pypy.interpreter.mixedmodule import MixedModule  class Module(MixedModule): interpleveldefs = {} appleveldefs = { 'commands' : 'app_commands.COMMANDS', 'find_commands' : 'app_commands.find_commands', 'CommandError' : 'app_commands.CommandError', }
App Level Python Start with #NOT RPYTHON Consider your imports carefully And then write python like you normally will
Testing  - App Level Hacking a module is  pain . Roundtrip to build executable is >30 mins TDD wins Write unit tests to cover as much as you can.  Time to write  pypy/module/test/test_one.py
Testing  - App Level Python Beware of imports and test setup mocks from pypy.conftest import gettestobjspace class AppTestCall(object): def setup_class(cls): #  import mymod, sys space = cls.space = gettestobjspace(usemodules=('mymod','sys',)) #  sys.app_name = "pypy-c" space.setattr(space.sys, space.wrap("app_name"), space.wrap("pypy-c")) def test_mymod(): import mymod
Interface in __init__.py Exposes symbols to the "user" from pypy.interpreter.mixedmodule import MixedModule  class Module(MixedModule): interpleveldefs = { 'find_module':  'interp_imp.find_module',} appleveldefs = {}
Interp Level Python RPython for Speed You can implement the internals of a module in RPython which will be compiled to binary. It is your responsibility to handle wrapping and unwrapping def find_module(space, w_name, w_path=None):  name = space.str_w(w_name)  if space.is_w(w_path, space.w_None):  w_path = None  return space.newtuple([w_fileobj, w_filename, w_import_info])
Testing  - Interp Level Python Beware of imports and test setup mocks from pypy.conftest import gettestobjspace class AppTestImpModule:  def setup_class(cls):  cls.w_imp  = cls.space.getbuiltinmodule('imp') def test_find_module(self):  import os  file, pathname, description =  self.imp .find_module('StringIO')
Customising the Command Line pypy/translator/goal/  targetpypystandalone.py # manually imports  app_main.py   filename = os.path.join(this_dir, 'app_main.py')  app = gateway.applevel(open(filename).read(), 'app_main.py', 'app_main') Keep changes to a minimum as you have to build a binary to test them!
Customising the Command Line pypy/translator/goal/  app_main.py def run_command_line(.. settings .., cmd=None, **ignored):  mainmodule = type(sys)('__main__')  import site  if run_command:  ...  elif run_module:  ...  elif run_stdin:  # piped or interactive shell  ...  else:  import installation  if not sys.argv[0].endswith(".py") and sys.argv[0].find("/") == -1:  argv = sys.argv[:]  argv.insert(0,"")  installation.commands.execute(argv)  success = True  else: ...
Main Sequence (I’m not too sure about this) nanos module app_main.py ... full os module ... run_command_line(..) site.py sitecustomize.py main module/script/interpreter loading
Command Line Parsers app_main.py: def parse_command_line(argv) optparse.OptionParser argsparse.ArgsParser
My Objective Objective Self updating Filesystem monitoring Network Peer Daemon/Service capable Configurable command line
Building PyPy Add to pypy/config/pypyoptions.py (or) Use --with- mymod cd pypy/translator/goal translate.py --with- mymod targetpypystandalone.py
Henrik Vendelbo ,[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados (20)

Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Command line arguments that make you smile
Command line arguments that make you smileCommand line arguments that make you smile
Command line arguments that make you smile
 
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and PackagesPython Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and Packages
 
PHP
PHPPHP
PHP
 
php basics
php basicsphp basics
php basics
 
PHP tutorial | ptutorial
PHP tutorial | ptutorialPHP tutorial | ptutorial
PHP tutorial | ptutorial
 
02 Php Vars Op Control Etc
02 Php Vars Op Control Etc02 Php Vars Op Control Etc
02 Php Vars Op Control Etc
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
 
PHP
PHPPHP
PHP
 
PHP-Part2
PHP-Part2PHP-Part2
PHP-Part2
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Arrays & functions in php
Arrays & functions in phpArrays & functions in php
Arrays & functions in php
 
PHP slides
PHP slidesPHP slides
PHP slides
 

Semelhante a Customising py py

JSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklJSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklChristoph Pickl
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application FrameworkJady Yang
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesSiarhei Barysiuk
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytestHector Canto
 
How to write maintainable code without tests
How to write maintainable code without testsHow to write maintainable code without tests
How to write maintainable code without testsJuti Noppornpitak
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Yung-Yu Chen
 
Php session 3 Important topics
Php session 3 Important topicsPhp session 3 Important topics
Php session 3 Important topicsSpy Seat
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlHideaki Ohno
 
Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonPython Ireland
 
PyWPS Development restart
PyWPS Development restartPyWPS Development restart
PyWPS Development restartJachym Cepicky
 
Intro to Pylons / Pyramid
Intro to Pylons / PyramidIntro to Pylons / Pyramid
Intro to Pylons / PyramidEric Paxton
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitJames Fuller
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Desenvolvendo em php cli
Desenvolvendo em php cliDesenvolvendo em php cli
Desenvolvendo em php cliThiago Paes
 
05 pig user defined functions (udfs)
05 pig user defined functions (udfs)05 pig user defined functions (udfs)
05 pig user defined functions (udfs)Subhas Kumar Ghosh
 

Semelhante a Customising py py (20)

JSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklJSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph Pickl
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best Practices
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytest
 
How to write maintainable code without tests
How to write maintainable code without testsHow to write maintainable code without tests
How to write maintainable code without tests
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020
 
20150319 testotipsio
20150319 testotipsio20150319 testotipsio
20150319 testotipsio
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Php session 3 Important topics
Php session 3 Important topicsPhp session 3 Important topics
Php session 3 Important topics
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
 
Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in Python
 
PyWPS Development restart
PyWPS Development restartPyWPS Development restart
PyWPS Development restart
 
Intro to Pylons / Pyramid
Intro to Pylons / PyramidIntro to Pylons / Pyramid
Intro to Pylons / Pyramid
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
function.pptx
function.pptxfunction.pptx
function.pptx
 
Desenvolvendo em php cli
Desenvolvendo em php cliDesenvolvendo em php cli
Desenvolvendo em php cli
 
05 pig user defined functions (udfs)
05 pig user defined functions (udfs)05 pig user defined functions (udfs)
05 pig user defined functions (udfs)
 

Customising py py

  • 1.
  • 2.
  • 3.
  • 4. Interface in __init__.py Exposes symbols to the "user" from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): interpleveldefs = {} appleveldefs = { 'commands' : 'app_commands.COMMANDS', 'find_commands' : 'app_commands.find_commands', 'CommandError' : 'app_commands.CommandError', }
  • 5. App Level Python Start with #NOT RPYTHON Consider your imports carefully And then write python like you normally will
  • 6. Testing - App Level Hacking a module is pain . Roundtrip to build executable is >30 mins TDD wins Write unit tests to cover as much as you can. Time to write pypy/module/test/test_one.py
  • 7. Testing - App Level Python Beware of imports and test setup mocks from pypy.conftest import gettestobjspace class AppTestCall(object): def setup_class(cls): # import mymod, sys space = cls.space = gettestobjspace(usemodules=('mymod','sys',)) # sys.app_name = "pypy-c" space.setattr(space.sys, space.wrap("app_name"), space.wrap("pypy-c")) def test_mymod(): import mymod
  • 8. Interface in __init__.py Exposes symbols to the "user" from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): interpleveldefs = { 'find_module': 'interp_imp.find_module',} appleveldefs = {}
  • 9. Interp Level Python RPython for Speed You can implement the internals of a module in RPython which will be compiled to binary. It is your responsibility to handle wrapping and unwrapping def find_module(space, w_name, w_path=None): name = space.str_w(w_name) if space.is_w(w_path, space.w_None): w_path = None return space.newtuple([w_fileobj, w_filename, w_import_info])
  • 10. Testing - Interp Level Python Beware of imports and test setup mocks from pypy.conftest import gettestobjspace class AppTestImpModule: def setup_class(cls): cls.w_imp = cls.space.getbuiltinmodule('imp') def test_find_module(self): import os file, pathname, description = self.imp .find_module('StringIO')
  • 11. Customising the Command Line pypy/translator/goal/ targetpypystandalone.py # manually imports app_main.py filename = os.path.join(this_dir, 'app_main.py') app = gateway.applevel(open(filename).read(), 'app_main.py', 'app_main') Keep changes to a minimum as you have to build a binary to test them!
  • 12. Customising the Command Line pypy/translator/goal/ app_main.py def run_command_line(.. settings .., cmd=None, **ignored): mainmodule = type(sys)('__main__') import site if run_command: ... elif run_module: ... elif run_stdin: # piped or interactive shell ... else: import installation if not sys.argv[0].endswith(".py") and sys.argv[0].find("/") == -1: argv = sys.argv[:] argv.insert(0,"") installation.commands.execute(argv) success = True else: ...
  • 13. Main Sequence (I’m not too sure about this) nanos module app_main.py ... full os module ... run_command_line(..) site.py sitecustomize.py main module/script/interpreter loading
  • 14. Command Line Parsers app_main.py: def parse_command_line(argv) optparse.OptionParser argsparse.ArgsParser
  • 15. My Objective Objective Self updating Filesystem monitoring Network Peer Daemon/Service capable Configurable command line
  • 16. Building PyPy Add to pypy/config/pypyoptions.py (or) Use --with- mymod cd pypy/translator/goal translate.py --with- mymod targetpypystandalone.py
  • 17.