Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Updating helper files. Moving docs to GHPages.
Browse files Browse the repository at this point in the history
Switching from Read The Docs hosting to SCVersioning on GitHub Pages.

Updating linters and fixing lints with getattr().
  • Loading branch information
Robpol86 committed Aug 23, 2016
1 parent 786ddc1 commit 3746dc2
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 51 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ after_success:
- appveyor-artifacts -mi download
- coverage combine
- coveralls
- eval "$(ssh-agent -s)"; touch docs/key; chmod 0600 docs/key
- openssl aes-256-cbc -d -K "$encrypted_039f315d67f4_key" -iv "$encrypted_039f315d67f4_iv" < docs/key.enc > docs/key
&& ssh-add docs/key
- git config --global user.email "builds@travis-ci.com"
- git config --global user.name "Travis CI"
- git remote set-url origin "git@github.com:$TRAVIS_REPO_SLUG"
- export ${!TRAVIS*}
- tox -e docsV

# Deploy.
deploy:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pip install tox # Install tox, which runs linting and tests.
tox # This runs all tests on your local machine. Make sure they pass.
```

If you don't have Python 2.6, 2.7, and 3.4 installed, you can manually run tests on one specific version by running
`tox -e lint,py27` (for Python 2.7) instead.
If you don't have Python 2.7 or 3.4 installed you can manually run tests on one specific version by running
`tox -e lint,py35` (for Python 3.5) instead.

## Updating Docs

Expand Down
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use both at the same time:
2. ``args = docoptcfg(__doc__, config_option='--config')``
3. ``args = docoptcfg(__doc__, config_option='--config', env_prefix='MYAPP_')``

📖 Full documentation: https://docoptcfg.readthedocs.org

* Python 2.6, 2.7, PyPy, PyPy3, 3.3, 3.4, and 3.5 supported on Linux and OS X.
* Python 2.7, 3.3, 3.4, and 3.5 supported on Windows (both 32 and 64 bit versions of Python).

📖 Full documentation: https://robpol86.github.io/docoptcfg

.. image:: https://img.shields.io/appveyor/ci/Robpol86/docoptcfg/master.svg?style=flat-square&label=AppVeyor%20CI
:target: https://ci.appveyor.com/project/Robpol86/docoptcfg
:alt: Build Status Windows
Expand All @@ -43,6 +43,8 @@ Install:
pip install docoptcfg
.. changelog-section-start
Changelog
=========

Expand All @@ -64,3 +66,5 @@ Fixed
------------------

* Initial release.

.. changelog-section-end
10 changes: 5 additions & 5 deletions docoptcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def settable_options(doc, argv, ignore, options_first):
for option in pattern.fix().flat():
if not hasattr(option, 'long'):
continue # Positional argument or sub-command.
if option.long not in settable:
if getattr(option, 'long') not in settable:
continue # Don't care about this if we can't set it.
if option.long in booleans and option.value == 0:
repeatable.add(option.long)
elif hasattr(option.value, '__iter__'):
repeatable.add(option.long)
if getattr(option, 'long') in booleans and getattr(option, 'value') == 0:
repeatable.add(getattr(option, 'long'))
elif hasattr(getattr(option, 'value'), '__iter__'):
repeatable.add(getattr(option, 'long'))

return settable, booleans, repeatable, short_map

Expand Down
6 changes: 6 additions & 0 deletions docs/_templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{# From https://github.com/snide/sphinx_rtd_theme/issues/166 #}

{# Import the theme's layout. #}
{% extends "!layout.html" %}

{% set css_files = css_files + ['_static/pygments.css'] %}
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. _changelog:

.. include:: ../README.rst
:start-after: changelog-section-start
:end-before: changelog-section-end
26 changes: 22 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,40 @@
import time
from subprocess import check_output

import sphinx_rtd_theme

SETUP = os.path.join(os.path.dirname(__file__), '..', 'setup.py')


# General configuration.
author = check_output([SETUP, '--author']).strip().decode('ascii')
copyright = '{}, {}'.format(time.strftime('%Y'), author)
master_doc = 'index'
nitpicky = True
project = check_output([SETUP, '--name']).strip().decode('ascii')
pygments_style = 'friendly'
release = version = check_output([SETUP, '--version']).strip().decode('ascii')
templates_path = ['_templates']
extensions = list()


# Options for HTML output.
html_context = dict(
conf_py_path='/docs/',
display_github=True,
github_repo=os.environ.get('TRAVIS_REPO_SLUG', '/' + project).split('/', 1)[1],
github_user=os.environ.get('TRAVIS_REPO_SLUG', 'robpol86/').split('/', 1)[0],
github_version=os.environ.get('TRAVIS_BRANCH', 'master'),
source_suffix='.rst',
)
html_copy_source = False
html_favicon = 'favicon.ico'
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
html_title = project

# google analytics
extensions.append('sphinxcontrib.googleanalytics')
googleanalytics_id = 'UA-82627369-1'

# SCVersioning.
scv_banner_greatest_tag = True
scv_grm_exclude = ('.gitignore', '.nojekyll', 'README.rst')
scv_show_banner = True
scv_sort = ('semver', 'time')
Binary file added docs/favicon.ico
Binary file not shown.
19 changes: 12 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=========
docoptcfg
=========
===================
docoptcfg |version|
===================

Love using `docopt <http://docopt.org/>`_ over argparse or `Click <http://click.pocoo.org/>`_? Wish it took care of
environment variables and/or config files?
Expand Down Expand Up @@ -78,16 +78,21 @@ Our result is:
Project Links
=============

