Skip to content

Commit 708a3d4

Browse files
committed
Fully implement PEP 527
1 parent 9ea09b4 commit 708a3d4

File tree

4 files changed

+49
-128
lines changed

4 files changed

+49
-128
lines changed

tests/unit/forklift/test_legacy.py

+4-101
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,10 @@ def test_fails_invalid_version(self, pyramid_config, pyramid_request, version):
786786
resp = excinfo.value
787787

788788
assert resp.status_code == 400
789-
assert resp.status == "400 Unknown protocol version."
789+
assert (
790+
resp.status
791+
== "400 Invalid value for filetype. Error: Use a known file type."
792+
)
790793

791794
@pytest.mark.parametrize(
792795
("post_data", "message"),
@@ -2485,106 +2488,6 @@ def storage_service_store(path, file_path, *, meta):
24852488
)
24862489
]
24872490

2488-
def test_upload_succeeds_with_legacy_ext(
2489-
self, tmpdir, monkeypatch, pyramid_config, db_request, metrics
2490-
):
2491-
monkeypatch.setattr(tempfile, "tempdir", str(tmpdir))
2492-
2493-
pyramid_config.testing_securitypolicy(userid=1)
2494-
2495-
user = UserFactory.create()
2496-
EmailFactory.create(user=user)
2497-
project = ProjectFactory.create(allow_legacy_files=True)
2498-
release = ReleaseFactory.create(project=project, version="1.0")
2499-
RoleFactory.create(user=user, project=project)
2500-
2501-
filename = "{}-{}.tar.bz2".format(project.name, release.version)
2502-
2503-
db_request.user = user
2504-
db_request.remote_addr = "10.10.10.30"
2505-
db_request.user_agent = "warehouse-tests/6.6.6"
2506-
db_request.POST = MultiDict(
2507-
{
2508-
"metadata_version": "1.2",
2509-
"name": project.name,
2510-
"version": release.version,
2511-
"filetype": "sdist",
2512-
"pyversion": "source",
2513-
"md5_digest": _TAR_BZ2_PKG_MD5,
2514-
"content": pretend.stub(
2515-
filename=filename,
2516-
file=io.BytesIO(_TAR_BZ2_PKG_TESTDATA),
2517-
type="application/tar",
2518-
),
2519-
}
2520-
)
2521-
2522-
def storage_service_store(path, file_path, *, meta):
2523-
with open(file_path, "rb") as fp:
2524-
assert fp.read() == _TAR_BZ2_PKG_TESTDATA
2525-
2526-
storage_service = pretend.stub(store=storage_service_store)
2527-
db_request.find_service = lambda svc, name=None, context=None: {
2528-
IFileStorage: storage_service,
2529-
IMetricsService: metrics,
2530-
}.get(svc)
2531-
2532-
monkeypatch.setattr(legacy, "_is_valid_dist_file", lambda *a, **kw: True)
2533-
2534-
resp = legacy.file_upload(db_request)
2535-
2536-
assert resp.status_code == 200
2537-
2538-
def test_upload_succeeds_with_legacy_type(
2539-
self, tmpdir, monkeypatch, pyramid_config, db_request, metrics
2540-
):
2541-
monkeypatch.setattr(tempfile, "tempdir", str(tmpdir))
2542-
2543-
pyramid_config.testing_securitypolicy(userid=1)
2544-
2545-
user = UserFactory.create()
2546-
EmailFactory.create(user=user)
2547-
project = ProjectFactory.create(allow_legacy_files=True)
2548-
release = ReleaseFactory.create(project=project, version="1.0")
2549-
RoleFactory.create(user=user, project=project)
2550-
2551-
filename = "{}-{}.tar.gz".format(project.name, release.version)
2552-
2553-
db_request.user = user
2554-
db_request.remote_addr = "10.10.10.30"
2555-
db_request.user_agent = "warehouse-tests/6.6.6"
2556-
db_request.POST = MultiDict(
2557-
{
2558-
"metadata_version": "1.2",
2559-
"name": project.name,
2560-
"version": release.version,
2561-
"filetype": "bdist_dumb",
2562-
"pyversion": "3.5",
2563-
"md5_digest": _TAR_GZ_PKG_MD5,
2564-
"content": pretend.stub(
2565-
filename=filename,
2566-
file=io.BytesIO(_TAR_GZ_PKG_TESTDATA),
2567-
type="application/tar",
2568-
),
2569-
}
2570-
)
2571-
2572-
def storage_service_store(path, file_path, *, meta):
2573-
with open(file_path, "rb") as fp:
2574-
assert fp.read() == _TAR_GZ_PKG_TESTDATA
2575-
2576-
storage_service = pretend.stub(store=storage_service_store)
2577-
db_request.find_service = lambda svc, name=None, context=None: {
2578-
IFileStorage: storage_service,
2579-
IMetricsService: metrics,
2580-
}.get(svc)
2581-
2582-
monkeypatch.setattr(legacy, "_is_valid_dist_file", lambda *a, **kw: True)
2583-
2584-
resp = legacy.file_upload(db_request)
2585-
2586-
assert resp.status_code == 200
2587-
25882491
@pytest.mark.parametrize("plat", ["linux_x86_64", "linux_x86_64.win32"])
25892492
def test_upload_fails_with_unsupported_wheel_plat(
25902493
self, monkeypatch, pyramid_config, db_request, plat

warehouse/forklift/legacy.py

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

143143

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

150146

151147
_wheel_file_re = re.compile(
@@ -464,16 +460,7 @@ class MetadataForm(forms.Form):
464460
validators=[
465461
wtforms.validators.DataRequired(),
466462
wtforms.validators.AnyOf(
467-
[
468-
"bdist_dmg",
469-
"bdist_dumb",
470-
"bdist_egg",
471-
"bdist_msi",
472-
"bdist_rpm",
473-
"bdist_wheel",
474-
"bdist_wininst",
475-
"sdist",
476-
],
463+
["bdist_egg", "bdist_wheel", "sdist",],
477464
message="Use a known file type.",
478465
),
479466
]
@@ -1150,7 +1137,7 @@ def file_upload(request):
11501137
)
11511138

11521139
# Make sure the filename ends with an allowed extension.
1153-
if _dist_file_regexes[project.allow_legacy_files].search(filename) is None:
1140+
if _dist_file_re.search(filename) is None:
11541141
raise _exc_with_message(
11551142
HTTPBadRequest,
11561143
"Invalid file extension: Use .egg, .tar.gz, .whl or .zip "
@@ -1172,16 +1159,6 @@ def file_upload(request):
11721159
):
11731160
raise _exc_with_message(HTTPBadRequest, "Invalid distribution file.")
11741161

1175-
# Ensure that the package filetype is allowed.
1176-
# TODO: Once PEP 527 is completely implemented we should be able to delete
1177-
# this and just move it into the form itself.
1178-
if not project.allow_legacy_files and form.filetype.data not in {
1179-
"sdist",
1180-
"bdist_wheel",
1181-
"bdist_egg",
1182-
}:
1183-
raise _exc_with_message(HTTPBadRequest, "Unknown type of file.")
1184-
11851162
# The project may or may not have a file size specified on the project, if
11861163
# it does then it may or may not be smaller or larger than our global file
11871164
# size limits.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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: 5c029d9ef925
17+
Create Date: 2020-03-12 17:51:08.447903
18+
"""
19+
20+
import sqlalchemy as sa
21+
22+
from alembic import op
23+
24+
revision = "b265ed9eeb8a"
25+
down_revision = "5c029d9ef925"
26+
27+
28+
def upgrade():
29+
op.drop_column("projects", "allow_legacy_files")
30+
31+
32+
def downgrade():
33+
op.add_column(
34+
"projects",
35+
sa.Column(
36+
"allow_legacy_files",
37+
sa.BOOLEAN(),
38+
server_default=sa.text("false"),
39+
autoincrement=False,
40+
nullable=False,
41+
),
42+
)

warehouse/packaging/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class Project(SitemapMixin, db.Model):
122122
has_docs = Column(Boolean)
123123
upload_limit = Column(Integer, nullable=True)
124124
last_serial = Column(Integer, nullable=False, server_default=sql.text("0"))
125-
allow_legacy_files = Column(Boolean, nullable=False, server_default=sql.false())
126125
zscore = Column(Float, nullable=True)
127126

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

0 commit comments

Comments
 (0)