Skip to content

Commit 3616eea

Browse files
authored
Merge branch 'main' into fix/punctuation
2 parents 0988231 + c62b169 commit 3616eea

43 files changed

Lines changed: 1345 additions & 351 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/test.yml‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Set up Python
13+
uses: actions/setup-python@v2
14+
with:
15+
python-version: 3.9
16+
17+
- name: pip cache
18+
uses: actions/cache@v2
19+
with:
20+
path: ~/.cache/pip
21+
key:
22+
${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('noxfile.py') }}
23+
restore-keys: |
24+
${{ matrix.os }}-${{ matrix.python-version }}-
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade nox virtualenv
29+
30+
- name: Nox build
31+
run: |
32+
python -m nox -s build

‎.travis.yml‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sphinx==3.2.0
22
sphinx-autobuild==0.7.1
3+
sphinx-inline-tabs==2020.10.19b4
34
git+https://github.com/python/python-docs-theme.git#egg=python-docs-theme
45
git+https://github.com/pypa/pypa-docs-theme.git#egg=pypa-docs-theme

‎source/conf.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'sphinx.ext.extlinks',
3535
'sphinx.ext.intersphinx',
3636
'sphinx.ext.todo',
37+
'sphinx_inline_tabs',
3738
]
3839

3940
# Add any paths that contain templates here, relative to this directory.
@@ -196,8 +197,8 @@
196197

197198
# Custom sidebar templates, filenames relative to this file.
198199
html_sidebars = {
199-
'**': ['localtoc.html', 'relations.html'],
200-
'index': ['localtoc.html']
200+
'**': ['globaltoc.html', 'relations.html'],
201+
'index': ['globaltoc.html']
201202
}
202203

203204
# Additional templates that should be rendered to pages, maps page names to
@@ -375,6 +376,7 @@
375376
'python': ('https://docs.python.org/3', None),
376377
'python2': ('https://docs.python.org/2', None),
377378
'pip': ('https://pip.pypa.io/en/latest/', None),
379+
'setuptools': ('https://setuptools.rtfd.io/en/latest/', None),
378380
}
379381

380382

‎source/contribute.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ need:
7979
1. `Nox <https://nox.readthedocs.io/en/latest/>`_. You can install or upgrade
8080
nox using ``pip``::
8181

82-
pip install --user nox
82+
python -m pip install --user nox
8383

8484
2. Python 3.6. Our build scripts are designed to work with Python 3.6 only.
8585
See the `Hitchhiker's Guide to Python installation instructions`_ to install

‎source/discussions/install-requires-vs-requirements.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ packages. [1]_
8383

8484
Whereas ``install_requires`` metadata is automatically analyzed by pip during an
8585
install, requirements files are not, and only are used when a user specifically
86-
installs them using ``pip install -r``.
86+
installs them using ``python -m pip install -r``.
8787

8888
----
8989

‎source/discussions/pip-vs-easy-install.rst‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pip vs easy_install
66
===================
77

88

9-
`easy_install` was released in 2004, as part of :ref:`setuptools`. It was
9+
:ref:`easy_install <easy_install>` was released in 2004, as part of :ref:`setuptools`. It was
1010
notable at the time for installing :term:`packages <Distribution Package>` from
1111
:term:`PyPI <Python Package Index (PyPI)>` using requirement specifiers, and
1212
automatically installing dependencies.
1313

