Skip to content

Commit ba1680f

Browse files
authored
Merge pull request #19 from python/readme_docs
Flesh out readme / documentation
2 parents d3bc645 + 4df4a96 commit ba1680f

File tree

10 files changed

+218
-10
lines changed

10 files changed

+218
-10
lines changed

.github/workflows/tests.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: "ubuntu-latest"
3232
strategy:
3333
matrix:
34-
toxenv: ["build", "pytype"]
34+
toxenv: ["build", "pytype", "docs"]
3535
env:
3636
TOXENV: ${{ matrix.toxenv }}
3737

@@ -47,4 +47,8 @@ jobs:
4747
python -m pip install --upgrade tox
4848
- name: Run action
4949
run: |
50-
tox
50+
if [[ $TOXENV == "docs" ]]; then
51+
tox -- -j auto -bhtml -W -n -a --keep-going
52+
else
53+
tox
54+
fi

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dist/
1010

1111
# Sphinx documentation
1212
docs/_build/
13+
docs/_output/
1314

1415
# Testing
1516
.cache

.readthedocs.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2 # Required in order to install with pip
2+
3+
python:
4+
version: 3.7
5+
install:
6+
- path: .
7+
- requirements: docs/requirements.txt

README.md

-6
This file was deleted.

README.rst

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tzdata: Python package providing IANA time zone data
2+
====================================================
3+
4+
This is a Python package containing ``zic``-compiled binaries for the IANA time
5+
zone database. It is intended to be a fallback for systems that do not have
6+
system time zone data installed (or don't have it installed in a standard
7+
location), as a part of `PEP 615 <https://www.python.org/dev/peps/pep-0615/>`_
8+
9+
This repository generates a ``pip``-installable package, published on PyPI as
10+
`tzdata <https://pypi.org/project/tzdata>`_.
11+
12+
For more information, see `the documentation <https://tzdata.readthedocs.io>`_.

docs/conf.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
import sphinx_bootstrap_theme
8+
import tzdata
9+
10+
# -- Project information -----------------------------------------------------
11+
12+
project = "tzdata"
13+
copyright = "2020, Python Software Foundation"
14+
author = "Python Software Foundation"
15+
version = tzdata.__version__
16+
17+
18+
# -- General configuration ---------------------------------------------------
19+
20+
# Add any Sphinx extension module names here, as strings. They can be
21+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
22+
# ones.
23+
extensions = ["sphinx.ext.intersphinx"]
24+
25+
# Add any paths that contain templates here, relative to this directory.
26+
templates_path = ["_templates"]
27+
28+
# List of patterns, relative to source directory, that match files and
29+
# directories to ignore when looking for source files.
30+
# This pattern also affects html_static_path and html_extra_path.
31+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
32+
33+
34+
# -- Options for HTML output -------------------------------------------------
35+
36+
# The theme to use for HTML and HTML Help pages. See the documentation for
37+
# a list of builtin themes.
38+
#
39+
html_theme = "bootstrap"
40+
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
41+
html_theme_options = {
42+
"bootswatch_theme": "cosmo",
43+
}
44+
45+
# For cross-links to other documentation
46+
intersphinx_mapping = {
47+
"python": ("https://docs.python.org/3", None),
48+
"dateutil": ("https://dateutil.readthedocs.io/en/stable/", None),
49+
}

