8000 Support local file paths as a value of PEP_ARTIFACT_URL (#1428) · python/pythondotorg@f17ceb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f17ceb8

Browse files
mozillazgberkerpeksag
authored andcommitted
Support local file paths as a value of PEP_ARTIFACT_URL (#1428)
1 parent f1747e7 commit f17ceb8

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

peps/management/commands/generate_pep_pages.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,7 @@ def verbose(msg):
5252

5353
with ExitStack() as stack:
5454
verbose(f"== Fetching PEP artifact from {settings.PEP_ARTIFACT_URL}")
55-
peps_last_updated = get_peps_last_updated()
56-
with requests.get(settings.PEP_ARTIFACT_URL, stream=True) as r:
57-
artifact_last_modified = parsedate(r.headers['last-modified'])
58-
if peps_last_updated > artifact_last_modified:
59-
verbose(f"== No update to artifacts, we're done here!")
60-
return
61-
62-
temp_file = stack.enter_context(TemporaryFile())
63-
for chunk in r.iter_content(chunk_size=8192):
64-
if chunk:
65-
temp_file.write(chunk)
66-
67-
temp_file.seek(0)
68-
55+
temp_file = self.get_artifact_tarball(stack, verbose)
6956
temp_dir = stack.enter_context(TemporaryDirectory())
7057
tar_ball = stack.enter_context(TarFile.open(fileobj=temp_file, mode='r:gz'))
7158
tar_ball.extractall(path=temp_dir, numeric_owner=False)
@@ -129,3 +116,23 @@ def verbose(msg):
129116
verbose("- Skipping non-PEP related image '{}'".format(img))
130117

131118
verbose("== Finished")
119+
120+
def get_artifact_tarball(self, stack, verbose):
121+
artifact_url = settings.PEP_ARTIFACT_URL
122+
if not artifact_url.startswith(('http://', 'https://')):
123+
return stack.enter_context(open(artifact_url, 'rb'))
124+
125+
peps_last_updated = get_peps_last_updated()
126+
with requests.get(artifact_url, stream=True) as r:
127+
artifact_last_modified = parsedate(r.headers['last-modified'])
128+
if peps_last_updated > artifact_last_modified:
129+
verbose(f"== No update to artifacts, we're done here!")
130+
return
131+
132+
temp_file = stack.enter_context(TemporaryFile())
133+
for chunk in r.iter_content(chunk_size=8192):
134+
if chunk:
135+
temp_file.write(chunk)
136+
137+
temp_file.seek(0)
138+
return temp_file

peps/tests/test_commands.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def setUp(self):
3232
)
3333

3434
@responses.activate
35-
def test_generate_pep_pages_real(self):
35+
def test_generate_pep_pages_real_with_remote_artifact(self):
36+
call_command('generate_pep_pages')
37+
38+
@override_settings(PEP_ARTIFACT_URL=FAKE_PEP_ARTIFACT)
39+
def test_generate_pep_pages_real_with_local_artifact(self):
3640
call_command('generate_pep_pages')
3741

3842
@responses.activate

pydotorg/settings/local.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424

2525
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
2626

27-
# Set the URL to where to fetch PEP artifacts from
28-
PEP_ARTIFACT_URL = 'https://pythondotorg-assets-staging.s3.amazonaws.com/fake-peps.tar.gz'
27+
# Set the path to where to fetch PEP artifacts from.
28+
# The value can be a local path or a remote URL.
29+
PEP_ARTIFACT_URL = os.path.join(BASE, 'peps/tests/peps.tar.gz')
2930

3031
# Use Dummy SASS compiler to avoid performance issues and remove the need to
3132
# have a sass compiler installed at all during local development if you aren't

0 commit comments

Comments
 (0)
0