Skip to content

Commit d20367b

Browse files
committed
Fully implement PEP 527
1 parent f4d91f2 commit d20367b

File tree

4 files changed

+47
-129
lines changed

4 files changed

+47
-129
lines changed

tests/unit/forklift/test_legacy.py

+4-101
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,10 @@ def test_upload_fails_with_legacy_type(self, pyramid_config, db_request):
15131513
resp = excinfo.value
15141514

15151515
assert resp.status_code == 400
1516-
assert resp.status == "400 Unknown type of file."
1516+
assert (
1517+
resp.status
1518+
== "400 Invalid value for filetype. Error: Use a known file type."
1519+
)
15171520

15181521
def test_upload_fails_with_legacy_ext(self, pyramid_config, db_request):
15191522
pyramid_config.testing_securitypolicy(userid=1)
@@ -2519,106 +2522,6 @@ def storage_service_store(path, file_path, *, meta):
25192522
)
25202523
]
25212524

2522-
def test_upload_succeeds_with_legacy_ext(
2523-
self, tmpdir, monkeypatch, pyramid_config, db_request, metrics
2524-
):
2525-
monkeypatch.setattr(tempfile, "tempdir", str(tmpdir))
2526-
2527-
pyramid_config.testing_securitypolicy(userid=1)
2528-
2529-
user = UserFactory.create()
2530-
EmailFactory.create(user=user)
2531-
project = ProjectFactory.create(allow_legacy_files=True)
2532-
release = ReleaseFactory.create(project=project, version="1.0")
2533-
RoleFactory.create(user=user, project=project)
2534-
2535-
filename = "{}-{}.tar.bz2".format(project.name, release.version)
2536-
2537-
db_request.user = user
2538-
db_request.remote_addr = "10.10.10.30"
2539-
db_request.user_agent = "warehouse-tests/6.6.6"
2540-
db_request.POST = MultiDict(
2541-
{
2542-
"metadata_version": "1.2",
2543-
"name": project.name,
2544-
"version": release.version,
2545-
"filetype": "sdist",
2546-
"pyversion": "source",
2547-
"md5_digest": _TAR_BZ2_PKG_MD5,
2548-
"content": pretend.stub(
2549-
filename=filename,
2550-
file=io.BytesIO(_TAR_BZ2_PKG_TESTDATA),
2551-
type="application/tar",
2552-
),
2553-
}
2554-
)
2555-
2556-
def storage_service_store(path, file_path, *, meta):
2557-
with open(file_path, "rb") as fp:
2558-
assert fp.read() == _TAR_BZ2_PKG_TESTDATA
2559-
2560-
storage_service = pretend.stub(store=storage_service_store)
2561-
db_request.find_service = lambda svc, name=None, context=None: {
2562-
IFileStorage: storage_service,
2563-
IMetricsService: metrics,
2564-
}.get(svc)
2565-
2566-
monkeypatch.setattr(legacy, "_is_valid_dist_file", lambda *a, **kw: True)
2567-
2568-
resp = legacy.file_upload(db_request)
2569-
2570-
assert resp.status_code == 200
2571-
2572-
def test_upload_succeeds_with_legacy_type(
2573-
self, tmpdir, monkeypatch, pyramid_config, db_request, metrics
2574-
):
2575-
monkeypatch.setattr(tempfile, "tempdir", str(tmpdir))
2576-
2577-
pyramid_config.testing_securitypolicy(userid=1)
2578-
2579-
user = UserFactory.create()
2580-
EmailFactory.create(user=user)
2581-
project = ProjectFactory.create(allow_legacy_files=True)
2582-
release = ReleaseFactory.create(project=project, version="1.0")
2583-
RoleFactory.create(user=user, project=project)
2584-
2585-
filename = "{}-{}.tar.gz".format(project.name, release.version)
2586-
2587-
db_request.user = user
2588-
db_request.remote_addr = "10.10.10.30"
2589-
db_request.user_agent = "warehouse-tests/6.6.6"
2590-
db_request.POST = MultiDict(
2591-
{
2592-
"metadata_version": "1.2",
2593-
"name": project.name,
2594-
"version": release.version,
2595-
"filetype": "bdist_dumb",
2596-
"pyversion": "3.5",
2597-
"md5_digest": _TAR_GZ_PKG_MD5,
2598-
"content": pretend.stub(
2599-
filename=filename,
2600-
file=io.BytesIO(_TAR_GZ_PKG_TESTDATA),
2601-
type="application/tar",
2602-
),
2603-
}
2604-
)
2605-
2606-
def storage_service_store(path, file_path, *, meta):
2607-
with open(file_path, "rb") as fp:
2608-
assert fp.read() == _TAR_GZ_PKG_TESTDATA
2609-
2610-
storage_service = pretend.stub(store=storage_service_store)
2611-
db_request.find_service = lambda svc, name=None, context=None: {
2612-
IFileStorage: storage_service,
2613-
IMetricsService: metrics,
2614-
}.get(svc)
2615-
2616-
monkeypatch.setattr(legacy, "_is_valid_dist_file", lambda *a, **kw: True)
2617-
2618-
resp = legacy.file_upload(db_request)
2619-
2620-
assert resp.status_code == 200
2621-
26222525
@pytest.mark.parametrize("plat", ["linux_x86_64", "linux_x86_64.win32"])
26232526
def test_upload_fails_with_unsupported_wheel_plat(
26242527
self, monkeypatch, pyramid_config, db_request, plat

warehouse/forklift/legacy.py

+3-27
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,7 @@ def _valid_platform_tag(platform_tag):
142142
_error_message_order = ["metadata_version", "name", "version"]
143143

144144

145-
_dist_file_regexes = {
146-
# True/False is for legacy or not.
147-
True: re.compile(r".+?\.(exe|tar\.gz|bz2|rpm|deb|zip|tgz|egg|dmg|msi|whl)$", re.I),
148-
False: re.compile(r".+?\.(tar\.gz|zip|whl|egg)$", re.I),
149-
}
145+
_dist_file_re = re.compile(r".+?\.(tar\.gz|zip|whl|egg)$", re.I)
150146

151147

152148
_wheel_file_re = re.compile(
@@ -500,17 +496,7 @@ class MetadataForm(forms.Form):
500496
validators=[
501497
wtforms.validators.DataRequired(),
502498
wtforms.validators.AnyOf(
503-
[
504-
"bdist_dmg",
505-
"bdist_dumb",
506-
"bdist_egg",
507-
"bdist_msi",
508-
"bdist_rpm",
509-
"bdist_wheel",
510-
"bdist_wininst",
511-
"sdist",
512-
],
513-
message="Use a known file type.",
499+
["bdist_egg", "bdist_wheel", "sdist"], message="Use a known file type.",
514500
),
515501
]
516502
)
@@ -1171,7 +1157,7 @@ def file_upload(request):
11711157
)
11721158

