|
3 | 3 | import os
|
4 | 4 | import subprocess
|
5 | 5 | from collections import namedtuple
|
6 |
| -from distutils.command.build_py import build_py as build_py_orig |
7 | 6 |
|
| 7 | +from setuptools.command.build_py import build_py as build_py_orig |
8 | 8 | from setuptools.command.sdist import sdist as sdist_orig
|
9 | 9 |
|
10 | 10 | Version = namedtuple("Version", ("release", "dev", "labels"))
|
|
15 | 15 | package_root = os.path.dirname(os.path.realpath(__file__))
|
16 | 16 | package_name = os.path.basename(package_root)
|
17 | 17 | distr_root = os.path.dirname(package_root)
|
| 18 | +# If the package is inside a "src" directory the |
| 19 | +# distribution root is 1 level up. |
| 20 | +if os.path.split(distr_root)[1] == "src": |
| 21 | + _package_root_inside_src = True |
| 22 | + distr_root = os.path.dirname(distr_root) |
| 23 | +else: |
| 24 | + _package_root_inside_src = False |
18 | 25 |
|
19 | 26 | STATIC_VERSION_FILE = "_static_version.py"
|
20 | 27 |
|
@@ -189,7 +196,11 @@ def run(self):
|
189 | 196 | class _sdist(sdist_orig):
|
190 | 197 | def make_release_tree(self, base_dir, files):
|
191 | 198 | super().make_release_tree(base_dir, files)
|
192 |
| - _write_version(os.path.join(base_dir, package_name, STATIC_VERSION_FILE)) |
| 199 | + if _package_root_inside_src: |
| 200 | + p = os.path.join("src", package_name) |
| 201 | + else: |
| 202 | + p = package_name |
| 203 | + _write_version(os.path.join(base_dir, p, STATIC_VERSION_FILE)) |
193 | 204 |
|
194 | 205 |
|
195 | 206 | cmdclass = dict(sdist=_sdist, build_py=_build_py)
|
0 commit comments