pyvec / elsa

Helper module for hosting Frozen-Flask based websites on GitHub pages
Other
29 stars 49 forks source link

Simplify adding extra files to watch during development #43

Open honzajavorek opened 6 years ago

honzajavorek commented 6 years ago

During development, Werkzeug's reloader watches just Python files and Jinja templates. Normally, this can be extended by the extra_files keyword argument:

app.run(host='0.0.0.0', ..., extra_files=['woohoo.yml'])

Elsa doesn't support this:

https://github.com/pyvec/elsa/blob/9672d65fdc48feaec3a3963204f1569fd013ad49/elsa/_cli.py#L83

Following workaround works, but it would be nice if Elsa was able to propagate the option in some way, out of the box.

from flask import Flask as BaseFlask

class Flask(BaseFlask):
    def run(self, *args, **kwargs):
        kwargs.setdefault('extra_files', [])
        kwargs['extra_files'].append('.../data.yml')
        return super().run(*args, **kwargs)

app = Flask(__name__)
honzajavorek commented 6 years ago

I'm not sending a PR for adding the argument, because I'm not sure where to add it (what would make sense the most) and I'm not sure having the argument there is something Elsa should actually support.

I'm playing with a thought that it could be actually smarter - e.g. reading MANIFEST.in and watching all files included to the package or something like that. I think feature like that would be a significant convenience and if it's way too greedy (reloading even on files not so important for the actual website rendering), it's probably no real issue.

hroncok commented 6 years ago

Adding it without a workaround should be possible once https://github.com/pyvec/elsa/pull/39 gets done (it's rotting there for quite a while, hopefully i can get to that next semester when i don't teach).

As for some smart handling, I will think about it. Thanks for the proposal.

honzajavorek commented 6 years ago

This is how MANIFEST.in can be parsed:

from setuptools.command.egg_info import FileList

file_list = FileList()
with open('MANIFEST.in') as f:
    for line in f.readlines():
        file_list.process_template_line(line)

file_list.sort()
print(file_list.files)
honzajavorek commented 6 years ago

I'm not sure about MANIFEST.in anymore. Applications will use pipenv mostly, so there will be no package. And recently I got into situation with Sphinx when I dynamically created a file during build, the file was always automatically considered as modified, and caused an endless loop of reloading. Thus I think we should forget about any automagic and just let people to set it as they like.