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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
| 2 |
+
# !/usr/bin/env python
|
| 3 |
+
import os
|
| 4 |
+
from setuptools import find_packages, setup
|
| 5 |
+
from typing import List
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def readme():
|
| 9 |
+
with open('README.md', encoding='utf-8') as f:
|
| 10 |
+
content = f.read()
|
| 11 |
+
return content
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
version_file = 'swift/version.py'
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def get_version():
|
| 18 |
+
with open(version_file, 'r', encoding='utf-8') as f:
|
| 19 |
+
exec(compile(f.read(), version_file, 'exec'))
|
| 20 |
+
return locals()['__version__']
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def parse_requirements(fname='requirements.txt', with_version=True):
|
| 24 |
+
"""
|
| 25 |
+
Parse the package dependencies listed in a requirements file but strips
|
| 26 |
+
specific versioning information.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
fname (str): path to requirements file
|
| 30 |
+
with_version (bool, default=False): if True include version specs
|
| 31 |
+
|
| 32 |
+
Returns:
|
| 33 |
+
List[str]: list of requirements items
|
| 34 |
+
|
| 35 |
+
CommandLine:
|
| 36 |
+
python -c "import setup; print(setup.parse_requirements())"
|
| 37 |
+
"""
|
| 38 |
+
import re
|
| 39 |
+
import sys
|
| 40 |
+
from os.path import exists
|
| 41 |
+
require_fpath = fname
|
| 42 |
+
|
| 43 |
+
def parse_line(line):
|
| 44 |
+
"""
|
| 45 |
+
Parse information from a line in a requirements text file
|
| 46 |
+
"""
|
| 47 |
+
if line.startswith('-r '):
|
| 48 |
+
# Allow specifying requirements in other files
|
| 49 |
+
target = line.split(' ')[1]
|
| 50 |
+
relative_base = os.path.dirname(fname)
|
| 51 |
+
absolute_target = os.path.join(relative_base, target)
|
| 52 |
+
for info in parse_require_file(absolute_target):
|
| 53 |
+
yield info
|
| 54 |
+
else:
|
| 55 |
+
info = {'line': line}
|
| 56 |
+
if line.startswith('-e '):
|
| 57 |
+
info['package'] = line.split('#egg=')[1]
|
| 58 |
+
else:
|
| 59 |
+
# Remove versioning from the package
|
| 60 |
+
pat = '(' + '|'.join(['>=', '==', '>']) + ')'
|
| 61 |
+
parts = re.split(pat, line, maxsplit=1)
|
| 62 |
+
parts = [p.strip() for p in parts]
|
| 63 |
+
|
| 64 |
+
info['package'] = parts[0]
|
| 65 |
+
if len(parts) > 1:
|
| 66 |
+
op, rest = parts[1:]
|
| 67 |
+
if ';' in rest:
|
| 68 |
+
# Handle platform specific dependencies
|
| 69 |
+
# http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies
|
| 70 |
+
version, platform_deps = map(str.strip, rest.split(';'))
|
| 71 |
+
info['platform_deps'] = platform_deps
|
| 72 |
+
else:
|
| 73 |
+
version = rest # NOQA
|
| 74 |
+
info['version'] = (op, version)
|
| 75 |
+
yield info
|
| 76 |
+
|
| 77 |
+
def parse_require_file(fpath):
|
| 78 |
+
with open(fpath, 'r', encoding='utf-8') as f:
|
| 79 |
+
for line in f.readlines():
|
| 80 |
+
line = line.strip()
|
| 81 |
+
if line.startswith('http'):
|
| 82 |
+
print('skip http requirements %s' % line)
|
| 83 |
+
continue
|
| 84 |
+
if line and not line.startswith('#') and not line.startswith('--'):
|
| 85 |
+
for info in parse_line(line):
|
| 86 |
+
yield info
|
| 87 |
+
elif line and line.startswith('--find-links'):
|
| 88 |
+
eles = line.split()
|
| 89 |
+
for e in eles:
|
| 90 |
+
e = e.strip()
|
| 91 |
+
if 'http' in e:
|
| 92 |
+
info = dict(dependency_links=e)
|
| 93 |
+
yield info
|
| 94 |
+
|
| 95 |
+
def gen_packages_items():
|
| 96 |
+
items = []
|
| 97 |
+
deps_link = []
|
| 98 |
+
if exists(require_fpath):
|
| 99 |
+
for info in parse_require_file(require_fpath):
|
| 100 |
+
if 'dependency_links' not in info:
|
| 101 |
+
parts = [info['package']]
|
| 102 |
+
if with_version and 'version' in info:
|
| 103 |
+
parts.extend(info['version'])
|
| 104 |
+
if not sys.version.startswith('3.4'):
|
| 105 |
+
# apparently package_deps are broken in 3.4
|
| 106 |
+
platform_deps = info.get('platform_deps')
|
| 107 |
+
if platform_deps is not None:
|
| 108 |
+
parts.append(';' + platform_deps)
|
| 109 |
+
item = ''.join(parts)
|
| 110 |
+
items.append(item)
|
| 111 |
+
else:
|
| 112 |
+
deps_link.append(info['dependency_links'])
|
| 113 |
+
return items, deps_link
|
| 114 |
+
|
| 115 |
+
return gen_packages_items()
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
if __name__ == '__main__':
|
| 119 |
+
install_requires, deps_link = parse_requirements('requirements.txt')
|
| 120 |
+
extra_requires = {}
|
| 121 |
+
all_requires = []
|
| 122 |
+
extra_requires['eval'], _ = parse_requirements('requirements/eval.txt')
|
| 123 |
+
extra_requires['swanlab'], _ = parse_requirements('requirements/swanlab.txt')
|
| 124 |
+
extra_requires['seq_parallel'], _ = parse_requirements('requirements/seq_parallel.txt')
|
| 125 |
+
all_requires.extend(install_requires)
|
| 126 |
+
all_requires.extend(extra_requires['eval'])
|
| 127 |
+
all_requires.extend(extra_requires['seq_parallel'])
|
| 128 |
+
all_requires.extend(extra_requires['swanlab'])
|
| 129 |
+
extra_requires['all'] = all_requires
|
| 130 |
+
|
| 131 |
+
setup(
|
| 132 |
+
name='ms_swift',
|
| 133 |
+
version=get_version(),
|
| 134 |
+
description='Swift: Scalable lightWeight Infrastructure for Fine-Tuning',
|
| 135 |
+
long_description=readme(),
|
| 136 |
+
long_description_content_type='text/markdown',
|
| 137 |
+
author='DAMO ModelScope teams',
|
| 138 |
+
author_email='contact@modelscope.cn',
|
| 139 |
+
keywords='python, petl, efficient tuners',
|
| 140 |
+
url='https://github.com/modelscope/swift',
|
| 141 |
+
packages=find_packages(exclude=('configs', 'demo')),
|
| 142 |
+
include_package_data=True,
|
| 143 |
+
package_data={
|
| 144 |
+
'': ['*.h', '*.cpp', '*.cu'],
|
| 145 |
+
},
|
| 146 |
+
classifiers=[
|
| 147 |
+
'Development Status :: 4 - Beta',
|
| 148 |
+
'License :: OSI Approved :: Apache Software License',
|
| 149 |
+
'Operating System :: OS Independent',
|
| 150 |
+
'Programming Language :: Python :: 3',
|
| 151 |
+
'Programming Language :: Python :: 3.8',
|
| 152 |
+
'Programming Language :: Python :: 3.9',
|
| 153 |
+
'Programming Language :: Python :: 3.10',
|
| 154 |
+
'Programming Language :: Python :: 3.11',
|
| 155 |
+
'Programming Language :: Python :: 3.12',
|
| 156 |
+
],
|
| 157 |
+
license='Apache License 2.0',
|
| 158 |
+
tests_require=parse_requirements('requirements/tests.txt'),
|
| 159 |
+
install_requires=install_requires,
|
| 160 |
+
extras_require=extra_requires,
|
| 161 |
+
entry_points={
|
| 162 |
+
'console_scripts': ['swift=swift.cli.main:cli_main', 'megatron=swift.cli._megatron.main:cli_main']
|
| 163 |
+
},
|
| 164 |
+
dependency_links=deps_link,
|
| 165 |
+
zip_safe=False)
|