README.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .. image:: https://jazzband.co/static/img/badge.svg
  2. :target: https://jazzband.co/
  3. :alt: Jazzband
  4. .. image:: https://github.com/jazzband/contextlib2/workflows/Test/badge.svg
  5. :target: https://github.com/jazzband/contextlib2/actions
  6. :alt: Tests
  7. .. image:: https://codecov.io/gh/jazzband/contextlib2/branch/master/graph/badge.svg
  8. :target: https://codecov.io/gh/jazzband/contextlib2
  9. :alt: Coverage
  10. .. image:: https://readthedocs.org/projects/contextlib2/badge/?version=latest
  11. :target: https://contextlib2.readthedocs.org/
  12. :alt: Latest Docs
  13. contextlib2 is a backport of the `standard library's contextlib
  14. module <https://docs.python.org/3/library/contextlib.html>`_ to
  15. earlier Python versions.
  16. It also sometimes serves as a real world proving ground for possible future
  17. enhancements to the standard library version.
  18. Licensing
  19. ---------
  20. As a backport of Python standard library software, the implementation, test
  21. suite and other supporting files for this project are distributed under the
  22. Python Software License used for the CPython reference implementation.
  23. The one exception is the included type hints file, which comes from the
  24. ``typeshed`` project, and is hence distributed under the Apache License 2.0.
  25. Development
  26. -----------
  27. contextlib2 has no runtime dependencies, but requires ``setuptools`` and
  28. ``wheel`` at build time to generate universal wheel archives.
  29. Local testing is a matter of running::
  30. python3 -m unittest discover -t . -s test
  31. You can test against multiple versions of Python with
  32. `tox <https://tox.testrun.org/>`_::
  33. pip install tox
  34. tox
  35. Versions currently tested in both tox and GitHub Actions are:
  36. * CPython 3.6
  37. * CPython 3.7
  38. * CPython 3.8
  39. * CPython 3.9
  40. * CPython 3.10
  41. * PyPy3
  42. Updating to a new stdlib reference version
  43. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  44. As of Python 3.10, 4 files needed to be copied from the CPython reference
  45. implementation to contextlib2:
  46. * ``Doc/contextlib.rst`` -> ``docs/contextlib2.rst``
  47. * ``Lib/contextlib.py`` -> ``contextlib2/__init__.py``
  48. * ``Lib/test/test_contextlib.py`` -> ``test/test_contextlib.py``
  49. * ``Lib/test/test_contextlib_async.py`` -> ``test/test_contextlib_async.py``
  50. The corresponding version of ``contextlib2/__init__.pyi`` also needs to be
  51. retrieved from the ``typeshed`` project::
  52. wget https://raw.githubusercontent.com/python/typeshed/master/stdlib/contextlib.pyi
  53. For the 3.10 sync, the only changes needed to the test files were to import from
  54. ``contextlib2`` rather than ``contextlib``. The test directory is laid out so
  55. that the test suite's imports from ``test.support`` work the same way they do in
  56. the main CPython test suite.
  57. The following patch files are saved in the ``dev`` directory:
  58. * changes made to ``contextlib2/__init__.py`` to get it to run on the older
  59. versions (and to add back in the deprecated APIs that never graduated to
  60. the standard library version)
  61. * changes made to ``contextlib2/__init__.pyi`` to make the Python version
  62. guards unconditional (since the ``contextlib2`` API is the same on all
  63. supported versions)
  64. * changes made to ``docs/contextlib2.rst`` to use ``contextlib2`` version
  65. numbers in the version added/changed notes and to integrate the module
  66. documentation with the rest of the project documentation