Getting started with 0.8 branch

76 views
Skip to first unread message

Ravi

unread,
Jul 2, 2012, 1:27:19 AM7/2/12
to blogofil...@googlegroups.com
Hi,
How do I get a new site started with the development branch? Is the
following process reasonably accurate on a Fedora 17 system?

Is this the right way to set up the plugins branch?

# Set up virtualenv and activate it
git checkout .../EnigmaCurry/blogofile.git
cd blogofile
python setup.py install
# wait for a while setuptools does its work
cd ..
git checkout .../EnigmaCurry/blogofile_blog.git
cd blogofile_blog
python setup.py install
cd ..

Starting a new site:

blogofile init mysite blog
cd mysite
# modify _config.py
blogofile build
blogofile serve

With the steps above, "blogofile init" fails because blogofile_blog is
installed as a zipped egg; unzipping the egg manually fixes the problem. Could
this be done automatically?

Second, when trying to remove the twitter feed from the sidebar by removing
the appropriate sections in _templates/sidebar.mako and js/site.js, the
twitter sidebar vanishes only for the main page but is still present in all of
the blog posts. Editing the installed
site-packages/.../blogofile_blog/site_src/_templates/sidebar.mako
does remove the sidebar. Hence, for blog posts, the template path is messed
up. In fact, printing out the value of config.template_path from init() in
site-packages/.../blogofile_blog/__init__.py
shows that mysite's _config.py's customization failes to override the path to
the default sidebar.mako. How can I work around this?

Regards,
Ravi


Doug Latornell

unread,
Jul 2, 2012, 3:17:28 PM7/2/12
to blogofil...@googlegroups.com
On Sun, Jul 1, 2012 at 10:27 PM, Ravi <lists...@lavabit.com> wrote:
> Hi,
>   How do I get a new site started with the development branch? Is the
> following process reasonably accurate on a Fedora 17 system?

First off, apologies that the docs are lagging the code. These getting
started steps should be in the 0.8 docs. My excuse is more cycling
than coding lately :-) Thanks for persevering to figure out the steps,
and for reporting the issues you've run into.

>
> Is this the right way to set up the plugins branch?
>
>   # Set up virtualenv and activate it
>   git checkout .../EnigmaCurry/blogofile.git
>   cd blogofile
>   python setup.py install
>   # wait for a while setuptools does its work
>   cd ..
>   git checkout .../EnigmaCurry/blogofile_blog.git
>   cd blogofile_blog
>   python setup.py install
>   cd ..
>
> Starting a new site:
>
>   blogofile init mysite blog
>   cd mysite
>   # modify _config.py
>   blogofile build
>   blogofile serve

Yes, the above is all correct. I just reproduced those steps
successfully on OS/X 10.6.8

>
> With the steps above, "blogofile init" fails because blogofile_blog is
> installed as a zipped egg; unzipping the egg manually fixes the problem. Could
> this be done automatically?

In my case the blogofile_blog egg is not zipped. I wonder why it is
not unzipped on Fedora? Having it unzipped is crucial because the
plugin init process uses shutil.copytree to copy the files from the
plugin's site_src to your mysite directory.

I will investigate... Can you please send me an ls of your virtualenv
site-packages directory, and your Python and virtualenv versions?
Actually, it would be wonderful if you could open an issue about this
on https://github.com/EnigmaCurry/blogofile with that info.

One guess is that whether or not the blogofile_blog egg is zipped is
being driven by the difference in zip-safe default handling between
setuptools and distribute.

>
> Second, when trying to remove the twitter feed from the sidebar by removing
> the appropriate sections in _templates/sidebar.mako and js/site.js, the
> twitter sidebar vanishes only for the main page but is still present in all of
> the blog posts. Editing the installed
>   site-packages/.../blogofile_blog/site_src/_templates/sidebar.mako
> does remove the sidebar. Hence, for blog posts, the template path is messed
> up. In fact, printing out the value of config.template_path from init() in
>   site-packages/.../blogofile_blog/__init__.py
> shows that mysite's _config.py's customization failes to override the path to
> the default sidebar.mako. How can I work around this?

I think might be an example of the issue I warned about in
https://groups.google.com/d/topic/blogofile-discuss/TNXBpb-_EWs/discussion

As you observe, the "resolution order" for templates is getting messed
up somewhere along the line. I haven't had a chance to get to the root
of this issue. It's small consolation for you, I know, but I
appreciate that you have confirmed that it is a generic issue rather
than one that is specific to the structure of my personal site.

> Regards,
> Ravi

Thanks again for helping to test 0.8.

Doug

Ravi

