allow distributions that place packages in a "src" directory
Joseph Weston authored on 17/10/2019 23:14:31 • GitHub committed on 17/10/2019 23:14:31... | ... |
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
5 | 5 |
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
6 | 6 |
|
7 | 7 |
## [Unreleased] |
8 |
+### Added |
|
9 |
+- Allow distributions that place packages in a "src" directory |
|
8 | 10 |
### Changed |
9 | 11 |
- Replace tool "install-miniver" with a tool "miniver" with a command "install" |
10 | 12 |
|
... | ... |
@@ -16,6 +16,13 @@ __all__ = [] |
16 | 16 |
package_root = os.path.dirname(os.path.realpath(__file__)) |
17 | 17 |
package_name = os.path.basename(package_root) |
18 | 18 |
distr_root = os.path.dirname(package_root) |
19 |
+# If the package is inside a "src" directory the |
|
20 |
+# distribution root is 1 level up. |
|
21 |
+if os.path.split(distr_root)[1] == "src": |
|
22 |
+ _package_root_inside_src = True |
|
23 |
+ distr_root = os.path.dirname(distr_root) |
|
24 |
+else: |
|
25 |
+ _package_root_inside_src = False |
|
19 | 26 |
|
20 | 27 |
STATIC_VERSION_FILE = "_static_version.py" |
21 | 28 |
|
... | ... |
@@ -190,7 +197,11 @@ class _build_py(build_py_orig): |
190 | 197 |
class _sdist(sdist_orig): |
191 | 198 |
def make_release_tree(self, base_dir, files): |
192 | 199 |
super().make_release_tree(base_dir, files) |
193 |
- _write_version(os.path.join(base_dir, package_name, STATIC_VERSION_FILE)) |
|
200 |
+ if _package_root_inside_src: |
|
201 |
+ p = os.path.join("src", package_name) |
|
202 |
+ else: |
|
203 |
+ p = package_name |
|
204 |
+ _write_version(os.path.join(base_dir, p, STATIC_VERSION_FILE)) |
|
194 | 205 |
|
195 | 206 |
|
196 | 207 |
cmdclass = dict(sdist=_sdist, build_py=_build_py) |