diff --git a/doc/index.rst b/doc/index.rst index bfbf2c9..bd0df15 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -82,5 +82,5 @@ module: pypi .. automodule:: doitpy.pypi .. autoclass:: doitpy.pypi.PyPi - :members: __init__, git_manifest, sdist_upload + :members: __init__, revision_git, manifest_git, sdist, sdist_upload :member-order: bysource diff --git a/dodo.py b/dodo.py index 3075b36..25e7459 100644 --- a/dodo.py +++ b/dodo.py @@ -31,7 +31,7 @@ def task_coverage(): def task_pypi(): """upload package to pypi""" pkg = PyPi() - yield pkg.git_manifest() + yield pkg.manifest_git() yield pkg.sdist_upload() diff --git a/doitpy/docs.py b/doitpy/docs.py index bcc2f93..a977e1b 100644 --- a/doitpy/docs.py +++ b/doitpy/docs.py @@ -54,15 +54,16 @@ def spell(files, dictionary): # task creator -def sphinx(root_path, build_path, task_dep=None): +def sphinx(root_path, build_path, sphinx_opts='', task_dep=None): """build sphinx docs :param str root_path: root path of sphinx docs :param str build_path: path generated sphinx docs will be saved in + :param str sphinx_opts: `sphinx-build` command line options :param list-str task_dep: list of tasks this task will depend on """ - cmd = "sphinx-build -b html -d %s_build/doctrees %s %s" - action = cmd % (root_path, root_path, build_path) + cmd = "sphinx-build -b html {opts} -d {root}_build/doctrees {root} {build}" + action = cmd.format(root=root_path, build=build_path, opts=sphinx_opts) # sphinx has its own check it up-to-date so we dont care # about always re-executing the task. task = { diff --git a/doitpy/pypi.py b/doitpy/pypi.py index da100df..bbc84ec 100644 --- a/doitpy/pypi.py +++ b/doitpy/pypi.py @@ -8,7 +8,7 @@ def task_pypi(): pkg = PyPi() - yield pkg.git_manifest() + yield pkg.manifest_git() yield pkg.sdist_upload() """ @@ -16,29 +16,57 @@ def task_pypi(): class PyPi(object): """helper to create tasks to upload a python package to PyPi""" - def __init__(self, name=None): - self.name = name + '-' if name else '' + def __init__(self): + self.revision_file = None - def git_manifest(self): + + def revision_git(self, file_name='revision.txt'): + """create file with repo rev number""" + cmd = "git rev-list --branches=master --max-count=1 HEAD > {}" + self.revision_file = file_name + return { + 'basename': 'pypi', + 'name': 'revision', + 'actions': [cmd.format(file_name)], + 'targets': [file_name], + } + + + def manifest_git(self): """create manifest file for distutils Put all files being tracked by git into the manifest """ - cmd = "git ls-tree --name-only -r HEAD > MANIFEST" + cmds = ["git ls-tree --name-only -r HEAD > MANIFEST"] + file_dep = [] + if self.revision_file: + file_dep.append(self.revision_file) + cmds.append("echo '{}' >> MANIFEST".format(self.revision_file)) return { 'basename': 'pypi', - 'name': self.name + 'manifest', - 'actions': [cmd], + 'name': 'manifest', + 'actions': cmds, + 'file_dep': file_dep, + 'targets': ['MANIFEST'], } + def sdist(self): + """create sdist package""" + return { + 'basename': 'pypi', + 'name': 'sdist', + 'actions': ["python setup.py sdist"], + 'file_dep': ['MANIFEST'], + 'verbosity': 2, + } def sdist_upload(self): """upload sdist package to pypi""" return { 'basename': 'pypi', - 'name': self.name + 'sdist_upload', + 'name': 'sdist_upload', 'actions': ["python setup.py sdist upload"], - 'task_dep': [ 'pypi:' + self.name + 'manifest'], + 'file_dep': ['MANIFEST'], 'verbosity': 2, } diff --git a/tests/test_pypi.py b/tests/test_pypi.py index afc47d2..d1a7339 100644 --- a/tests/test_pypi.py +++ b/tests/test_pypi.py @@ -2,16 +2,47 @@ class TestPyPi(object): - def test_git_manifest(self): - task = pypi.PyPi('abc').git_manifest() + def test_revision_git(self): + pkg = pypi.PyPi() + task = pkg.revision_git() assert task['basename'] == 'pypi' - assert task['name'] == 'abc-manifest' - assert 'git' in task['actions'][0] + assert task['name'] == 'revision' + assert 'git rev-list' in task['actions'][0] + assert pkg.revision_file == 'revision.txt' + assert pkg.revision_file in task['actions'][0] + assert task['targets'] == [pkg.revision_file] + + def test_manifest_git(self): + task = pypi.PyPi().manifest_git() + assert task['basename'] == 'pypi' + assert task['name'] == 'manifest' + assert len(task['actions']) == 1 + assert task['file_dep'] == [] + assert 'git ls-tree' in task['actions'][0] assert 'MANIFEST' in task['actions'][0] + def test_manifest_with_revision(self): + pkg = pypi.PyPi() + pkg.revision_git() + task = pkg.manifest_git() + assert task['basename'] == 'pypi' + assert task['name'] == 'manifest' + assert len(task['actions']) == 2 + assert task['file_dep'] == [pkg.revision_file] + assert 'git ls-tree' in task['actions'][0] + assert 'MANIFEST' in task['actions'][0] + assert pkg.revision_file in task['actions'][1] + + def test_sdist(self): + task = pypi.PyPi().sdist() + assert task['basename'] == 'pypi' + assert task['name'] == 'sdist' + assert task['actions'][0].endswith('sdist') + assert task['file_dep'][0] == 'MANIFEST' + def test_sdist_upload(self): - task = pypi.PyPi('abc').sdist_upload() + task = pypi.PyPi().sdist_upload() assert task['basename'] == 'pypi' - assert task['name'] == 'abc-sdist_upload' + assert task['name'] == 'sdist_upload' assert 'sdist upload' in task['actions'][0] - assert task['task_dep'][0] == 'pypi:abc-manifest' + assert task['file_dep'][0] == 'MANIFEST'