Update pelican_quickstart.py

Have pelican_quickstart generate a requirements.txt
This commit is contained in:
Stuart Axon 2018-11-15 00:35:11 +00:00 committed by GitHub
commit c01eb8e6ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,9 +8,9 @@ import locale
import os import os
import sys import sys
from jinja2 import Environment, FileSystemLoader import pkg_resources
import pytz import pytz
from jinja2 import Environment, FileSystemLoader
try: try:
import readline # NOQA import readline # NOQA
@ -19,6 +19,7 @@ except ImportError:
try: try:
import tzlocal import tzlocal
_DEFAULT_TIMEZONE = tzlocal.get_localzone().zone _DEFAULT_TIMEZONE = tzlocal.get_localzone().zone
except ImportError: except ImportError:
_DEFAULT_TIMEZONE = 'Europe/Paris' _DEFAULT_TIMEZONE = 'Europe/Paris'
@ -45,7 +46,6 @@ _jinja_env = Environment(
trim_blocks=True, trim_blocks=True,
) )
_GITHUB_PAGES_BRANCHES = { _GITHUB_PAGES_BRANCHES = {
'personal': 'master', 'personal': 'master',
'project': 'gh-pages' 'project': 'gh-pages'
@ -111,6 +111,7 @@ def decoding_strings(f):
else: else:
return out.decode(sys.stdin.encoding) return out.decode(sys.stdin.encoding)
return out return out
return wrapper return wrapper
@ -189,6 +190,14 @@ def ask(question, answer=str_compat, default=None, length=None):
'Argument `answer` must be str_compat, bool, or integer') 'Argument `answer` must be str_compat, bool, or integer')
def write_requirements_txt():
distribution = pkg_resources.working_set.by_key['pelican']
with open(os.path.join(CONF['basedir'], 'requirements.txt'), 'w') as f:
f.write('{}\n'.format(distribution.as_requirement()))
for dependency in sorted(distribution.requires()):
f.write('{}\n'.format(dependency))
def ask_timezone(question, default, tzurl): def ask_timezone(question, default, tzurl):
"""Prompt for time zone and validate input""" """Prompt for time zone and validate input"""
lower_tz = [tz.lower() for tz in pytz.all_timezones] lower_tz = [tz.lower() for tz in pytz.all_timezones]
@ -361,6 +370,8 @@ needed by Pelican.
fd.close() fd.close()
except OSError as e: except OSError as e:
print('Error: {0}'.format(e)) print('Error: {0}'.format(e))
write_requirements_txt()
if automation: if automation:
try: try: