Debian Codegraph @

tasks/build_/source.py

raw symbols SCIP
1 # -*- coding: ascii -*-
2 #
3 # Copyright 2007 - 2025
4 # Andr\xe9 Malo or his licensors, as applicable
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
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 # pylint: disable = import-outside-toplevel
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 # Collect names
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 # Build each package from a copy
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")