unread,
Jul 2, 2012, 10:17:43 PM7/2/12
to blogofil...@googlegroups.com
On Monday, July 02, 2012 12:17:28 PM Doug Latornell wrote:
> > Second, when trying to remove the twitter feed from the sidebar by
> > removing
> > the appropriate sections in _templates/sidebar.mako and js/site.js, the
> > twitter sidebar vanishes only for the main page but is still present in
> > all of the blog posts. Editing the installed
> > site-packages/.../blogofile_blog/site_src/_templates/sidebar.mako
> > does remove the sidebar. Hence, for blog posts, the template path is
> > messed
> > up. In fact, printing out the value of config.template_path from init() in
> > site-packages/.../blogofile_blog/__init__.py
> > shows that mysite's _config.py's customization failes to override the path
> > to the default sidebar.mako. How can I work around this?
>
> I think might be an example of the issue I warned about in
> https://groups.google.com/d/topic/blogofile-discuss/TNXBpb-_EWs/discussion
>
> As you observe, the "resolution order" for templates is getting messed
> up somewhere along the line. I haven't had a chance to get to the root
> of this issue.

I think I found the root cause of the problem, I think. The issue is that the
init() function in
blogofile_blog/site_src/_controllers/blog/__init__.py
says this:
if config.template_path:
#Add the user's custom template path first
tools.add_template_dir(config.template_path)
The comment is wrong however, since tools.add_template_dir appends the path to
the list of template lookup paths, instead of inserting it first. Here is a
simple fix, in two parts:

1. Change PluginTools.add_template_dir in blogofile/plugins.py as follows:
def add_template_dir(self, path, append=True):
if append:
self.template_lookup.directories.append(path)
else:
self.template_lookup.directories.insert(0, path)

2. Next, change init() in
blogofile_blog/site_src/_controllers/blog/__init__.py
as follows:
if config.template_path:
#Add the user's custom template path first
tools.add_template_dir(config.template_path,False)

This fixes the issue of template lookup order, as far as I can tell. If you
have a better fix, please let me know.

Regards,
Ravi


Doug Latornell

unread,
Jul 5, 2012, 1:20:01 AM7/5/12
to blogofil...@googlegroups.com
Thanks for digging into this, Ravi!

I think that you're right, although I had to do one more thing to get
the sidebar in my site to behave properly (I've replaced the Twitter
feed with an Flickr widget but it was reverting to the Twitter feed
widget on the blog and archive pages). In
PluginTools.__get_template_lookup() I also had to change the template
order in the directories list to put the user _templates dir before
the one in src_dir:

def __get_template_lookup(self):
return TemplateLookup(
directories=[
"_templates", os.path.join(self.get_src_dir(),
"_templates")],
input_encoding='utf-8', output_encoding='utf-8',
encoding_errors='replace')

Can you please try making that change in your code and let me know if
it breaks anything for you?

Thanks...

Doug

Ravi

unread,
Jul 5, 2012, 11:33:19 AM7/5/12
to blogofil...@googlegroups.com
On Wednesday, July 04, 2012 10:20:01 PM Doug Latornell wrote:
> I think that you're right, although I had to do one more thing to get
> the sidebar in my site to behave properly (I've replaced the Twitter
> feed with an Flickr widget but it was reverting to the Twitter feed
> widget on the blog and archive pages). In
> PluginTools.__get_template_lookup() I also had to change the template
> order in the directories list to put the user _templates dir before
> the one in src_dir:
>
> def __get_template_lookup(self):
> return TemplateLookup(
> directories=[
> "_templates", os.path.join(self.get_src_dir(),
> "_templates")],
> input_encoding='utf-8', output_encoding='utf-8',
> encoding_errors='replace')
>
> Can you please try making that change in your code and let me know if
> it breaks anything for you?

That kind of works. Unfortunately, blog templates in the user's
_templates/blog directory are not picked up. It seemed that knowledge of the
user's _template directory structure was too much to assume. My solution is to
let the user specify as many directories as wished in the controller's init
file:

def init():
config["url"] = bf.config.site.url + config["path"]
if config.template_path:
#Add the user's custom template path first
if not isinstance( config.template_path, list ):
template_path = [config.template_path]
else:
template_path = config.template_path
for tp in template_path:
tools.add_template_dir(tp,False)
tools.add_template_dir(os.path.join(tools.get_src_dir(),"_templates/blog"))

In my config, I have:

blog.template_path = ["_templates","_templates/blog"]

Apart from this, I had to fix an issue related to unicode. Unicode characters
that were syntax highlighted were not handled correctly in
syntax_highlight.py. The change was pretty trivial:

--- a/_filters/syntax_highlight.py 2012-06-30 09:53:29.516564835 -0700
+++ b/_filters/syntax_highlight.py 2012-07-04 19:22:20.671403159 -0700
@@ -61,7 +61,7 @@
config = HC(
css_dir = "/css",
preload_styles = [],
- style = "murphy")
+ style = "solarized")

def init():
#This filter normally only loads pygments styles when needed.
@@ -107,7 +107,7 @@
#But get rid of the last <br> which throws off line numbers:
highlighted =
"</pre></div>".join(highlighted.rsplit("</pre></div><br/>"))
#Surround the text with newlines so markdown etc parse properly:
- highlighted = "\n\n{0}\n\n".format(highlighted)
+ highlighted = u"\n\n{0}\n\n".format(highlighted)
return highlighted

def parse_args(args):


Hope this helps. An example of the generated code can be found at my site:
http://code.lexarcana.com

Regards,
Ravi


Reply all
Reply to author
Forward
0 new messages