|
1 | 1 | #!/usr/bin/env python |
2 | 2 | import os |
| 3 | +import re |
3 | 4 | import shutil |
4 | 5 | import subprocess |
5 | 6 | from pathlib import Path |
|
11 | 12 | ROOT_DIR = Path(__file__).parent.resolve() |
12 | 13 |
|
13 | 14 |
|
| 15 | +def _run_cmd(cmd, default): |
| 16 | + try: |
| 17 | + return subprocess.check_output(cmd, cwd=ROOT_DIR).decode('ascii').strip() |
| 18 | + except Exception: |
| 19 | + return default |
| 20 | + |
| 21 | + |
14 | 22 | # Creating the version file |
15 | 23 | version = '0.10.0a0' |
16 | | -sha = 'Unknown' |
17 | | - |
18 | | -try: |
19 | | - sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=ROOT_DIR).decode('ascii').strip() |
20 | | -except Exception: |
21 | | - pass |
| 24 | +sha = _run_cmd(['git', 'rev-parse', 'HEAD'], default='Unknown') |
22 | 25 |
|
23 | 26 | if os.getenv('BUILD_VERSION'): |
24 | 27 | version = os.getenv('BUILD_VERSION') |
@@ -65,7 +68,17 @@ def _get_packages(): |
65 | 68 | "third_party*", |
66 | 69 | "build_tools*", |
67 | 70 | ] |
68 | | - if os.environ.get('UPLOAD_CHANNEL', '') == 'test': |
| 71 | + exclude_prototype = False |
| 72 | + branch_name = _run_cmd(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], default=None) |
| 73 | + is_on_tag = _run_cmd(['git', 'describe', '--tags', '--exact-match', '@'], default=None) |
| 74 | + |
| 75 | + if branch_name is not None and branch_name.startswith('release/'): |
| 76 | + print('On release branch') |
| 77 | + exclude_prototype = True |
| 78 | + if is_on_tag is not None and re.match(r'v[\d.]+(-rc\d+)?', is_on_tag): |
| 79 | + print('On release tag') |
| 80 | + exclude_prototype = True |
| 81 | + if exclude_prototype: |
69 | 82 | print('Excluding torchaudio.prototype from the package.') |
70 | 83 | exclude.append("torchaudio.prototype") |
71 | 84 | return find_packages(exclude=exclude) |
|
0 commit comments