Skip to content

Commit

Permalink
Add ignore_files to pserve configuration section
Browse files Browse the repository at this point in the history
  • Loading branch information
ericatkin authored and mmerickel committed Mar 22, 2019
1 parent eda95b5 commit c380d02
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,6 @@ Contributors

- Alexandre Yukio Harano, 2018/10/05

- Eric Atkin, 2019/02/15

- Arijit Basu, 2019/02/19
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def readfile(name):
VERSION = '2.0.dev0'

install_requires = [
'hupper',
'hupper >= 1.5', # ignore_files support
'plaster',
'plaster_pastedeploy',
'setuptools',
Expand Down
24 changes: 21 additions & 3 deletions src/pyramid/scripts/pserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
from pyramid.settings import aslist


def main(argv=sys.argv, quiet=False):
command = PServeCommand(argv, quiet=quiet)
def main(argv=sys.argv, quiet=False, original_ignore_files=None):
command = PServeCommand(
argv, quiet=quiet, original_ignore_files=original_ignore_files
)
return command.run()


Expand Down Expand Up @@ -131,13 +133,15 @@ class PServeCommand(object):

_scheme_re = re.compile(r'^[a-z][a-z]+:', re.I)

def __init__(self, argv, quiet=False):
def __init__(self, argv, quiet=False, original_ignore_files=None):
self.args = self.parser.parse_args(argv[1:])
if quiet:
self.args.verbose = 0
if self.args.reload:
self.worker_kwargs = {'argv': argv, "quiet": quiet}
self.watch_files = set()
self.ignore_files = set()
self.original_ignore_files = original_ignore_files

def out(self, msg): # pragma: no cover
if self.args.verbose > 0:
Expand All @@ -151,6 +155,9 @@ def pserve_file_config(self, loader, global_conf=None):
config_path = self.get_config_path(loader)
here = os.path.dirname(config_path)
watch_files = aslist(settings.get('watch_files', ''), flatten=False)
self.ignore_files = set(
aslist(settings.get('ignore_files', ''), flatten=False)
)

# track file paths relative to the ini file
resolver = AssetResolver(package=None)
Expand Down Expand Up @@ -232,11 +239,13 @@ def open_browser():
if self.args.reload and not hupper.is_active():
if self.args.verbose > 1:
self.out('Running reloading file monitor')
self.worker_kwargs['original_ignore_files'] = self.ignore_files
hupper.start_reloader(
'pyramid.scripts.pserve.main',
reload_interval=int(self.args.reload_interval),
verbose=self.args.verbose,
worker_kwargs=self.worker_kwargs,
ignore_files=self.ignore_files,
)
return 0

Expand All @@ -250,6 +259,15 @@ def open_browser():
reloader = hupper.get_reloader()
reloader.watch_files(list(self.watch_files))

if (
self.original_ignore_files is not None
and self.original_ignore_files != self.ignore_files
):
self.out(
'A change to "ignore_files" was detected but it will not take'
' effect until pserve is restarted.'
)

server = server_loader.get_wsgi_server(server_name, config_vars)

app = loader.get_wsgi_app(app_name, config_vars)
Expand Down
32 changes: 30 additions & 2 deletions tests/test_scripts/test_pserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def _getTargetClass(self):

return PServeCommand

def _makeOne(self, *args):
def _makeOne(self, *args, **kwargs):
effargs = ['pserve']
effargs.extend(args)
cmd = self._getTargetClass()(effargs)
cmd = self._getTargetClass()(effargs, **kwargs)
cmd.out = self.out
self.loader = dummy.DummyLoader()
cmd._get_config_loader = self.loader
Expand All @@ -49,6 +49,32 @@ def get_app(name, global_conf):
inst.run()
self.assertEqual(app.global_conf, {'a': '1', 'b': '2'})

def test_original_ignore_files(self):
msg = 'A change to "ignore_files" was detected'

def get_app(name, global_conf):
app.name = name
app.global_conf = global_conf
return app

inst = self._makeOne('development.ini')
app = dummy.DummyApp()
self.loader.get_wsgi_app = get_app
self.loader.server = lambda x: x
self.loader.settings = {'pserve': {'ignore_files': '*.txt'}}
inst.run()
self.assertNotIn(msg, self.out_.getvalue())

inst = self._makeOne(
'development.ini', original_ignore_files={'*.txt'}
)
app = dummy.DummyApp()
self.loader.get_wsgi_app = get_app
self.loader.server = lambda x: x
self.loader.settings = {'pserve': {'ignore_files': 'foo/*.txt'}}
inst.run()
self.assertIn(msg, self.out_.getvalue())

def test_parse_vars_bad(self):
inst = self._makeOne('development.ini', 'a')
self.assertRaises(ValueError, inst.run)
Expand Down Expand Up @@ -122,7 +148,9 @@ def dummy_start_reloader(*args, **kwargs):
'worker_kwargs': {
'argv': ['pserve', '--reload', 'development.ini'],
'quiet': False,
'original_ignore_files': set(),
},
'ignore_files': set(),
},
)

Expand Down

0 comments on commit c380d02

Please sign in to comment.