Skip to content

Commit

Permalink
Added a skeleton python file
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Wilhelm authored and Florian Wilhelm committed Jan 2, 2015
1 parent a5fe370 commit 4b4f2b8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version 2.0, 2015-??-??
- Removed .pre from version string (newer PEP 440)
- FIX: Sphinx now works if package name does not equal project name
- Allow namespace packages with --with-namespace
- Added a skeleton.py as a console_script template

Version 1.4, 2014-12-16
=======================
Expand Down
4 changes: 3 additions & 1 deletion pyscaffold/data/setup_cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ classifiers = ${classifiers}

[console_scripts]
# Add here console scripts like:
# hello_world = ${package}.module:function
# script = ${package}.module:function
# for example:
# hello_world = ${package}.skeleton:run
${console_scripts}
[test]
# html, xml or annotate
Expand Down
40 changes: 40 additions & 0 deletions pyscaffold/data/skeleton.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is a skeleton file that can serve as a starting point for a Python
console script. To run this script uncomment the following line in the
console_scripts section in setup.cfg:
hello_world = ${package}.skeleton:run
Then run `python setup.py install` which will install the command `hello_world`
inside your current environment.
Besides console scripts, the header (i.e. until _logger...) of this file can
also be used as template for Python modules.
Note: This skeleton file can be safely removed if not needed!
"""
from __future__ import division, print_function, absolute_import

import sys
import logging

__author__ = "${author}"
__copyright__ = "${author}"
__license__ = "${license}"

_logger = logging.getLogger(__name__)


def main(args):
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
print("Hello World!")
_logger.info("Script ends here")


def run():
main(sys.argv[1:])


if __name__ == "__main__":
run()
1 change: 1 addition & 0 deletions pyscaffold/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def make_structure(args):
struct = {args.project: {
".gitignore": templates.gitignore(args),
args.package: {"__init__.py": templates.init(args),
"skeleton.py": templates.skeleton(args),
"_version.py": templates.version(args)},
"tests": {"__init__.py": ""},
"docs": {"conf.py": templates.sphinx_conf(args),
Expand Down
11 changes: 11 additions & 0 deletions pyscaffold/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,14 @@ def namespace(args):
"""
template = get_template("namespace")
return template.substitute(vars(args))


def skeleton(args):
"""
Template of skeleton.py defining a basic console script
:param args: command line parameters as :obj:`argparse.Namespace`
:return: file content as string
"""
template = get_template("skeleton")
return template.substitute(vars(args))

0 comments on commit 4b4f2b8

Please sign in to comment.