14-
:ref:`pip` came later in 2008, as alternative to `easy_install`, although still
14+
:ref:`pip` came later in 2008, as alternative to :ref:`easy_install <easy_install>`, although still
1515
largely built on top of :ref:`setuptools` components. It was notable at the
1616
time for *not* installing packages as :term:`Eggs <Egg>` or from :term:`Eggs <Egg>` (but
1717
rather simply as 'flat' packages from :term:`sdists <Source Distribution (or
@@ -27,13 +27,13 @@ Here's a breakdown of the important differences between pip and easy_install now
2727
|Installs from :term:`Wheels |Yes |No |
2828
|<Wheel>` | | |
2929
+------------------------------+--------------------------------------+-------------------------------+
30-
|Uninstall Packages |Yes (``pip uninstall``) |No |
30+
|Uninstall Packages |Yes (``python -m pip uninstall``) |No |
3131
+------------------------------+--------------------------------------+-------------------------------+
3232
|Dependency Overrides |Yes (:ref:`Requirements Files |No |
3333
| |<pip:Requirements Files>`) | |
3434
+------------------------------+--------------------------------------+-------------------------------+
35-
|List Installed Packages |Yes (``pip list`` and ``pip |No |
36-
| |freeze``) | |
35+
|List Installed Packages |Yes (``python -m pip list`` and |No |
36+
| |``python -m pip freeze``) | |
3737
+------------------------------+--------------------------------------+-------------------------------+
3838
|:pep:`438` |Yes |No |
3939
|Support | | |

‎source/glossary.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Glossary
4444
A :term:`Built Distribution` format introduced by :ref:`setuptools`,
4545
which is being replaced by :term:`Wheel`. For details, see `The
4646
Internal Structure of Python Eggs
47-
<https://setuptools.readthedocs.io/en/latest/formats.html>`_ and
47+
<https://setuptools.readthedocs.io/en/latest/deprecated/python_eggs.html>`_ and
4848
`Python Eggs <http://peak.telecommunity.com/DevCenter/PythonEggs>`_
4949

5050
Extension Module

‎source/guides/analyzing-pypi-package-downloads.rst‎

Lines changed: 93 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,35 @@ the `BigQuery quickstart guide
6868
Data schema
6969
-----------
7070

71-
Linehaul writes an entry in a ``the-psf.pypi.downloadsYYYYMMDD`` table for each
71+
Linehaul writes an entry in a ``bigquery-public-data.pypi.file_downloads`` table for each
7272
download. The table contains information about what file was downloaded and how
7373
it was downloaded. Some useful columns from the `table schema
74-
<https://console.cloud.google.com/bigquery?pli=1&p=the-psf&d=pypi&t=downloads&page=table>`__
74+
<https://console.cloud.google.com/bigquery?pli=1&p=bigquery-public-data&d=pypi&t=file_downloads&page=table>`__
7575
include:
7676

77-
+------------------------+-----------------+-----------------------+
78-
| Column | Description | Examples |
79-
+========================+=================+=======================+
80-
| file.project | Project name | ``pipenv``, ``nose`` |
81-
+------------------------+-----------------+-----------------------+
82-
| file.version | Package version | ``0.1.6``, ``1.4.2`` |
83-
+------------------------+-----------------+-----------------------+
84-
| details.installer.name | Installer | pip, `bandersnatch`_ |
85-
+------------------------+-----------------+-----------------------+
86-
| details.python | Python version | ``2.7.12``, ``3.6.4`` |
87-
+------------------------+-----------------+-----------------------+
77+
+------------------------+-----------------+-----------------------------+
78+
| Column | Description | Examples |
79+
+========================+=================+=============================+
80+
| timestamp | Date and time | ``2020-03-09 00:33:03 UTC`` |
81+
+------------------------+-----------------+-----------------------------+
82+
| file.project | Project name | ``pipenv``, ``nose`` |
83+
+------------------------+-----------------+-----------------------------+
84+
| file.version | Package version | ``0.1.6``, ``1.4.2`` |
85+
+------------------------+-----------------+-----------------------------+
86+
| details.installer.name | Installer | pip, `bandersnatch`_ |
87+
+------------------------+-----------------+-----------------------------+
88+
| details.python | Python version | ``2.7.12``, ``3.6.4`` |
89+
+------------------------+-----------------+-----------------------------+
8890

8991

9092
Useful queries
9193
--------------
9294

9395
Run queries in the `BigQuery web UI`_ by clicking the "Compose query" button.
9496

95-
Note that the rows are stored in separate tables for each day, which helps
97+
Note that the rows are stored in a partitioned, which helps
9698
limit the cost of queries. These example queries analyze downloads from
97-
recent history by using `wildcard tables
98-
<https://cloud.google.com/bigquery/docs/querying-wildcard-tables>`__ to
99-
select all tables and then filter by ``_TABLE_SUFFIX``.
99+
recent history by filtering on the ``timestamp`` column.
100100

101101
Counting package downloads
102102
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -108,18 +108,17 @@ The following query counts the total number of downloads for the project
108108

109109
#standardSQL
110110
SELECT COUNT(*) AS num_downloads
111-
FROM `the-psf.pypi.downloads*`
111+
FROM `bigquery-public-data.pypi.file_downloads`
112112
WHERE file.project = 'pytest'
113113
-- Only query the last 30 days of history
114-
AND _TABLE_SUFFIX
115-
BETWEEN FORMAT_DATE(
116-
'%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY))
117-
AND FORMAT_DATE('%Y%m%d', CURRENT_DATE())
114+
AND DATE(timestamp)
115+
BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
116+
AND CURRENT_DATE()
118117

119118
+---------------+
120119
| num_downloads |
121120
+===============+
122-
| 2117807 |
121+
| 26190085 |
123122
+---------------+
124123

125124
To only count downloads from pip, filter on the ``details.installer.name``
@@ -129,71 +128,94 @@ column.
129128

130129
#standardSQL
131130
SELECT COUNT(*) AS num_downloads
132-
FROM `the-psf.pypi.downloads*`
131+
FROM `bigquery-public-data.pypi.file_downloads`
133132
WHERE file.project = 'pytest'
134133
AND details.installer.name = 'pip'
135134
-- Only query the last 30 days of history
136-
AND _TABLE_SUFFIX
137-
BETWEEN FORMAT_DATE(
138-
'%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY))
139-
AND FORMAT_DATE('%Y%m%d', CURRENT_DATE())
135+
AND DATE(timestamp)
136+
BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
137+
AND CURRENT_DATE()
140138

141139
+---------------+
142140
| num_downloads |
143141
+===============+
144-
| 1829322 |
142+
| 24334215 |
145143
+---------------+
146144

147145
Package downloads over time
148146
~~~~~~~~~~~~~~~~~~~~~~~~~~~
149147

150-
To group by monthly downloads, use the ``_TABLE_SUFFIX`` pseudo-column. Also
151-
use the pseudo-column to limit the tables queried and the corresponding
152-
costs.
148+
To group by monthly downloads, use the ``TIMESTAMP_TRUNC`` function. Also
149+
filtering by this column reduces corresponding costs.
153150

154151
::
155152

156153
#standardSQL
157154
SELECT
158155
COUNT(*) AS num_downloads,
159-
SUBSTR(_TABLE_SUFFIX, 1, 6) AS `month`
160-
FROM `the-psf.pypi.downloads*`
156+
DATE_TRUNC(DATE(timestamp), MONTH) AS `month`
157+
FROM `bigquery-public-data.pypi.file_downloads`
161158
WHERE
162159
file.project = 'pytest'
163160
-- Only query the last 6 months of history
164-
AND _TABLE_SUFFIX
165-
BETWEEN FORMAT_DATE(
166-
'%Y%m01', DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH))
167-
AND FORMAT_DATE('%Y%m%d', CURRENT_DATE())
161+
AND DATE(timestamp)
162+
BETWEEN DATE_TRUNC(DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH), MONTH)
163+
AND CURRENT_DATE()
168164
GROUP BY `month`
169165
ORDER BY `month` DESC
170166

171-
+---------------+--------+
172-
| num_downloads | month |
173-
+===============+========+
174-
| 1956741 | 201801 |
175-
+---------------+--------+
176-
| 2344692 | 201712 |
177-
+---------------+--------+
178-
| 1730398 | 201711 |
179-
+---------------+--------+
180-
| 2047310 | 201710 |
181-
+---------------+--------+
182-
| 1744443 | 201709 |
183-
+---------------+--------+
184-
| 1916952 | 201708 |
185-
+---------------+--------+
186-
187-
More queries
188-
~~~~~~~~~~~~
189-
190-
- `Data driven decisions using PyPI download statistics
191-
<https://langui.sh/2016/12/09/data-driven-decisions/>`__
192-
- `PyPI queries gist <https://gist.github.com/alex/4f100a9592b05e9b4d63>`__
193-
- `Python versions over time
194-
<https://github.com/tswast/code-snippets/blob/master/2018/python-community-insights/Python%20Community%20Insights.ipynb>`__
195-
- `Non-Windows downloads, grouped by platform
196-
<https://bigquery.cloud.google.com/savedquery/51422494423:ff1976af63614ad4a1258d8821dd7785>`__
167+
+---------------+------------+
168+
| num_downloads | month |
169+
+===============+============+
170+
| 1956741 | 2018-01-01 |
171+
+---------------+------------+
172+
| 2344692 | 2017-12-01 |
173+
+---------------+------------+
174+
| 1730398 | 2017-11-01 |
175+
+---------------+------------+
176+
| 2047310 | 2017-10-01 |
177+
+---------------+------------+
178+
| 1744443 | 2017-09-01 |
179+
+---------------+------------+
180+
| 1916952 | 2017-08-01 |
181+
+---------------+------------+
182+
183+
Python versions over time
184+
~~~~~~~~~~~~~~~~~~~~~~~~~
185+
186+
Extract the Python version from the ``details.python`` column. Warning: This
187+
query processes over 500 GB of data.
188+
189+
::
190+
191+
#standardSQL
192+
SELECT
193+
REGEXP_EXTRACT(details.python, r"[0-9]+\.[0-9]+") AS python_version,
194+
COUNT(*) AS num_downloads,
195+
FROM `bigquery-public-data.pypi.file_downloads`
196+
WHERE
197+
-- Only query the last 6 months of history
198+
DATE(timestamp)
199+
BETWEEN DATE_TRUNC(DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH), MONTH)
200+
AND CURRENT_DATE()
201+
GROUP BY `python_version`
202+
ORDER BY `num_downloads` DESC
203+
204+
+--------+---------------+
205+
| python | num_downloads |
206+
+========+===============+
207+
| 3.7 | 18051328726 |
208+
+--------+---------------+
209+
| 3.6 | 9635067203 |
210+
+--------+---------------+
211+
| 3.8 | 7781904681 |
212+
+--------+---------------+
213+
| 2.7 | 6381252241 |
214+
+--------+---------------+
215+
| null | 2026630299 |
216+
+--------+---------------+
217+
| 3.5 | 1894153540 |
218+
+--------+---------------+
197219

