METADATA 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. Metadata-Version: 2.1
  2. Name: apipkg
  3. Version: 2.0.0
  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
  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 :: MacOS :: MacOS X
  19. Classifier: Operating System :: Microsoft :: Windows
  20. Classifier: Operating System :: POSIX
  21. Classifier: Programming Language :: Python
  22. Classifier: Programming Language :: Python :: 2
  23. Classifier: Programming Language :: Python :: 2.7
  24. Classifier: Programming Language :: Python :: 3
  25. Classifier: Programming Language :: Python :: 3.4
  26. Classifier: Programming Language :: Python :: 3.5
  27. Classifier: Programming Language :: Python :: 3.6
  28. Classifier: Programming Language :: Python :: 3.7
  29. Classifier: Programming Language :: Python :: 3.8
  30. Classifier: Programming Language :: Python :: 3.9
  31. Classifier: Programming Language :: Python :: Implementation :: CPython
  32. Classifier: Topic :: Software Development :: Libraries
  33. Requires-Python: !=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7
  34. Description-Content-Type: text/x-rst
  35. License-File: LICENSE
  36. Welcome to apipkg !
  37. -------------------
  38. With apipkg you can control the exported namespace of a Python package and
  39. greatly reduce the number of imports for your users.
  40. It is a `small pure Python module`_ that works on CPython 2.7 and 3.4+,
  41. Jython and PyPy. It cooperates well with Python's ``help()`` system,
  42. custom importers (PEP302) and common command-line completion tools.
  43. Usage is very simple: you can require 'apipkg' as a dependency or you
  44. can copy paste the ~200 lines of code into your project.
  45. Tutorial example
  46. -------------------
  47. Here is a simple ``mypkg`` package that specifies one namespace
  48. and exports two objects imported from different modules::
  49. # mypkg/__init__.py
  50. import apipkg
  51. apipkg.initpkg(__name__, {
  52. 'path': {
  53. 'Class1': "_mypkg.somemodule:Class1",
  54. 'clsattr': "_mypkg.othermodule:Class2.attr",
  55. }
  56. }
  57. The package is initialized with a dictionary as namespace.
  58. You need to create a ``_mypkg`` package with a ``somemodule.py``
  59. and ``othermodule.py`` containing the respective classes.
  60. The ``_mypkg`` is not special - it's a completely
  61. regular Python package.
  62. Namespace dictionaries contain ``name: value`` mappings
  63. where the value may be another namespace dictionary or
  64. a string specifying an import location. On accessing
  65. an namespace attribute an import will be performed::
  66. >>> import mypkg
  67. >>> mypkg.path
  68. <ApiModule 'mypkg.path'>
  69. >>> mypkg.path.Class1 # '_mypkg.somemodule' gets imported now
  70. <class _mypkg.somemodule.Class1 at 0xb7d428fc>
  71. >>> mypkg.path.clsattr # '_mypkg.othermodule' gets imported now
  72. 4 # the value of _mypkg.othermodule.Class2.attr
  73. The ``mypkg.path`` namespace and its two entries are
  74. loaded when they are accessed. This means:
  75. * lazy loading - only what is actually needed is ever loaded
  76. * only the root "mypkg" ever needs to be imported to get
  77. access to the complete functionality
  78. * the underlying modules are also accessible, for example::
  79. from mypkg.sub import Class1
  80. Including apipkg in your package
  81. --------------------------------------
  82. If you don't want to add an ``apipkg`` dependency to your package you
  83. can copy the `apipkg.py`_ file somewhere to your own package,
  84. for example ``_mypkg/apipkg.py`` in the above example. You
  85. then import the ``initpkg`` function from that new place and
  86. are good to go.
  87. .. _`small pure Python module`:
  88. .. _`apipkg.py`: https://github.com/pytest-dev/apipkg/blob/master/src/apipkg/__init__.py
  89. Feedback?
  90. -----------------------
  91. If you have questions you are welcome to
  92. * join the **#pytest** channel on irc.libera.chat_
  93. (using an IRC client, via webchat_, or via Matrix_).
  94. * create an issue on the bugtracker_
  95. .. _irc.libera.chat: ircs://irc.libera.chat:6697/#pytest
  96. .. _webchat: https://web.libera.chat/#pytest
  97. .. _matrix: https://matrix.to/#/%23pytest:libera.chat
  98. .. _bugtracker: https://github.com/pytest-dev/apipkg/issues