Skip to content

Commit b5bac72

Browse files
committed
read version from __init__
1 parent 5f507d0 commit b5bac72

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

optillm/__init__.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
from importlib import util
22
import os
3-
import re
43

5-
def get_version_from_setup():
6-
try:
7-
setup_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setup.py')
8-
with open(setup_path, 'r') as f:
9-
content = f.read()
10-
version_match = re.search(r'version=["\']([^"\']+)["\']', content)
11-
if version_match:
12-
return version_match.group(1)
13-
except Exception:
14-
pass
15-
return "unknown"
4+
# Version information
5+
__version__ = "0.1.3"
166

177
# Get the path to the root optillm.py
188
spec = util.spec_from_file_location(
@@ -46,9 +36,6 @@ def get_version_from_setup():
4636
# Export streaming response generation
4737
generate_streaming_response = module.generate_streaming_response
4838

49-
# Version information
50-
__version__ = get_version_from_setup()
51-
5239
# List of exported symbols
5340
__all__ = [
5441
'main',

optillm/plugins/readurls_plugin.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,10 @@
44
import os
55
from bs4 import BeautifulSoup
66
from urllib.parse import urlparse
7+
from optillm import __version__
78

89
SLUG = "readurls"
910

10-
def get_version():
11-
try:
12-
# Get path to setup.py relative to this file
13-
current_dir = os.path.dirname(__file__)
14-
package_root = os.path.dirname(os.path.dirname(current_dir))
15-
setup_path = os.path.join(package_root, 'setup.py')
16-
17-
with open(setup_path, 'r') as f:
18-
content = f.read()
19-
version_match = re.search(r'version=["\']([^"\']+)["\']', content)
20-
if version_match:
21-
return version_match.group(1)
22-
except Exception:
23-
pass
24-
return "unknown"
25-
2611
def extract_urls(text: str) -> List[str]:
2712
# Updated regex pattern to be more precise
2813
url_pattern = re.compile(r'https?://[^\s\'"]+')
@@ -41,9 +26,8 @@ def extract_urls(text: str) -> List[str]:
4126

4227
def fetch_webpage_content(url: str, max_length: int = 100000) -> str:
4328
try:
44-
version = get_version()
4529
headers = {
46-
'User-Agent': f'optillm/{version} (https://github.com/codelion/optillm)'
30+
'User-Agent': f'optillm/{__version__} (https://github.com/codelion/optillm)'
4731
}
4832

4933
response = requests.get(url, headers=headers, timeout=10)

setup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
from setuptools import setup, find_packages
22

3+
def read_version():
4+
version_dict = {}
5+
try:
6+
with open('optillm/__init__.py', 'r') as f:
7+
exec(f.read(), version_dict)
8+
return version_dict.get('__version__', 'unknown')
9+
except Exception:
10+
return 'unknown'
11+
312
setup(
413
name="optillm",
514
version="0.1.2",

0 commit comments

Comments
 (0)