198220
Caveats
199221
=======
@@ -229,13 +251,12 @@ the official Python client library for BigQuery.
229251
230252
query_job = client.query("""
231253
SELECT COUNT(*) AS num_downloads
232-
FROM `the-psf.pypi.downloads*`
254+
FROM `bigquery-public-data.pypi.file_downloads`
233255
WHERE file.project = 'pytest'
234-
-- Only query the last 30 days of history
235-
AND _TABLE_SUFFIX
236-
BETWEEN FORMAT_DATE(
237-
'%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY))
238-
AND FORMAT_DATE('%Y%m%d', CURRENT_DATE())""")
256+
-- Only query the last 30 days of history
257+
AND DATE(timestamp)
258+
BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
259+
AND CURRENT_DATE()""")
239260
240261
results = query_job.result() # Waits for job to complete.
241262
for row in results:
@@ -253,7 +274,7 @@ Install `pypinfo`_ using pip.
253274

254275
::
255276

256-
pip install pypinfo
277+
python -m pip install pypinfo
257278

258279
Usage:
259280

@@ -282,7 +303,7 @@ References
282303
.. [#] `PyPI Download Counts deprecation email <https://mail.python.org/pipermail/distutils-sig/2013-May/020855.html>`__
283304
.. [#] `PyPI BigQuery dataset announcement email <https://mail.python.org/pipermail/distutils-sig/2016-May/028986.html>`__
284305
285-
.. _public PyPI download statistics dataset: https://console.cloud.google.com/bigquery?p=the-psf&d=pypi&page=dataset
306+
.. _public PyPI download statistics dataset: https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=pypi&page=dataset
286307
.. _bandersnatch: /key_projects/#bandersnatch
287308
.. _Google BigQuery: https://cloud.google.com/bigquery
288309
.. _BigQuery web UI: https://console.cloud.google.com/bigquery

0 commit comments

Comments
 (0)