docs/index.rst

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
tzdata: Python package providing IANA time zone data
2+
====================================================
3+
4+
This is a Python package containing ``zic``-compiled binaries for the IANA time
5+
zone database. It is intended to be a fallback for systems that do not have
6+
system time zone data installed (or don't have it installed in a standard
7+
location), as a part of `PEP 615 <https://www.python.org/dev/peps/pep-0615/>`_
8+
9+
This repository generates a ``pip``-installable package, published on PyPI as
10+
`tzdata <https://pypi.org/project/tzdata>`_.
11+
12+
Overview
13+
--------
14+
15+
``tzdata`` is a *data-only* package, organized in such a way that its resources
16+
are accessible via :mod:`importlib.resources` (or, in older versions of Python,
17+
its backport `importlib_resources`_). Although ``importlib.resources`` or
18+
equivalent is recommended, it is also possible to access the data via
19+
:func:`pkgutil.get_data` as well.
20+
21+
.. TODO: Change ``zoneinfo`` to :mod:`zoneinfo` when 3.9 is released
22+
23+
It is primarily intended to be used by standard library's ``zoneinfo``
24+
module (new in Python 3.9), but it is also available as a source for time zone
25+
data for other time zone libraries. It is generally recommended that any time
26+
zone libraries should attempt to use the system data before using the
27+
``tzdata`` package, but some systems (notably Windows) do not deploy zoneinfo
28+
binaries of this type, and so ``tzdata`` is necessary.
29+
30+
Contents
31+
--------
32+
33+
The ``tzdata`` package provides the output of ``zic`` compilation (the
34+
equivalent of something like ``/usr/share/zoneinfo``) under the
35+
``tzdata.zoneinfo`` package unaltered. This includes the ``tzdata.zi`` file,
36+
which is a compact text representation of the un-compiled time zone database.
37+
38+
The package organization looks something like this::
39+
40+
src/tzdata
41+
├── __init__.py
42+
├── zoneinfo
43+
│   ├── __init__.py
44+
│   ├── Africa
45+
│   │   ├── __init__.py
46+
│   │   ├── Abidjan
47+
│   │   ├── Accra
48+
│   │   ├── …
49+
│   │   └── Windhoek
50+
│   ├── America
51+
│   │   ├── __init__.py
52+
│   │   ├── Adak
53+
│   │   ├── Anchorage
54+
│   │   ├── …
55+
│   │   └── Yellowknife
56+
│   ├── …
57+
│   ├── tzdata.zi
58+
│   ├── …
59+
│   ├── zone.tab
60+
│   └── Zulu
61+
└── zones
62+
63+
21 directories, 623 files
64+
65+
In addition to the zoneinfo files, it also provides a small amount of extra
66+
metadata about the time zones. The ``tzdata.zones`` file is a newline-delimited
67+
file listing all the IANA keys for time zone files present in the
68+
``tzdata.zoneinfo`` package. The version of the IANA data is provided as a
69+
Python variable as ``tzdata.IANA_VERSION``.
70+
71+
Examples
72+
--------
73+
74+
End users should generally **not** need to use this package directly and should
75+
use a Python library like :mod:`dateutil.tz` or `zoneinfo`_, like so:
76+
77+
.. code-block:: python
78+
79+
# Python 3.9+
80+
from datetime import datetime
81+
from zoneinfo import ZoneInfo
82+
83+
dt = datetime.now(ZoneInfo("America/New_York"))
84+
85+
For those writing time zone libraries, the recommended mechanism for access is
86+
to open the relevant zoneinfo binaries with
87+
:func:`importlib.resources.open_binary`, like so:
88+
89+
.. code-block:: python
90+
91+
from importlib import resources
92+
93+
# America/New_York
94+
with resources.open_binary("tzdata.zoneinfo.America", "New_York") as f:
95+
assert f.read(4) == b"TZif"
96+
97+
Note that the way this is organized, each folder in ``tzdata.zoneinfo`` is a
98+
package with resources below it. An example function for converting IANA keys
99+
to package names:
100+
101+
.. code-block:: python
102+
103+
def iana_key_to_resource(key):
104+
package_loc, resource = key.rsplit("/", 1)
105+
package = "tzdata.zoneinfo." + package_loc.replace("/", ".")
106+
107+
return package, resource
108+
109+
assert iana_key_to_resource("America/New_York") == \
110+
("tzdata.zoneinfo.America", "New_York")
111+
assert iana_key_to_resource("America/Indiana/Indianapolis") == \
112+
("tzdata.zoneinfo.America.Indiana", "Indianapolis")
113+
114+
.. Links
115+
116+
.. _importlib_resources: https://importlib-resources.readthedocs.io/en/latest/
117+
.. _zoneinfo: https://docs.python.org/3/library/zoneinfo.html
118+
119+
.. toctree::
120+
:maxdepth: 2
121+
:caption: Contents:
122+
123+
124+
125+
Indices and tables
126+
==================
127+
128+
* :ref:`genindex`
129+
* :ref:`modindex`
130+
* :ref:`search`

docs/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sphinx>=3.0.0
2+
sphinx_bootstrap_theme

setup.cfg

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
name = tzdata
33
version = attr:tzdata.__version__
44
description = Provider of IANA time zone data
5-
long_description = file: README.md
6-
long_description_content_type = text/markdown
5+
long_description = file: README.rst
6+
long_description_content_type = text/x-rst
77
url = https://github.com/python/tzdata
88
author = Python Software Foundation
99
author_email = [email protected]
@@ -21,6 +21,7 @@ classifiers =
2121
project_urls =
2222
Bug Reports = https://github.com/python/tzdata/issues
2323
Source = https://github.com/python/tzdata
24+
Documentation = https://tzdata.readthedocs.io
2425

2526
[options]
2627
packages = tzdata

tox.ini

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ commands =
4141
isort update.py
4242
isort --atomic -rc tests
4343

44+
[testenv:docs]
45+
description = Build the documentation
46+
deps =
47+
-rdocs/requirements.txt
48+
commands =
49+
sphinx-build -d "{toxworkdir}/docs_doctree" "{toxinidir}/docs" \
50+
"{toxinidir}/docs/_output" {posargs: -j auto --color -bhtml}
51+
4452
[testenv:build]
4553
description = Build a wheel and source distribution
4654
skip_install = True

0 commit comments

Comments
 (0)