|
1 | 1 | #!/usr/bin/env python |
2 | 2 | """ |
3 | | -Script to install pyopenms with the version specified in conf.py |
| 3 | +Script to install pyopenms with the version from ReadTheDocs environment variable. |
4 | 4 | This is used by ReadTheDocs build process to ensure the correct version is installed. |
5 | 5 | """ |
6 | 6 | import subprocess |
7 | 7 | import sys |
| 8 | +import os |
8 | 9 | import re |
9 | | -from pathlib import Path |
10 | 10 |
|
11 | | -def get_version_from_conf(): |
12 | | - """Extract version from docs/source/conf.py""" |
13 | | - conf_path = Path(__file__).parent.resolve() / "source" / "conf.py" |
| 11 | +def get_version_from_rtd(): |
| 12 | + """ |
| 13 | + Extract version from READTHEDOCS_VERSION_NAME environment variable. |
14 | 14 | |
15 | | - with open(conf_path, 'r', encoding='utf-8') as f: |
16 | | - content = f.read() |
| 15 | + The variable will be: |
| 16 | + - "latest" for latest builds |
| 17 | + - "release/X.Y.Z" for release branches |
| 18 | + - Tag names for tag builds |
17 | 19 | |
18 | | - # Look for version = u'X.Y.Z' pattern (with word boundary to be more specific) |
19 | | - match = re.search(r"\bversion\s*=\s*u?['\"]([^'\"]+)['\"]", content) |
| 20 | + Returns the version to install (e.g., "3.5.0" or "latest") |
| 21 | + """ |
| 22 | + rtd_version = os.environ.get('READTHEDOCS_VERSION_NAME', '') |
20 | 23 |
|
21 | | - if match: |
22 | | - version = match.group(1) |
23 | | - print(f"Found version in conf.py: {version}") |
| 24 | + if not rtd_version: |
| 25 | + print("Warning: READTHEDOCS_VERSION_NAME not set, defaulting to 'latest'") |
| 26 | + return 'latest' |
| 27 | + |
| 28 | + print(f"READTHEDOCS_VERSION_NAME: {rtd_version}") |
| 29 | + |
| 30 | + # If it's "latest", install latest version |
| 31 | + if rtd_version == "latest": |
| 32 | + return 'latest' |
| 33 | + |
| 34 | + # If it's a release branch like "release/3.5.0" or "Release/3.5.0", extract the version |
| 35 | + if rtd_version.lower().startswith('release/'): |
| 36 | + version = rtd_version.split('/', 1)[1] |
| 37 | + print(f"Extracted version from release branch: {version}") |
24 | 38 | return version |
25 | | - else: |
26 | | - raise ValueError("Could not find version in conf.py") |
| 39 | + |
| 40 | + # If it looks like a version tag (e.g., "v3.5.0", "3.5.0"), use it directly |
| 41 | + # Strip leading 'v' if present |
| 42 | + version = rtd_version.lstrip('v') |
| 43 | + print(f"Using version from tag: {version}") |
| 44 | + return version |
27 | 45 |
|
28 | 46 | def install_pyopenms(version): |
29 | | - """Install pyopenms with specific version""" |
30 | | - print(f"Installing pyopenms=={version}") |
| 47 | + """Install pyopenms with specific version or latest""" |
31 | 48 |
|
32 | | - # Use the extra index URL for pyopenms |
33 | | - subprocess.check_call([ |
| 49 | + # Build pip install command |
| 50 | + cmd = [ |
34 | 51 | sys.executable, "-m", "pip", "install", |
35 | 52 | "--extra-index-url", "https://pypi.cs.uni-tuebingen.de/simple/", |
36 | | - f"pyopenms=={version}" |
37 | | - ]) |
| 53 | + "--pre" # Allow pre-release versions |
| 54 | + ] |
| 55 | + |
| 56 | + if version == 'latest': |
| 57 | + print("Installing latest version of pyopenms") |
| 58 | + cmd.append("pyopenms") |
| 59 | + else: |
| 60 | + print(f"Installing pyopenms=={version}") |
| 61 | + cmd.append(f"pyopenms=={version}") |
| 62 | + |
| 63 | + subprocess.check_call(cmd) |
38 | 64 |
|
39 | | - print(f"Successfully installed pyopenms=={version}") |
| 65 | + print(f"Successfully installed pyopenms") |
40 | 66 |
|
41 | 67 | if __name__ == "__main__": |
42 | 68 | try: |
43 | | - version = get_version_from_conf() |
| 69 | + version = get_version_from_rtd() |
44 | 70 | install_pyopenms(version) |
45 | 71 | except Exception as e: |
46 | 72 | print(f"Error: {e}", file=sys.stderr) |
|
0 commit comments