Skip to content

Commit

Permalink
Turn Stone into Python package with setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
neuralsandwich committed Jun 6, 2017
1 parent 2b14371 commit ead9c11
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 53 deletions.
10 changes: 10 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Stone Changelog
===============

Here are the release notes for each version of Stone.

Version 0.0.1
-------------

* Generate HTML from Markdown
* jinja2 templating is processed in HTML files
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal=1
72 changes: 72 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Setup script for Stone
See:
https://github.com/NeuralSandwich/stone
"""

# To use a consistent encoding
# pylint: disable=redefined-builtin
from codecs import open
from os import path

# Apparently you should always prefer setuptools over distutils
from setuptools import setup, find_packages

# pylint: disable=invalid-name
here = path.abspath(path.dirname(__file__))

# Get the long description from the README file
with open(path.join(here, 'README'), encoding='utf-8') as f:
long_description = f.read()

setup(name='stone-site',

# Versions should comply with PEP440. For a discussion on single-sourcing
version='0.1a1.dev1',


description='Static site generator',
long_description=long_description,

# The project's main homepage
url='https://github.com/NeuralSandwich/stone',

# Author's details
author='Sean Jones',
author_email='sean@half.systems',

license='MIT',

# https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 3 - Alpha',

'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],

# What does this project relate to?
keywords='web html markdown static content',
packages=find_packages(exclude=['contrib', 'docs', 'tests']),

# List run-time dependencies here.
# https://packaging.python.org/en/latest/requirements.html
install_requires=['jinja2', 'Markdown'],
extras_require={
'dev': ['check-manifest'],
'test': ['coverage'],
},
entry_points={
'console_scripts': ['stone=stone.__main__:main']
}
)
Empty file added stone/__init__.py
Empty file.
50 changes: 50 additions & 0 deletions stone/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Entry point for Stone"""

from __future__ import print_function
import argparse
import os

from jinja2 import Environment, FileSystemLoader, select_autoescape
import markdown
from .stone import ConfigLoader, add_page


def main(args=None):
"""Entry point function for Stone"""
parser = argparse.ArgumentParser(description='Static website generator')
parser.add_argument("site_root", help='website root directory')

subparsers = parser.add_subparsers(help='sub-command help')
newpage = subparsers.add_parser(
'newpage', help=('add a new page to site.json and an emtpy file'))
newpage.add_argument(
"--page-type",
default="post",
type=str,
help='type of page to generate')

args = parser.parse_args()
sites = ConfigLoader().load(args.site_root)

if hasattr(args, 'page_type'):
return add_page(args, sites)
else:
if not os.path.isdir(args.site_root):
print("[ERROR] %s is not a directory" % args.site_root)
parser.print_help()
return 1

markdown_renderer = markdown.Markdown(
extensions=['markdown.extensions.meta'])
for site in sites:
env = Environment(
loader=FileSystemLoader(site.templates),
autoescape=select_autoescape(["html", "xml"]))

site.render(markdown_renderer, env)

return 0


if __name__ == '__main__':
main()
59 changes: 6 additions & 53 deletions stone/stone.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/usr/bin/env python3

import argparse
"""Stone library functions?"""
import collections
import errno
import json
import os
import sys

from jinja2 import Environment, FileSystemLoader, select_autoescape
from jinja2.exceptions import TemplateNotFound
import json
import markdown
from css_html_js_minify import css_minify, html_minify


class Page(collections.UserDict):
class Page(dict):
"""Representation of a Page"""
def __init__(self,
site_root,
source,
Expand Down Expand Up @@ -64,9 +58,8 @@ def render_html(self, environment):
try:
with open(self.data['target_path'], "w") as target_file:
target_file.write(
html_minify(
environment.get_template(self['template']).render(
self)))
self))
except TemplateNotFound as tnf:
print(tnf)
except KeyError as ke:
Expand All @@ -84,7 +77,7 @@ def render_html(self, environment):
raise


class Resource(collections.UserDict):
class Resource(dict):
def __init__(self, site_root, source, target, resource_type=None):
self.data = {
"resource_type": resource_type,
Expand Down Expand Up @@ -221,43 +214,3 @@ def add_page(args, sites):
if not int(choice) < len(sites):
print("[ERROR] %s is not a valid selection" % choice)
return 1


def main(parser, args):
sites = ConfigLoader().load(args.site_root)

if hasattr(args, 'page_type'):
return add_page(args, sites)
else:
if not os.path.isdir(args.site_root):
print("[ERROR] %s is not a directory" % args.site_root)
parser.print_help()
return 1

markdown_renderer = markdown.Markdown(
extensions=['markdown.extensions.meta'])
for site in sites:
env = Environment(
loader=FileSystemLoader(site.templates),
autoescape=select_autoescape(["html", "xml"]))

site.render(markdown_renderer, env)

return 0


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Static website generator')
parser.add_argument("site_root", help='website root directory')

subparsers = parser.add_subparsers(help='sub-command help')
newpage = subparsers.add_parser(
'newpage', help=('add a new page to site.json and an emtpy file'))
newpage.add_argument(
"--page-type",
default="post",
type=str,
help='type of page to generate')

args = parser.parse_args()
sys.exit(main(parser, args))

0 comments on commit ead9c11

Please sign in to comment.