| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
""" |
| 18 |
Build Tasks |
| 19 |
~~~~~~~~~~~ |
| 20 |
|
| 21 |
""" |
| 22 |
|
| 23 |
import os as _os |
| 24 |
|
| 25 |
try: |
| 26 |
import build as _build |
| 27 |
except ImportError: |
| 28 |
_build = None |
| 29 |
|
| 30 |
import invoke as _invoke |
| 31 |
|
| 32 |
from .._inv import tasks as _tasks |
| 33 |
from . import _pkg_dir |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
NAMESPACE = "build" |
| 38 |
|
| 39 |
|
| 40 |
@_invoke.task(default=True) |
| 41 |
def source(ctx): |
| 42 |
"""Build source package""" |
| 43 |
if source.avoid_rerun: |
| 44 |
return |
| 45 |
|
| 46 |
if _tasks.exists("doc.doc"): |
| 47 |
_tasks.execute(ctx, "doc.doc") |
| 48 |
|
| 49 |
with ctx.shell.root_dir(): |
| 50 |
if not _os.path.isdir("setups"): |
| 51 |
_build_sdist(ctx) |
| 52 |
source.avoid_rerun = True |
| 53 |
return |
| 54 |
|
| 55 |
_source_multi(ctx) |
| 56 |
source.avoid_rerun = True |
| 57 |
|
| 58 |
|
| 59 |
source.avoid_rerun = False |
| 60 |
|
| 61 |
|
| 62 |
def _source_multi(ctx): |
| 63 |
"""Build multiple source packages""" |
| 64 |
with ctx.shell.root_dir(): |
| 65 |
ctx.shell.mkdir_p("dist") |
| 66 |
|
| 67 |
|
| 68 |
names = sorted( |
| 69 |
set( |
| 70 |
name.rsplit(".", 1)[0] |
| 71 |
for name in _os.listdir("setups") |
| 72 |
if not name.startswith(".") |
| 73 |
and name.endswith((".py", ".toml")) |
| 74 |
) |
| 75 |
) |
| 76 |
|
| 77 |
|
| 78 |
for name in names: |
| 79 |
with _pkg_dir.sdist(ctx, name) as pkg_root: |
| 80 |
_build_sdist(ctx) |
| 81 |
for archive in _os.listdir("dist"): |
| 82 |
ctx.shell.cp( |
| 83 |
_os.path.join(pkg_root, "dist", archive), |
| 84 |
_os.path.join(ctx.shell.root, "dist", archive), |
| 85 |
) |
| 86 |
|
| 87 |
|
| 88 |
def _build_sdist(ctx): |
| 89 |
"""Build single sdist in the CWD""" |
| 90 |
if ctx.get("wheels", {}).get("build") == "universal": |
| 91 |
with open("setup.cfg", "wb") as fp: |
| 92 |
fp.write(b"[bdist_wheel]\n") |
| 93 |
fp.write(b"universal = 1\n") |
| 94 |
|
| 95 |
if _build is None: |
| 96 |
ctx.run("python setup.py sdist") |
| 97 |
else: |
| 98 |
ctx.run("python -m build --sdist") |