Skip to content

Commit

Permalink
Merge pull request #8 from jacebrowning/feature/embed-version
Browse files Browse the repository at this point in the history
Embed version and copywrite
  • Loading branch information
jacebrowning committed Oct 17, 2016
2 parents 27219ef + 983d67f commit 2e9d61b
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision History

## 0.2 (unreleased)

- Added `--version` command.

## 0.1 (2016/10/17)

- Initial release.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ $(DIST_FILES): $(MODULES) README.rst CHANGELOG.rst
$(PYTHON) setup.py check --restructuredtext --strict --metadata
$(PYTHON) setup.py sdist
$(PYTHON) setup.py bdist_wheel
cp $(PACKAGE)/script.py dist/$(PROJECT) && chmod a+x dist/$(PROJECT)

%.rst: %.md
pandoc -f markdown_github -t rst -o $@ $<
Expand Down
8 changes: 8 additions & 0 deletions docs/cli/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Configuration Filenames

Any of the following can be used as the `verchew` configuration filename:

* `.verchew`
* `.verchewrc`
* `verchew.ini`
* `.verchew.ini`
25 changes: 25 additions & 0 deletions docs/cli/embedding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Standalone Script

Normally, `verchew` is installed using `pip`, but given the variety of environments in which this program is run, you might be in a situation where `pip`:

* is not installed
* does not have the correct permissions to install `verchew`
* does not have network access to PyPI

For this reason, `verchew` can also be embedded into your project as a standalone Python script.

## Building

After cloning this repository, build the script for distribution:

```
$ make dist
```

## Copying

In your project:

1. Create a `bin/` directory: `$ mkdir -p bin`
2. Copy the script: `$ cp ../verchew/dist/verchew bin/verchew`
3. Ensure the script is executable: `$ chmod a+x bin/verchew`
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ theme: readthedocs

pages:
- Home: index.md
- CLI:
- Configuration: cli/config.md
- Embedded Script: cli/embedding.md
- About:
- Release Notes: about/changelog.md
- Contributing: about/contributing.md
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def check_python_version():
sys.exit("Python {}.{}+ is required.".format(*MINIMUM_PYTHON_VERSION))


def read_package_variable(key):
def read_package_variable(key, filename='__init__.py'):
"""Read the value of a variable from the package without importing."""
module_path = os.path.join(PACKAGE_NAME, '__init__.py')
module_path = os.path.join(PACKAGE_NAME, filename)
with open(module_path) as module:
for line in module:
parts = line.strip().split(' ')
Expand All @@ -43,8 +43,8 @@ def read_descriptions():
check_python_version()

setuptools.setup(
name=read_package_variable('__project__'),
version=read_package_variable('__version__'),
name=PACKAGE_NAME,
version=read_package_variable(filename='script.py', key='__version__'),

description="System dependency version checker.",
url='https://github.com/jacebrowning/verchew',
Expand Down
14 changes: 9 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ def cli(env, *args):

def describe_cli():

def describe_help():
def it_displays_help_information(env):
cmd = cli(env, '--help')

def it_returns_information(env):
cmd = cli(env, '--help')
expect(cmd.returncode) == 0
expect(cmd.stdout).contains("usage: verchew")

expect(cmd.returncode) == 0
expect(cmd.stdout).contains("usage: verchew")
def it_displays_version_information(env):
cmd = cli(env, '--version')

expect(cmd.returncode) == 0
expect(cmd.stdout or cmd.stderr).contains("verchew v0.")
5 changes: 1 addition & 4 deletions verchew/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
"""Package for verchew."""

__project__ = 'verchew'
__version__ = '0.1'

VERSION = "{0} v{1}".format(__project__, __version__)
from .script import __version__
27 changes: 25 additions & 2 deletions verchew/script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# The MIT License (MIT)
# Copyright © 2016, Jace Browning
#
# 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 wcopies 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.


from __future__ import unicode_literals

import os
Expand All @@ -13,6 +35,7 @@
import subprocess
import logging

__version__ = '0.1'

CONFIG_FILENAMES = ['.verchew', '.verchewrc', 'verchew.ini', '.verchew.ini']

Expand All @@ -30,8 +53,8 @@ def main():

def parse_args():
parser = argparse.ArgumentParser()
# TODO: add '--version' option
# parser.add_argument('--version', action='version', version=VERSION)
version = "%(prog)s v" + __version__
parser.add_argument('--version', action='version', version=version)
parser.add_argument('-v', '--verbose', action='count', default=0,
help="enable verbose logging")

Expand Down

0 comments on commit 2e9d61b

Please sign in to comment.