Skip to content

Commit

Permalink
Merge pull request #161 from codelion/fix-version-info
Browse files Browse the repository at this point in the history
read version from __init__
  • Loading branch information
codelion authored Jan 29, 2025
2 parents 5f507d0 + b5bac72 commit 70ff4de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
17 changes: 2 additions & 15 deletions optillm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
from importlib import util
import os
import re

def get_version_from_setup():
try:
setup_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setup.py')
with open(setup_path, 'r') as f:
content = f.read()
version_match = re.search(r'version=["\']([^"\']+)["\']', content)
if version_match:
return version_match.group(1)
except Exception:
pass
return "unknown"
# Version information
__version__ = "0.1.3"

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

# Version information
__version__ = get_version_from_setup()

# List of exported symbols
__all__ = [
'main',
Expand Down
20 changes: 2 additions & 18 deletions optillm/plugins/readurls_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,10 @@
import os
from bs4 import BeautifulSoup
from urllib.parse import urlparse
from optillm import __version__

SLUG = "readurls"

def get_version():
try:
# Get path to setup.py relative to this file
current_dir = os.path.dirname(__file__)
package_root = os.path.dirname(os.path.dirname(current_dir))
setup_path = os.path.join(package_root, 'setup.py')

with open(setup_path, 'r') as f:
content = f.read()
version_match = re.search(r'version=["\']([^"\']+)["\']', content)
if version_match:
return version_match.group(1)
except Exception:
pass
return "unknown"

def extract_urls(text: str) -> List[str]:
# Updated regex pattern to be more precise
url_pattern = re.compile(r'https?://[^\s\'"]+')
Expand All @@ -41,9 +26,8 @@ def extract_urls(text: str) -> List[str]:

def fetch_webpage_content(url: str, max_length: int = 100000) -> str:
try:
version = get_version()
headers = {
'User-Agent': f'optillm/{version} (https://github.com/codelion/optillm)'
'User-Agent': f'optillm/{__version__} (https://github.com/codelion/optillm)'
}

response = requests.get(url, headers=headers, timeout=10)
Expand Down
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from setuptools import setup, find_packages

def read_version():
version_dict = {}
try:
with open('optillm/__init__.py', 'r') as f:
exec(f.read(), version_dict)
return version_dict.get('__version__', 'unknown')
except Exception:
return 'unknown'

setup(
name="optillm",
version="0.1.2",
Expand Down

0 comments on commit 70ff4de

Please sign in to comment.