/usr/lib/python2.7/dist-packages/invocations/packaging.py is in python-invocations 0.6.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | from glob import glob
import os
from shutil import rmtree, copy, copytree
from tempfile import mkdtemp
from invoke import ctask as task, Collection
def unpack(ctx, tmp, package, version, git_url=None):
"""
Download + unpack given package into temp dir ``tmp``.
Return ``(real_version, source)`` where ``real_version`` is the "actual"
version downloaded (e.g. if a Git master was indicated, it will be the SHA
of master HEAD) and ``source`` is the source directory (relative to
unpacked source) to import into ``<project>/vendor``.
"""
real_version = version[:]
source = None
if git_url:
pass
# git clone into tempdir
# git checkout <version>
# set target to checkout
# if version does not look SHA-ish:
# in the checkout, obtain SHA from that branch
# set real_version to that value
else:
cwd = os.getcwd()
print("Moving into temp dir %s" % tmp)
os.chdir(tmp)
try:
# Nab from index
flags = "--download-cache= --download=. --build=build"
cmd = "pip install %s %s==%s" % (flags, package, version)
ctx.run(cmd)
# Identify basename
# TODO: glob is bad here because pip install --download gets all
# dependencies too! ugh.
zipfile = os.path.basename(glob("*.zip")[0])
source = os.path.splitext(zipfile)[0]
# Unzip
ctx.run("unzip *.zip")
finally:
os.chdir(cwd)
return real_version, source
@task
def vendorize(ctx, distribution, version, vendor_dir, package=None,
git_url=None, license=None):
"""
Vendorize Python package ``distribution`` at version/SHA ``version``.
Specify the vendor folder (e.g. ``<mypackage>/vendor``) as ``vendor_dir``.
For Crate/PyPI releases, ``package`` should be the name of the software
entry on those sites, and ``version`` should be a specific version number.
E.g. ``vendorize('lexicon', '0.1.2')``.
For Git releases, ``package`` should be the name of the package folder
within the checkout that needs to be vendorized and ``version`` should be a
Git identifier (branch, tag, SHA etc.) ``git_url`` must also be given,
something suitable for ``git clone <git_url>``.
For SVN releases: xxx.
For packages where the distribution name is not the same as the package
directory name, give ``package='name'``.
By default, no explicit license seeking is done -- we assume the license
info is in file headers or otherwise within the Python package vendorized.
This is not always true; specify ``license=/path/to/license/file`` to
trigger copying of a license into the vendored folder from the
checkout/download (relative to its root.)
"""
tmp = mkdtemp()
package = package or distribution
target = os.path.join(vendor_dir, package)
try:
# Unpack source
real_version, source = unpack(ctx, tmp, distribution, version, git_url)
abs_source = os.path.join(tmp, source)
source_package = os.path.join(abs_source, package)
# Ensure source package exists
if not os.path.exists(source_package):
rel_package = os.path.join(source, package)
raise ValueError("Source package %s doesn't exist!" % rel_package)
# Nuke target if exists
if os.path.exists(target):
print("Removing pre-existing vendorized folder %s" % target)
rmtree(target)
# Perform the copy
print("Copying %s => %s" % (source_package, target))
copytree(source_package, target)
# Explicit license if needed
if license:
copy(os.path.join(abs_source, license), target)
# git commit -a -m "Update $package to $version ($real_version if different)"
finally:
rmtree(tmp)
@task(name='all')
def all_(ctx):
"""
Catchall version-bump/tag/changelog/PyPI upload task.
"""
@task
def changelog(ctx, target='docs/changelog.rst'):
"""
Update changelog with new release entry.
"""
pass
@task
def version(ctx):
"""
Update stored project version (e.g. a ``_version.py``.)
Requires configuration to be effective (since version file is usually kept
within a project-named directory.
"""
pass
@task
def tag(ctx):
"""
Create a release tag.
May set a config option for a prefix, e.g. 'v1.0.0' vs just '1.0.0'. This
is unset/blank by default.
"""
pass
@task
def push(ctx):
"""
Push tag/changelog/version changes to Git origin.
"""
# TODO: or should this be distributed amongst the appropriate tasks?
pass
@task
def publish(ctx, wheel=False):
"""
Publish code to PyPI.
"""
# TODO: Use twine.
parts = ["python", "setup.py", "sdist"]
if wheel:
parts.append("bdist_wheel")
parts.append("register")
parts.append("upload")
ctx.run(" ".join(parts))
release = Collection('release', changelog, version, tag, push)
release.add_task(all_, default=True)
|