You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.7KB

  1. Metadata-Version: 2.1
  2. Name: apipkg
  3. Version: 1.5
  4. Summary: apipkg: namespace control and lazy-import mechanism
  5. Home-page: https://github.com/pytest-dev/apipkg
  6. Author: holger krekel
  7. Maintainer: Ronny Pfannschmidt
  8. Maintainer-email: opensource@ronnypfannschmidt.de
  9. License: MIT License
  10. Platform: unix
  11. Platform: linux
  12. Platform: osx
  13. Platform: cygwin
  14. Platform: win32
  15. Classifier: Development Status :: 4 - Beta
  16. Classifier: Intended Audience :: Developers
  17. Classifier: License :: OSI Approved :: MIT License
  18. Classifier: Operating System :: POSIX
  19. Classifier: Operating System :: Microsoft :: Windows
  20. Classifier: Operating System :: MacOS :: MacOS X
  21. Classifier: Topic :: Software Development :: Libraries
  22. Classifier: Programming Language :: Python
  23. Classifier: Programming Language :: Python :: 2
  24. Classifier: Programming Language :: Python :: 2.7
  25. Classifier: Programming Language :: Python :: 3
  26. Classifier: Programming Language :: Python :: 3.4
  27. Classifier: Programming Language :: Python :: 3.5
  28. Classifier: Programming Language :: Python :: 3.6
  29. Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
  30. Welcome to apipkg!
  31. ------------------------
  32. With apipkg you can control the exported namespace of a Python package and
  33. greatly reduce the number of imports for your users.
  34. It is a `small pure Python module`_ that works on CPython 2.7 and 3.4+,
  35. Jython and PyPy. It cooperates well with Python's ``help()`` system,
  36. custom importers (PEP302) and common command-line completion tools.
  37. Usage is very simple: you can require 'apipkg' as a dependency or you
  38. can copy paste the ~200 lines of code into your project.
  39. Tutorial example
  40. -------------------
  41. Here is a simple ``mypkg`` package that specifies one namespace
  42. and exports two objects imported from different modules::
  43. # mypkg/__init__.py
  44. import apipkg
  45. apipkg.initpkg(__name__, {
  46. 'path': {
  47. 'Class1': "_mypkg.somemodule:Class1",
  48. 'clsattr': "_mypkg.othermodule:Class2.attr",
  49. }
  50. }
  51. The package is initialized with a dictionary as namespace.
  52. You need to create a ``_mypkg`` package with a ``somemodule.py``
  53. and ``othermodule.py`` containing the respective classes.
  54. The ``_mypkg`` is not special - it's a completely
  55. regular Python package.
  56. Namespace dictionaries contain ``name: value`` mappings
  57. where the value may be another namespace dictionary or
  58. a string specifying an import location. On accessing
  59. an namespace attribute an import will be performed::
  60. >>> import mypkg
  61. >>> mypkg.path
  62. <ApiModule 'mypkg.path'>
  63. >>> mypkg.path.Class1 # '_mypkg.somemodule' gets imported now
  64. <class _mypkg.somemodule.Class1 at 0xb7d428fc>
  65. >>> mypkg.path.clsattr # '_mypkg.othermodule' gets imported now
  66. 4 # the value of _mypkg.othermodule.Class2.attr
  67. The ``mypkg.path`` namespace and its two entries are
  68. loaded when they are accessed. This means:
  69. * lazy loading - only what is actually needed is ever loaded
  70. * only the root "mypkg" ever needs to be imported to get
  71. access to the complete functionality
  72. * the underlying modules are also accessible, for example::
  73. from mypkg.sub import Class1
  74. Including apipkg in your package
  75. --------------------------------------
  76. If you don't want to add an ``apipkg`` dependency to your package you
  77. can copy the `apipkg.py`_ file somewhere to your own package,
  78. for example ``_mypkg/apipkg.py`` in the above example. You
  79. then import the ``initpkg`` function from that new place and
  80. are good to go.
  81. .. _`small pure Python module`:
  82. .. _`apipkg.py`: https://github.com/pytest-dev/apipkg/blob/master/src/apipkg/__init__.py
  83. Feedback?
  84. -----------------------
  85. If you have questions you are welcome to
  86. * join the #pylib channel on irc.freenode.net
  87. * create an issue on https://github.com/pytest-dev/apipkg/issues
  88. have fun,
  89. holger krekel