Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) ModelScope Contributors. All rights reserved.
from setuptools import find_packages, setup

import re


def get_readme():
with open('README.md', encoding='utf-8') as f:
Expand All @@ -13,8 +15,7 @@ def get_readme():

def get_version():
with open(version_file, 'r', encoding='utf-8') as f:
exec(compile(f.read(), version_file, 'exec'))
return locals()['__version__']
return re.search(r'^__version__\s*=\s*["\'](.+?)["\']', f.read(), re.M).group(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation has two potential issues:

  1. It will raise an AttributeError if re.search returns None (i.e., the version string is not found), which will crash the setup process.
  2. The regex character set ["\'] is likely incorrect. It matches a double quote, a backslash, or a single quote. The intention is likely to match only a double or single quote, which would be ["'].

A more robust implementation would handle the None case and use the correct regex.

Suggested change
return re.search(r'^__version__\s*=\s*["\'](.+?)["\']', f.read(), re.M).group(1)
match = re.search(r"""^__version__\s*=\s*["'](.+?)["']""", f.read(), re.M)
if not match:
raise RuntimeError('Unable to find version string.')
return match.group(1)



def parse_requirements(path='requirements.txt'):
Expand Down
Loading