Skip to content

Commit

Permalink
Remove 'trending projects' and 'latest releases' (#12888)
Browse files Browse the repository at this point in the history
  • Loading branch information
di authored Jan 24, 2023
1 parent ede4fa0 commit 748138e
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 332 deletions.
12 changes: 1 addition & 11 deletions tests/unit/packaging/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
from warehouse.packaging.models import File, Project, Release, Role
from warehouse.packaging.tasks import ( # sync_bigquery_release_files,
compute_2fa_mandate,
compute_trending,
update_description_html,
)


@pytest.mark.parametrize("with_trending", [True, False])
@pytest.mark.parametrize("with_bq_sync", [True, False])
@pytest.mark.parametrize("with_2fa_mandate", [True, False])
def test_includeme(monkeypatch, with_trending, with_bq_sync, with_2fa_mandate):
def test_includeme(monkeypatch, with_bq_sync, with_2fa_mandate):
storage_class = pretend.stub(
create_service=pretend.call_recorder(lambda *a, **kw: pretend.stub())
)
Expand All @@ -40,8 +38,6 @@ def key_factory(keystring, iterate_on=None):

monkeypatch.setattr(packaging, "key_factory", key_factory)
settings = dict()
if with_trending:
settings["warehouse.trending_table"] = "foobar"
if with_bq_sync:
settings["warehouse.release_files_table"] = "fizzbuzz"
if with_2fa_mandate:
Expand Down Expand Up @@ -128,12 +124,6 @@ def key_factory(keystring, iterate_on=None):
# )
pass

if with_trending:
assert (
pretend.call(crontab(minute=0, hour=3), compute_trending)
in config.add_periodic_task.calls
)

if with_2fa_mandate:
assert (
pretend.call(crontab(minute=0, hour=3), compute_2fa_mandate)
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/packaging/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_build_search():
platform="any platform",
created=datetime.datetime(1956, 1, 31),
classifiers=["Alpha", "Beta"],
zscore=None,
)
obj = Project.from_db(release)

Expand All @@ -55,4 +54,3 @@ def test_build_search():
assert obj["platform"] == "any platform"
assert obj["created"] == datetime.datetime(1956, 1, 31)
assert obj["classifiers"] == ["Alpha", "Beta"]
assert obj["zscore"] is None
94 changes: 2 additions & 92 deletions tests/unit/packaging/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@
import pretend
import pytest

from google.cloud.bigquery import Row, SchemaField
from google.cloud.bigquery import SchemaField
from wtforms import Field, Form, StringField

import warehouse.packaging.tasks

from warehouse.accounts.models import WebAuthn
from warehouse.cache.origin import IOriginCache
from warehouse.packaging.models import Description, Project
from warehouse.packaging.models import Description
from warehouse.packaging.tasks import (
compute_2fa_mandate,
compute_2fa_metrics,
compute_trending,
sync_bigquery_release_files,
update_bigquery_release_files,
update_description_html,
Expand All @@ -45,94 +43,6 @@
)


class TestComputeTrending:
@pytest.mark.parametrize("with_purges", [True, False])
def test_computes_trending(self, db_request, with_purges):
projects = [
ProjectFactory.create(zscore=1 if not i else None) for i in range(3)
]

results = iter(
[
Row((projects[1].normalized_name, 2), {"project": 0, "zscore": 1}),
Row((projects[2].normalized_name, -1), {"project": 0, "zscore": 1}),
]
)
query = pretend.stub(result=pretend.call_recorder(lambda *a, **kw: results))
bigquery = pretend.stub(query=pretend.call_recorder(lambda q: query))

cacher = pretend.stub(purge=pretend.call_recorder(lambda keys: None))

def find_service(iface=None, name=None):
if iface is None and name == "gcloud.bigquery":
return bigquery

if with_purges and issubclass(iface, IOriginCache):
return cacher

raise LookupError

db_request.find_service = find_service
db_request.registry.settings = {
"warehouse.trending_table": "example.pypi.downloads*"
}

compute_trending(db_request)

assert bigquery.query.calls == [
pretend.call(
""" SELECT project,
IF(
STDDEV(downloads) > 0,
(todays_downloads - AVG(downloads))/STDDEV(downloads),
NULL
) as zscore
FROM (
SELECT project,
date,
downloads,
FIRST_VALUE(downloads) OVER (
PARTITION BY project
ORDER BY DATE DESC
ROWS BETWEEN UNBOUNDED PRECEDING
AND UNBOUNDED FOLLOWING
) as todays_downloads
FROM (
SELECT file.project as project,
DATE(timestamp) AS date,
COUNT(*) as downloads
FROM `example.pypi.downloads*`
WHERE _TABLE_SUFFIX BETWEEN
FORMAT_DATE(
"%Y%m%d",
DATE_ADD(CURRENT_DATE(), INTERVAL -31 day))
AND
FORMAT_DATE(
"%Y%m%d",
DATE_ADD(CURRENT_DATE(), INTERVAL -1 day))
GROUP BY file.project, date
)
)
GROUP BY project, todays_downloads
HAVING SUM(downloads) >= 5000
ORDER BY zscore DESC
"""
)
]
assert query.result.calls == [pretend.call()]
assert cacher.purge.calls == (
[pretend.call(["trending"])] if with_purges else []
)

results = dict(db_request.db.query(Project.name, Project.zscore).all())

assert results == {
projects[0].name: None,
projects[1].name: 2,
projects[2].name: -1,
}


def test_update_description_html(monkeypatch, db_request):
current_version = "24.0"
previous_version = "23.0"
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ def test_mixed_quoted_query(self):
},
}

