Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/pep_generation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The PEP Page Generation process is as follows:
2. From the cloned PEP Repository, run::

$ make -j
$ make rss

3. Set ``PEP_REPO_PATH`` in ``pydotorg/settings/local.py`` to the location
of the cloned PEP Repository
Expand All @@ -31,4 +32,4 @@ This process runs periodically via cron to keep the PEP pages up to date.

See :ref:`management-commands` for all management commands.

.. _PEP Repository: https://github.com/python/peps.git
.. _PEP Repository: https://github.com/python/peps.git
48 changes: 28 additions & 20 deletions peps/management/commands/generate_pep_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,7 @@ def verbose(msg):
verbose("== Starting PEP page generation")

with ExitStack() as stack:
verbose(f"== Fetching PEP artifact from {settings.PEP_ARTIFACT_URL}")
peps_last_updated = get_peps_last_updated()
with requests.get(settings.PEP_ARTIFACT_URL, stream=True) as r:
artifact_last_modified = parsedate(r.headers['last-modified'])
if peps_last_updated > artifact_last_modified:
verbose(f"== No update to artifacts, we're done here!")
return

temp_file = stack.enter_context(TemporaryFile())
for chunk in r.iter_content(chunk_size=8192):
if chunk:
temp_file.write(chunk)

temp_file.seek(0)

temp_dir = stack.enter_context(TemporaryDirectory())
tar_ball = stack.enter_context(TarFile.open(fileobj=temp_file, mode='r:gz'))
tar_ball.extractall(path=temp_dir, numeric_owner=False)

artifacts_path = os.path.join(temp_dir, 'peps')
artifacts_path = self.get_artifacts_path(stack, verbose)

verbose("Generating RSS Feed")
peps_rss = get_peps_rss(artifacts_path)
Expand Down Expand Up @@ -129,3 +110,30 @@ def verbose(msg):
verbose("- Skipping non-PEP related image '{}'".format(img))

verbose("== Finished")

def get_artifacts_path(self, stack, verbose):
if settings.DEBUG and settings.PEP_REPO_PATH:
Copy link
Member

@berkerpeksag berkerpeksag Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should go back to the old method. Downloading and extracting an artifact from S3 sounds like a better idea to me.

I think we can set settings.PEP_ARTIFACT_URL to os.path.join(settings.BASE, 'peps/tests/peps.tar.gz') in settings/local.py. This way contributors wouldn't need to clone python/peps repo if they would like to work on our PEP converter code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

return settings.PEP_REPO_PATH

verbose(f"== Fetching PEP artifact from {settings.PEP_ARTIFACT_URL}")
peps_last_updated = get_peps_last_updated()
with requests.get(settings.PEP_ARTIFACT_URL, stream=True) as r:
artifact_last_modified = parsedate(r.headers['last-modified'])
if peps_last_updated > artifact_last_modified:
verbose(f"== No update to artifacts, we're done here!")
return

temp_file = stack.enter_context(TemporaryFile())
for chunk in r.iter_content(chunk_size=8192):
if chunk:
temp_file.write(chunk)

temp_file.seek(0)

temp_dir = stack.enter_context(TemporaryDirectory())
tar_ball = stack.enter_context(
TarFile.open(fileobj=temp_file, mode='r:gz'))
tar_ball.extractall(path=temp_dir, numeric_owner=False)
artifacts_path = os.path.join(temp_dir, 'peps')

return artifacts_path
13 changes: 9 additions & 4 deletions peps/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
from django.conf import settings
from django.core import serializers
from django.core.management import call_command
from django.core.exceptions import ImproperlyConfigured

import responses

from pages.models import Image

from . import FAKE_PEP_REPO
from . import FAKE_PEP_REPO, FAKE_PEP_ARTIFACT


@responses.activate
class PEPManagementCommandTests(TestCase):

def setUp(self):
Expand All @@ -31,17 +29,24 @@ def setUp(self):
)

@override_settings(PEP_ARTIFACT_URL='https://example.net/fake-peps.tar.gz')
def test_generate_pep_pages_real(self):
@responses.activate
def test_generate_pep_pages_real_with_artifact_url(self):
call_command('generate_pep_pages')

@override_settings(DEBUG=True, PEP_REPO_PATH=FAKE_PEP_REPO)
def test_generate_pep_pages_real_with_local_repo(self):
call_command('generate_pep_pages')

@override_settings(PEP_ARTIFACT_URL='https://example.net/fake-peps.tar.gz')
@responses.activate
def test_image_generated(self):
call_command('generate_pep_pages')
img = Image.objects.get(page__path='dev/peps/pep-3001/')
soup = BeautifulSoup(img.page.content.raw, 'lxml')
self.assertIn(settings.MEDIA_URL, soup.find('img')['src'])

@override_settings(PEP_ARTIFACT_URL='https://example.net/fake-peps.tar.gz')
@responses.activate
def test_dump_pep_pages(self):
call_command('generate_pep_pages')
stdout = io.StringIO()
Expand Down
4 changes: 3 additions & 1 deletion pydotorg/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@
### Registration mailing lists
MAILING_LIST_PSF_MEMBERS = "psf-members-announce-request@python.org"

### PEP Repo Location
### PEP Repo Location on local
PEP_REPO_PATH = ''
### PEP Repo Location on remote
PEP_ARTIFACT_URL = 'https://pythondotorg-assets-staging.s3.amazonaws.com/fake-peps.tar.gz'

### Fastly ###
Expand Down
3 changes: 3 additions & 0 deletions pydotorg/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

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

# Set the path to where the PEP repo's HTML source files are located
# For example, PEP_REPO_PATH = '/Users/frank/work/src/pythondotorg/tmp/peps'
PEP_REPO_PATH = ''
# Set the URL to where to fetch PEP artifacts from
PEP_ARTIFACT_URL = 'https://pythondotorg-assets-staging.s3.amazonaws.com/fake-peps.tar.gz'

Expand Down