* Documentation: https://docoptcfg.readthedocs.org
* Documentation: https://robpol86.github.io/docoptcfg
* Source code: https://github.com/Robpol86/docoptcfg
* PyPI homepage: https://pypi.python.org/pypi/docoptcfg

Contents
========

.. toctree::
:maxdepth: 3
:caption: General

install
usage
env_vars
config_files

.. toctree::
:maxdepth: 1
:caption: Appendix

changelog
38 changes: 38 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. _install:

============
Installation
============

Getting started is pretty simple. The first step is to install the library.

Pip Install
===========

The easiest way to get docoptcfg is to use `pip <https://pip.pypa.io>`_. Simply run this command.

.. code-block:: bash
pip install docoptcfg
Latest from GitHub
==================

You can also elect to install the latest bleeding-edge version by using pip to install directly from the GitHub
repository.

.. code-block:: bash
pip install git+https://github.com/Robpol86/docoptcfg.git
Clone and Install
=================

Lastly you can also just clone the repo and install from it. Usually you only need to do this if you plan on
`contributing <https://github.com/Robpol86/docoptcfg/blob/master/CONTRIBUTING.md>`_ to the project.

.. code-block:: bash
git clone https://github.com/Robpol86/docoptcfg.git
cd docoptcfg
python setup.py install
Binary file added docs/key.enc
Binary file not shown.
54 changes: 48 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@

import codecs
import os
import re

from setuptools import setup
from setuptools import Command, setup

NAME = 'docoptcfg'
INSTALL_REQUIRES = ['docopt']
LICENSE = 'MIT'
NAME = IMPORT = 'docoptcfg'
VERSION = '1.0.2'


def readme():
def readme(path='README.rst'):
"""Try to read README.rst or return empty string if failed.
:param str path: Path to README file.
:return: File contents.
:rtype: str
"""
path = os.path.realpath(os.path.join(os.path.dirname(__file__), 'README.rst'))
path = os.path.realpath(os.path.join(os.path.dirname(__file__), path))
handle = None
url_prefix = 'https://raw.githubusercontent.com/Robpol86/{name}/v{version}/'.format(name=NAME, version=VERSION)
try:
Expand All @@ -30,6 +35,42 @@ def readme():
getattr(handle, 'close', lambda: None)()


class CheckVersion(Command):
"""Make sure version strings and other metadata match here, in module/package, tox, and other places."""

description = 'verify consistent version/etc strings in project'
user_options = []

@classmethod
def initialize_options(cls):
"""Required by distutils."""
pass

@classmethod
def finalize_options(cls):
"""Required by distutils."""
pass

