100 lines
2.8 KiB
Python
100 lines
2.8 KiB
Python
|
# This software is licensed by the MIT License (MIT), see LICENSE file
|
||
|
|
||
|
# Use it with: `python setup.py sdist bdist_wheel`
|
||
|
|
||
|
import os
|
||
|
|
||
|
from pathlib import Path
|
||
|
from setuptools import setup, find_packages
|
||
|
|
||
|
AUTHOR = 'Author'
|
||
|
AUTHOR_EMAIL = 'email@example.com'
|
||
|
PROJECT_URL = 'https://dev.lirent.ru/python/package-name'
|
||
|
PROJECT_REPO = f'{PROJECT_URL}/src/branch/master'
|
||
|
PROJECT_DOCS = f'{PROJECT_REPO}/README.md'
|
||
|
DESCRIPTION = 'Package description'
|
||
|
KEYWORDS = ''
|
||
|
PYTHON_VERSION = "3.11"
|
||
|
|
||
|
CLASSIFIERS = [
|
||
|
f'Programming Language :: Python :: {PYTHON_VERSION}',
|
||
|
'License :: OSI Approved :: MIT License',
|
||
|
'Operating System :: OS Independent',
|
||
|
'Framework :: Django :: 5.0'
|
||
|
]
|
||
|
|
||
|
|
||
|
CWD = Path(__file__).resolve().parent
|
||
|
|
||
|
|
||
|
def get_package_name():
|
||
|
excludes = [('.git', '.git'), ('test', '')]
|
||
|
candidates = []
|
||
|
|
||
|
with open(CWD / '.gitignore', 'r', -1, 'utf8') as f:
|
||
|
for line in f.readlines():
|
||
|
line = line.strip()
|
||
|
if line.endswith('/'):
|
||
|
line = line[1:-1] if line.startswith('/') else line[:-1]
|
||
|
if line.count('*') == 1:
|
||
|
line = line.split('*')
|
||
|
elif line.count('*') > 1:
|
||
|
raise AttributeError(f'unexpected value in .gitignore: {line}/')
|
||
|
else:
|
||
|
line = (line, line)
|
||
|
excludes.append(line)
|
||
|
|
||
|
for instance in os.listdir(CWD):
|
||
|
if os.path.isdir(CWD / instance):
|
||
|
exclude = False
|
||
|
for x in excludes:
|
||
|
if instance.startswith(x[0]) and instance.endswith(x[1]):
|
||
|
exclude = True
|
||
|
break
|
||
|
if not exclude:
|
||
|
candidates.append(instance)
|
||
|
if len(candidates) != 1:
|
||
|
raise AttributeError('package name cannot be determined')
|
||
|
else:
|
||
|
return candidates[0]
|
||
|
|
||
|
|
||
|
def readme():
|
||
|
with open(CWD / 'README.md', 'r', -1, 'utf8') as f:
|
||
|
return f.read()
|
||
|
|
||
|
|
||
|
def version():
|
||
|
with open(CWD / 'RELEASE-NOTES.md', 'r', -1, 'utf8') as f:
|
||
|
for line in f.readlines():
|
||
|
if line.startswith('## '):
|
||
|
return line[2:].strip().split(' ')[0]
|
||
|
raise AttributeError('version not found')
|
||
|
|
||
|
|
||
|
def requirements():
|
||
|
with open(CWD / 'requirements.txt', 'r', -1, 'utf8') as f:
|
||
|
return [line.strip() for line in f.readlines() if line.strip()]
|
||
|
|
||
|
|
||
|
setup(
|
||
|
name=get_package_name(),
|
||
|
version=version(),
|
||
|
author=AUTHOR,
|
||
|
author_email=AUTHOR_EMAIL,
|
||
|
description=DESCRIPTION,
|
||
|
long_description=readme(),
|
||
|
long_description_content_type='text/markdown',
|
||
|
url=PROJECT_URL,
|
||
|
packages=find_packages(),
|
||
|
install_requires=requirements(),
|
||
|
classifiers=CLASSIFIERS,
|
||
|
keywords=KEYWORDS,
|
||
|
project_urls={
|
||
|
'homepage': PROJECT_URL,
|
||
|
'repository': PROJECT_REPO,
|
||
|
'documentation': PROJECT_DOCS
|
||
|
},
|
||
|
python_requires=f'>={PYTHON_VERSION}'
|
||
|
)
|