Skip to content

Commit

Permalink
pypi. added tasks revision and sdist
Browse files Browse the repository at this point in the history
  • Loading branch information
schettino72 committed Aug 31, 2014
1 parent fc9691d commit 2eed0f7
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 21 deletions.
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
7 changes: 4 additions & 3 deletions doitpy/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
46 changes: 37 additions & 9 deletions doitpy/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,65 @@
def task_pypi():
pkg = PyPi()
yield pkg.git_manifest()
yield pkg.manifest_git()
yield pkg.sdist_upload()
"""

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,
}
45 changes: 38 additions & 7 deletions tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 2eed0f7

Please sign in to comment.