@classmethod
def run(cls):
"""Check variables."""
project = __import__(IMPORT, fromlist=[''])
for expected, var in [('@Robpol86', '__author__'), (LICENSE, '__license__'), (VERSION, '__version__')]:
if getattr(project, var) != expected:
raise SystemExit('Mismatch: {0}'.format(var))
# Check changelog.
if not re.compile(r'^%s - \d{4}-\d{2}-\d{2}$' % VERSION, re.MULTILINE).search(readme()):
raise SystemExit('Version not found in readme/changelog file.')
# Check tox.
if INSTALL_REQUIRES:
section = re.compile(r'\ninstall_requires =\n(.+?)\n\w', re.DOTALL).findall(readme('tox.ini'))
if not section:
raise SystemExit('Missing install_requires section in tox.ini.')
in_tox = re.findall(r' ([^=]+)==[\w\d.-]+', section[0])
if INSTALL_REQUIRES != in_tox:
raise SystemExit('Missing/unordered pinned dependencies in tox.ini.')


setup(
author='@Robpol86',
author_email='robpol86@gmail.com',
Expand All @@ -56,10 +97,11 @@ def readme():
'Topic :: Software Development :: Libraries',
'Topic :: Terminals',
],
cmdclass=dict(check_version=CheckVersion),
description='docopt wrapper adding config file and environment variable support.',
install_requires=['docopt'],
install_requires=INSTALL_REQUIRES,
keywords='docopt config configuration environment',
license='MIT',
license=LICENSE,
long_description=readme(),
name=NAME,
py_modules=[NAME],
Expand Down
56 changes: 31 additions & 25 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[general]
author = @Robpol86
license = MIT
install_requires =
docopt==0.6.2
name = docoptcfg
version = 1.0.2

[tox]
envlist = lint,py{34,27,26}
Expand All @@ -12,7 +11,8 @@ commands =
py.test --cov-append --cov-report term-missing --cov-report xml --cov {[general]name} --cov-config tox.ini \
{posargs:tests}
deps =
pytest-cov==2.2.1
{[general]install_requires}
pytest-cov==2.3.1
usedevelop = True

[testenv:py35x64]
Expand All @@ -36,42 +36,48 @@ commands =
python setup.py check --strict
python setup.py check --strict -m
python setup.py check --strict -s
python setup.py check_version
flake8 --application-import-names={[general]name},tests
pylint --rcfile=tox.ini setup.py {[general]name}
python -c "assert '{[general]author}' == __import__('{[general]name}').__author__"
python -c "assert '{[general]license}' == __import__('{[general]name}').__license__"
python -c "assert '{[general]version}' == __import__('{[general]name}').__version__"
python -c "assert 'author=\'{[general]author}\'' in open('setup.py').read(102400)"
python -c "assert 'license=\'{[general]license}\'' in open('setup.py').read(102400)"
python -c "assert 'VERSION = \'{[general]version}\'' in open('setup.py').read(102400)"
python -c "assert '\n{[general]version} - ' in open('README.rst').read(102400)"
deps =
coverage==4.0.3
flake8==2.5.4
flake8-import-order==0.5
flake8-pep257==1.0.5
pep8-naming==0.3.3
pylint==1.5.4
{[general]install_requires}
coverage==4.2
flake8-docstrings==1.0.2
flake8-import-order==0.9.1
flake8==3.0.3
pep8-naming==0.4.1
pylint==1.6.4

[testenv:docs]
changedir = {toxinidir}/docs
commands =
sphinx-build -a -E -W . _build/html
sphinx-build -a -E . _build/html
deps =
Sphinx==1.4.2
sphinx-rtd-theme==0.1.9
{[general]install_requires}
sphinx==1.4.5
sphinx-rtd-theme==0.1.10a0
sphinxcontrib-googleanalytics==0.1

[testenv:docsV]
commands =
sphinx-versioning push docs gh-pages .
deps =
{[testenv:docs]deps}
sphinxcontrib-versioning==2.1.0
passenv =
HOME
HOSTNAME
SSH_AUTH_SOCK
TRAVIS*
USER

[flake8]
exclude = .tox/*,build/*,docs/*,env/*,get-pip.py
ignore = D203
import-order-style = google
import-order-style = smarkets
max-line-length = 120
statistics = True

[pylint]
disable =
import-error,
no-member,
ignore = .tox/*,build/*,docs/*,env/*,get-pip.py
max-line-length = 120
reports = no
Expand Down

0 comments on commit 3746dc2

Please sign in to comment.