11731159
# Make sure the filename ends with an allowed extension.
1174-
if _dist_file_regexes[project.allow_legacy_files].search(filename) is None:
1160+
if _dist_file_re.search(filename) is None:
11751161
raise _exc_with_message(
11761162
HTTPBadRequest,
11771163
"Invalid file extension: Use .egg, .tar.gz, .whl or .zip "
@@ -1193,16 +1179,6 @@ def file_upload(request):
11931179
):
11941180
raise _exc_with_message(HTTPBadRequest, "Invalid distribution file.")
11951181

1196-
# Ensure that the package filetype is allowed.
1197-
# TODO: Once PEP 527 is completely implemented we should be able to delete
1198-
# this and just move it into the form itself.
1199-
if not project.allow_legacy_files and form.filetype.data not in {
1200-
"sdist",
1201-
"bdist_wheel",
1202-
"bdist_egg",
1203-
}:
1204-
raise _exc_with_message(HTTPBadRequest, "Unknown type of file.")
1205-
12061182
# The project may or may not have a file size specified on the project, if
12071183
# it does then it may or may not be smaller or larger than our global file
12081184
# size limits.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
"""
13+
Fully deprecate legacy distribution types
14+
15+
Revision ID: b265ed9eeb8a
16+
Revises: d15f020ee3df
17+
Create Date: 2020-03-12 17:51:08.447903
18+
"""
19+
20+
from alembic import op
21+
22+
revision = "b265ed9eeb8a"
23+
down_revision = "d15f020ee3df"
24+
25+
26+
def upgrade():
27+
op.drop_column("projects", "allow_legacy_files")
28+
29+
30+
def downgrade():
31+
op.add_column(
32+
"projects",
33+
sa.Column(
34+
"allow_legacy_files",
35+
sa.BOOLEAN(),
36+
server_default=sa.text("false"),
37+
autoincrement=False,
38+
nullable=False,
39+
),
40+
)

warehouse/packaging/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class Project(SitemapMixin, db.Model):
115115
has_docs = Column(Boolean)
116116
upload_limit = Column(Integer, nullable=True)
117117
last_serial = Column(Integer, nullable=False, server_default=sql.text("0"))
118-
allow_legacy_files = Column(Boolean, nullable=False, server_default=sql.false())
119118
zscore = Column(Float, nullable=True)
120119

121120
total_size = Column(BigInteger, server_default=sql.text("0"))

0 commit comments

Comments
 (0)