@pytest.mark.parametrize(
"order,field", [("created", "created"), ("-zscore", "zscore")]
)
@pytest.mark.parametrize("order,field", [("created", "created")])
def test_sort_order(self, order, field):
es = Search()
terms = "foo bar"
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ def test_index(self, db_request):
UserFactory.create()

assert index(db_request) == {
# assert that ordering is correct
"latest_releases": [release2, release1],
"trending_projects": [release2],
"num_projects": 1,
"num_users": 3,
"num_releases": 2,
Expand Down
1 change: 0 additions & 1 deletion warehouse/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def configure(settings=None):
"GITHUB_TOKEN_SCANNING_META_API_URL",
default="https://api.github.com/meta/public_keys/token_scanning",
)
maybe_set(settings, "warehouse.trending_table", "WAREHOUSE_TRENDING_TABLE")
maybe_set(settings, "warehouse.downloads_table", "WAREHOUSE_DOWNLOADS_TABLE")
maybe_set(settings, "celery.broker_url", "BROKER_URL")
maybe_set(settings, "celery.result_url", "REDIS_URL")
Expand Down
70 changes: 25 additions & 45 deletions warehouse/locale/messages.pot
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#: warehouse/views.py:141
#: warehouse/views.py:140
msgid ""
"Two-factor authentication must be enabled on your account to perform this"
" action."
msgstr ""

#: warehouse/views.py:304
#: warehouse/views.py:265
msgid "Locale updated"
msgstr ""

Expand Down Expand Up @@ -520,7 +520,7 @@ msgstr ""
#: warehouse/templates/includes/accounts/profile-callout.html:18
#: warehouse/templates/includes/hash-modal.html:23
#: warehouse/templates/includes/packaging/project-data.html:66
#: warehouse/templates/index.html:112 warehouse/templates/index.html:116
#: warehouse/templates/index.html:100 warehouse/templates/index.html:104
#: warehouse/templates/manage/account.html:228
#: warehouse/templates/manage/account.html:234
#: warehouse/templates/manage/account/totp-provision.html:32
Expand Down Expand Up @@ -737,7 +737,7 @@ msgid ""
"Foundation</a>."
msgstr ""

#: warehouse/templates/base.html:93 warehouse/templates/index.html:109
#: warehouse/templates/base.html:93 warehouse/templates/index.html:97
msgid ""
"The Python Package Index (PyPI) is a repository of software for the "
"Python programming language."
Expand Down Expand Up @@ -796,19 +796,19 @@ msgstr ""

#: warehouse/templates/base.html:227 warehouse/templates/base.html:248
#: warehouse/templates/error-base-with-search.html:20
#: warehouse/templates/index.html:55
#: warehouse/templates/index.html:43
msgid "Search PyPI"
msgstr ""

#: warehouse/templates/base.html:228 warehouse/templates/base.html:249
#: warehouse/templates/error-base-with-search.html:21
#: warehouse/templates/index.html:58
#: warehouse/templates/index.html:46
msgid "Search projects"
msgstr ""

#: warehouse/templates/base.html:232 warehouse/templates/base.html:253
#: warehouse/templates/error-base-with-search.html:24
#: warehouse/templates/index.html:62
#: warehouse/templates/index.html:50
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -971,85 +971,69 @@ msgstr ""
msgid "The Python Package Index"
msgstr ""

