Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support a [pserve] config section with a list of files to watch #2827

Merged
merged 5 commits into from Dec 10, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

support asset specs in watch_files and variable interpolation

  • Loading branch information...
mmerickel committed Nov 22, 2016
commit 9cab0e7cc24dc95e357db026cead2507111ee93a
@@ -32,6 +32,7 @@

from pyramid.scripts.common import parse_vars
from pyramid.scripts.common import setup_logging
from pyramid.path import AssetResolver
from pyramid.settings import aslist

def main(argv=sys.argv, quiet=False):
@@ -119,8 +120,14 @@ def get_options(self):
restvars = self.args[1:]
return parse_vars(restvars)

def pserve_file_config(self, filename):
config = self.ConfigParser()
def pserve_file_config(self, filename, global_conf=None):
here = os.path.abspath(os.path.dirname(filename))
defaults = {}
if global_conf:
defaults.update(global_conf)
defaults['here'] = here

config = self.ConfigParser(defaults=defaults)
config.optionxform = str
config.read(filename)
try:
@@ -131,11 +138,13 @@ def pserve_file_config(self, filename):
watch_files = aslist(items.get('watch_files', ''), flatten=False)

# track file paths relative to the ini file
basedir = os.path.dirname(filename)
resolver = AssetResolver(package=None)
for file in watch_files:
if not os.path.isabs(file):
file = os.path.join(basedir, file)
self.watch_files.append(os.path.normpath(file))
if ':' in file:
file = resolver.resolve(file).abspath()
elif not os.path.isabs(file):
file = os.path.join(here, file)
self.watch_files.append(os.path.abspath(file))

def run(self): # pragma: no cover
if not self.args:
@@ -185,8 +194,8 @@ def open_browser():

if config_path:
setup_logging(config_path, global_conf=vars)
self.pserve_file_config(config_path, global_conf=vars)
self.watch_files.append(config_path)
self.pserve_file_config(config_path)

if hupper.is_active():
reloader = hupper.get_reloader()
@@ -205,19 +214,16 @@ def open_browser():
msg = 'Starting server.'
self.out(msg)

def serve():
try:
server(app)
except (SystemExit, KeyboardInterrupt) as e:
if self.options.verbose > 1:
raise
if str(e):
msg = ' ' + str(e)
else:
msg = ''
self.out('Exiting%s (-v to see traceback)' % msg)

serve()
try:
server(app)
except (SystemExit, KeyboardInterrupt) as e:
if self.options.verbose > 1:
raise
if str(e):
msg = ' ' + str(e)
else:
msg = ''
self.out('Exiting%s (-v to see traceback)' % msg)

# For paste.deploy server instantiation (egg:pyramid#wsgiref)
def wsgiref_server_runner(wsgi_app, global_conf, **kw): # pragma: no cover
@@ -82,8 +82,9 @@ def __init__(self, *views, **attrs):
self.__request_attrs__ = attrs

class DummyConfigParser(object):
def __init__(self, result):
def __init__(self, result, defaults=None):
self.result = result
self.defaults = defaults

def read(self, filename):
self.filename = filename
@@ -98,8 +99,9 @@ def items(self, section):
class DummyConfigParserFactory(object):
items = None

def __call__(self):
self.parser = DummyConfigParser(self.items)
def __call__(self, defaults=None):
self.defaults = defaults
self.parser = DummyConfigParser(self.items, defaults)
return self.parser

class DummyCloser(object):
@@ -2,6 +2,8 @@
import unittest
from pyramid.tests.test_scripts import dummy

here = os.path.abspath(os.path.dirname(__file__))

class TestPServeCommand(unittest.TestCase):
def setUp(self):
from pyramid.compat import NativeIO
@@ -59,12 +61,19 @@ def test_parse_vars_bad(self):

def test_config_file_finds_watch_files(self):
inst = self._makeOne('development.ini')
self.config_factory.items = [('watch_files', 'foo\nbar\n/baz')]
inst.pserve_file_config('/base/path.ini')
self.config_factory.items = [(
'watch_files',
'foo\n/baz\npyramid.tests.test_scripts:*.py',
)]
inst.pserve_file_config('/base/path.ini', global_conf={'a': '1'})
self.assertEqual(self.config_factory.defaults, {
'a': '1',
'here': os.path.abspath('/base'),
})
self.assertEqual(inst.watch_files, [
os.path.normpath('/base/foo'),
os.path.normpath('/base/bar'),
os.path.normpath('/baz'),
os.path.abspath('/base/foo'),
os.path.abspath('/baz'),
os.path.abspath(os.path.join(here, '*.py')),
])

class Test_main(unittest.TestCase):
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.