Skip to content

Instantly share code, notes, and snippets.

@logc
Last active March 8, 2017 09:48

Revisions

  1. logc revised this gist Mar 7, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions pypkg.sh
    Original file line number Diff line number Diff line change
    @@ -138,5 +138,6 @@ sed -i -e '12 a\
    cd docs/
    make html
    cd ${doc_root}
    touch .nojekyll
    git add --all .
    git commit --quiet -m "Start HTML documentation"
  2. logc revised this gist Mar 7, 2017. No changes.
  3. logc revised this gist Mar 7, 2017. 1 changed file with 18 additions and 12 deletions.
    30 changes: 18 additions & 12 deletions pypkg.sh
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@

    pkg_name=$1
    pkg_root=$PWD/${pkg_name}
    doc_root=${pkg_root}/docs/_build/html

    hostname=`hostname`
    year=`date '+%Y'`
    version='0.1.0'
    @@ -119,18 +121,22 @@ cd ${pkg_root}
    git commit --quiet -m "Initial commit"
    git checkout --orphan gh-pages
    git checkout master
    mkdir -p docs/build/_html
    git worktree add -b gh-pages docs/_build/html/
    cd docs/build/_html
    mkdir -p ${doc_root}
    git worktree add -b gh-pages ${doc_root}
    cd ${doc_root}
    git rm -rf .
    git commit --quiet -m "Start documentation"
    cd -
    sed -i -e "s/# import os/import os/" docs/conf.py
    sed -i -e "s/# import sys/import sys/" docs/conf.py
    # Notice we insert the **parent directory**
    sed -i -e "s/# sys.path.insert(0, os.path.abspath('.'))/sys.path.insert(0, os.path.abspath('..'))/" docs/conf.py
    sphinx-apidoc -o docs/ ${pkg_name}
    sed -i -e '12 a\
    \ \ \ modules' docs/index.rst
    git commit --quiet -m "Remove sources from documentation root"

    cd ${pkg_root}
    sed -i -e "s/# import os/import os/" docs/conf.py
    sed -i -e "s/# import sys/import sys/" docs/conf.py
    # Notice we insert the **parent directory**
    sed -i -e "s/# sys.path.insert(0, os.path.abspath('.'))/sys.path.insert(0, os.path.abspath('..'))/" docs/conf.py
    sphinx-apidoc -o docs/ ${pkg_name}
    sed -i -e '12 a\
    \ \ \ modules' docs/index.rst
    cd docs/
    make html
    cd ${doc_root}
    git add --all .
    git commit --quiet -m "Start HTML documentation"
  4. logc created this gist Mar 7, 2017.
    136 changes: 136 additions & 0 deletions pypkg.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,136 @@
    #!/usr/bin/env bash

    pkg_name=$1
    pkg_root=$PWD/${pkg_name}
    hostname=`hostname`
    year=`date '+%Y'`
    version='0.1.0'

    mkdir -p ${pkg_root}/${pkg_name}
    mkdir -p ${pkg_root}/test

    cat << EOF > ${pkg_root}/setup.py
    from setuptools import setup
    setup(name='$pkg_name',
    version='$version',
    author='$USER',
    author_email='$USER@$hostname',
    entry_points={
    'console_scripts': [
    '${pkg_name} = ${pkg_name}.main:run'
    ]
    },
    test_suite='nose.collector'
    )
    EOF

    touch ${pkg_root}/${pkg_name}/__init__.py
    cat <<EOF > ${pkg_root}/${pkg_name}/main.py
    """
    This module holds entry points of the ${pkg_name} package
    """
    def run():
    """Main console entry point"""
    print "Hello, ${pkg_name}"
    if __name__ == '__main__':
    main()
    EOF

    cat <<EOF > ${pkg_root}/test/test_main.py
    def test_main():
    assert 1 == 2, "Fix this test"
    EOF

    cat << EOF > ${pkg_root}/README.md
    $pkg_name
    =========
    # Installation
    This is a Python setuptools package. Use this command:
    $ python setup.py install
    # Usage
    Please refer to the documentation
    # License
    See LICENSE.txt
    EOF

    cat << EOF > ${pkg_root}/LICENSE.txt
    MIT License
    Copyright (c) $year $USER
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
    EOF

    cat << EOF > ${pkg_root}/requirements.txt
    nose
    sphinx
    EOF

    cat << EOF > ${pkg_root}/.gitignore
    .Python
    /bin/
    /include/
    /lib/
    pip-selfcheck.json
    EOF

    pip --quiet install virtualenv
    virtualenv --quiet ${pkg_root}
    source ${pkg_root}/bin/activate
    pip --quiet install -r ${pkg_root}/requirements.txt
    git init --quiet ${pkg_root}
    sphinx-quickstart --quiet \
    --project=${pkg_name} \
    --author=$USER \
    -v $version \
    --ext-autodoc \
    --no-batchfile \
    ${pkg_root}/docs

    cd ${pkg_root}
    git add --all .
    git commit --quiet -m "Initial commit"
    git checkout --orphan gh-pages
    git checkout master
    mkdir -p docs/build/_html
    git worktree add -b gh-pages docs/_build/html/
    cd docs/build/_html
    git rm -rf .
    git commit --quiet -m "Start documentation"
    cd -
    sed -i -e "s/# import os/import os/" docs/conf.py
    sed -i -e "s/# import sys/import sys/" docs/conf.py
    # Notice we insert the **parent directory**
    sed -i -e "s/# sys.path.insert(0, os.path.abspath('.'))/sys.path.insert(0, os.path.abspath('..'))/" docs/conf.py
    sphinx-apidoc -o docs/ ${pkg_name}
    sed -i -e '12 a\
    \ \ \ modules' docs/index.rst
    cd docs/
    make html