#: warehouse/templates/index.html:43
#: warehouse/templates/index.html:31
msgid "Test Python package publishing with the Test Python Package Index"
msgstr ""

#: warehouse/templates/index.html:45
#: warehouse/templates/index.html:33
msgid "Develop the codebase behind PyPI with the Dev Python Package Index"
msgstr ""

#: warehouse/templates/index.html:47
#: warehouse/templates/index.html:35
msgid "Find, install and publish Python packages with the Python Package Index"
msgstr ""

#: warehouse/templates/index.html:66
#: warehouse/templates/index.html:54
#, python-format
msgid "Or <a href=\"%(href)s\">browse projects</a>"
msgstr ""

#: warehouse/templates/index.html:73
#: warehouse/templates/index.html:61
#, python-format
msgid "%(num_projects_formatted)s project"
msgid_plural "%(num_projects_formatted)s projects"
msgstr[0] ""
msgstr[1] ""

#: warehouse/templates/index.html:80
#: warehouse/templates/index.html:68
#, python-format
msgid "%(num_releases_formatted)s release"
msgid_plural "%(num_releases_formatted)s releases"
msgstr[0] ""
msgstr[1] ""

#: warehouse/templates/index.html:87
#: warehouse/templates/index.html:75
#, python-format
msgid "%(num_files_formatted)s file"
msgid_plural "%(num_files_formatted)s files"
msgstr[0] ""
msgstr[1] ""

#: warehouse/templates/index.html:94
#: warehouse/templates/index.html:82
#, python-format
msgid "%(num_users_formatted)s user"
msgid_plural "%(num_users_formatted)s users"
msgstr[0] ""
msgstr[1] ""

#: warehouse/templates/index.html:111
#: warehouse/templates/index.html:99
msgid ""
"PyPI helps you find and install software developed and shared by the "
"Python community."
msgstr ""

#: warehouse/templates/index.html:112
#: warehouse/templates/index.html:100
msgid "Learn about installing packages"
msgstr ""

#: warehouse/templates/index.html:115
#: warehouse/templates/index.html:103
msgid "Package authors use PyPI to distribute their software."
msgstr ""

#: warehouse/templates/index.html:116
#: warehouse/templates/index.html:104
msgid "Learn how to package your Python code for PyPI"
msgstr ""

#: warehouse/templates/index.html:126
msgid "Trending projects"
msgstr ""

#: warehouse/templates/index.html:127
msgid "Trending projects as downloaded by the community"
msgstr ""

#: warehouse/templates/index.html:137
msgid "New releases"
msgstr ""

#: warehouse/templates/index.html:138
msgid "Hot off the press: the newest project releases"
msgstr ""

#: warehouse/templates/accounts/login.html:17
#: warehouse/templates/accounts/recovery-code.html:17
#: warehouse/templates/accounts/register.html:17
Expand Down Expand Up @@ -2347,7 +2331,7 @@ msgstr ""
#: warehouse/templates/manage/project/release.html:137
#: warehouse/templates/manage/project/releases.html:178
#: warehouse/templates/manage/project/settings.html:111
#: warehouse/templates/search/results.html:199
#: warehouse/templates/search/results.html:198
msgid "Close"
msgstr ""

Expand Down Expand Up @@ -7789,7 +7773,7 @@ msgstr ""

#: warehouse/templates/search/results.html:18
#: warehouse/templates/search/results.html:114
#: warehouse/templates/search/results.html:212
#: warehouse/templates/search/results.html:211
msgid "Search results"
msgstr ""

Expand Down Expand Up @@ -7861,24 +7845,20 @@ msgstr ""
msgid "Date last updated"
msgstr ""

#: warehouse/templates/search/results.html:181
msgid "Trending"
msgstr ""

#: warehouse/templates/search/results.html:194
#: warehouse/templates/search/results.html:193
msgid "Filter"
msgstr ""

#: warehouse/templates/search/results.html:205
#: warehouse/templates/search/results.html:204
msgid "Add filter"
msgstr ""

#: warehouse/templates/search/results.html:221
#: warehouse/templates/search/results.html:220
#, python-format
msgid "There were no results for '%(term)s'"
msgstr ""

#: warehouse/templates/search/results.html:223
#: warehouse/templates/search/results.html:222
#, python-format
msgid "There were no results for '%(filters)s' filter"
msgid_plural "There were no results for '%(filters)s' filters"
Expand Down
Loading

0 comments on commit 748138e

Please sign in to comment.