From 6e7a19ce607d648733157f5e1595085ebb8f7a3d Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Fri, 5 Aug 2016 18:27:10 -0700 Subject: [PATCH] make into a proper distutils package, with wp2git as CLI entry point, and call it version 1.0 --- .gitignore | 2 ++ README.md | 51 +++++++++++++++++++---------------- setup.py | 41 ++++++++++++++++++++++++++++ version.py | 1 + wp2git/__init__.py | 0 wp2git/version.py | 3 +++ wp2git.py => wp2git/wp2git.py | 2 ++ 7 files changed, 77 insertions(+), 23 deletions(-) create mode 100755 setup.py create mode 120000 version.py create mode 100644 wp2git/__init__.py create mode 100644 wp2git/version.py rename wp2git.py => wp2git/wp2git.py (97%) diff --git a/.gitignore b/.gitignore index b883f1f..193b9cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.exe +*.py[co] +*~ diff --git a/README.md b/README.md index f2a66d0..b162750 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,28 @@ -wp2git -====== - -This program allows you to download and convert any Wikipedia article's history to a `git` repository, for easy browsing and blaming. - -### Usage - - $ wp2git.py [--bare] article_name - -`wp2git` will create a directory, in which a new `git` repository will be created. -The repository will contain a single file named `article_name.mw`, along with its entire edit history. - -Run `wp2git --help` for more options. - -### Requirements - -`git` should be accessible from `PATH`. - -The [`mwclient` package](http://github.com/mwclient/mwclient) must be installed (use `pip install mwclient`). - -### Entirely based on - -[CyberShadow's version](http://github.com/CyberShadow/wp2git) written in the D language. +wp2git +====== + +This program allows you to download and convert any Wikipedia article's history to a `git` repository, for easy browsing and blaming. + +### Quick installation + +``` +pip install https://github.com/dlenski/wp2git/archive/v1.0.zip +``` + +### Usage + + $ wp2git [--bare] article_name + +`wp2git` will create a directory, in which a new `git` repository will be created. +The repository will contain a single file named `article_name.mw`, along with its entire edit history. + +Run `wp2git --help` for more options. + +### Requirements + +`git` should be accessible from `PATH`. The [`mwclient` package](http://github.com/mwclient/mwclient) +is required. + +### Entirely based on + +[CyberShadow's version](http://github.com/CyberShadow/wp2git) written in the D language. diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..fa5a94d --- /dev/null +++ b/setup.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +from __future__ import print_function +import sys, os, re, subprocess as sp +from distutils.core import setup + +######################################## + +# Based on this recipe, adapted for Python 3, Git 2.8.x, and PEP-440 version identifiers +# http://blogs.nopcode.org/brainstorm/2013/05/20/pragmatic-python-versioning-via-setuptools-and-git-tags/ +# https://www.python.org/dev/peps/pep-0440/#version-scheme + +# Fetch version from git tags, and write to version.py. +# Also, when git is not available (PyPi package), use stored version.py. +version_py = os.path.join(os.path.dirname(__file__), 'version.py') + +try: + version_git = sp.check_output(["git", "describe", "--tags"]).strip().decode('ascii') + final, dev, blob = re.match(r'v?((?:\d+\.)*\d+)(?:-(\d+)-(g[a-z0-9]+))?', version_git).groups() + version_pep = final+('.dev%s+%s'%(dev,blob) if dev else '') +except (sp.CalledProcessError, OSError): + with open(version_py, 'r') as fh: + version_pep = open(version_py).read().strip().split('=')[-1][1:-1] +else: + with open(version_py, 'w') as fh: + print("# Do not edit this file, wp2git versioning is governed by git tags", file=fh) + print('__version__="%s"\n' % version_pep, file=fh) + +######################################## + +setup(name="wp2git", + version=version_pep, + description=("Downloads and imports Wikipedia page histories to a git repository"), + long_description=open('README.md').read(), + author=open('AUTHORS').read(), + author_email="dlenski@gmail.com", + install_requires=[ 'mwclient>=0.8' ], + license=open('LICENSE').read(), + url="https://github.com/dlenski/wp2git", + packages=["wp2git"], + entry_points={ 'console_scripts': [ 'wp2git=wp2git.wp2git:main' ] } + ) diff --git a/version.py b/version.py new file mode 120000 index 0000000..2e837a9 --- /dev/null +++ b/version.py @@ -0,0 +1 @@ +wp2git/version.py \ No newline at end of file diff --git a/wp2git/__init__.py b/wp2git/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wp2git/version.py b/wp2git/version.py new file mode 100644 index 0000000..9aca18b --- /dev/null +++ b/wp2git/version.py @@ -0,0 +1,3 @@ +# Do not edit this file, wp2git versioning is governed by git tags +__version__="1.0" + diff --git a/wp2git.py b/wp2git/wp2git.py similarity index 97% rename from wp2git.py rename to wp2git/wp2git.py index aba4332..5c19b2f 100755 --- a/wp2git.py +++ b/wp2git/wp2git.py @@ -7,6 +7,7 @@ import mwclient import subprocess as sp import urlparse import os, locale, time +from .version import __version__ lang = locale.getdefaultlocale()[0].split('_')[0] or '' @@ -18,6 +19,7 @@ def sanitize(s): def parse_args(): p = argparse.ArgumentParser(description='Create a git repository with the history of the specified Wikipedia article.') + p.add_argument('--version', action='version', version=__version__) p.add_argument('article_name') g2 = p.add_argument_group('Output options') g=g2.add_mutually_exclusive_group()