euscan-ng/setup.py

108 lines
2.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2019-12-05 17:46:19 +01:00
"""
Python setup script
"""
2012-03-27 18:45:35 +02:00
try:
from setuptools import setup, Command
2012-03-27 18:45:35 +02:00
except ImportError:
from distutils.core import setup, Command
from glob import glob
import io
import os
import re
import sys
2012-05-19 14:23:24 +02:00
from os.path import join, dirname
from distutils import log
2020-09-11 14:48:42 +02:00
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
__version__ = os.getenv('VERSION', default='9999')
cwd = os.getcwd()
# Load EPREFIX from Portage, fall back to the empty string if it fails
try:
from portage.const import EPREFIX
except ImportError:
EPREFIX = ''
# Python files that need `__version__ = ""` subbed, relative to this dir:
python_scripts = [os.path.join(cwd, path) for path in (
'bin/euscan',
)]
2012-03-27 18:45:35 +02:00
class SetVersion(Command):
"""Set python __version__ to our __version__."""
description = "hardcode scripts' version using VERSION from environment"
user_options = [] # [(long_name, short_name, desc),]
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
ver = 'git' if __version__ == '9999' else __version__
2019-12-05 17:46:19 +01:00
print(("Settings version to %s" % ver))
def sub(files, pattern):
for f in files:
updated_file = []
with io.open(f, 'r', 1, 'utf_8') as s:
for line in s:
newline = re.sub(pattern, '"%s"' % ver, line, 1)
if newline != line:
log.info("%s: %s" % (f, newline))
updated_file.append(newline)
with io.open(f, 'w', 1, 'utf_8') as s:
s.writelines(updated_file)
quote = r'[\'"]{1}'
python_re = r'(?<=^__version__ = )' + quote + '[^\'"]*' + quote
sub(python_scripts, python_re)
2020-09-11 21:41:20 +02:00
packages = [
str('.'.join(root.split(os.sep)[1:]))
for root, dirs, files in os.walk('src/euscan')
if '__init__.py' in files
]
2012-03-27 18:45:35 +02:00
setup(
name='euscan',
version=__version__,
description='Ebuild upstream scan utility.',
2012-05-19 14:23:24 +02:00
long_description=open(join(dirname(__file__), 'README.rst')).read(),
2020-09-11 21:41:20 +02:00
author='src_prepare',
maintainer='src_prepare',
url='https://gitlab.com/src_prepare/euscan-ng',
download_url=(
'https://github.com/iksaif/euscan/tarball/' +
('master' if __version__ == '9999' else ('euscan-%s' % __version__))
),
install_requires=[
# Command line utility
2020-09-11 14:48:42 +02:00
'beautifulsoup4>=4.8.2',
],
package_dir={'': 'src'},
packages=packages,
package_data={},
scripts=python_scripts,
2020-09-11 14:48:42 +02:00
# enable user install
# data_files=(
# (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'usr/share/man/man1'),
# glob('man/*')),
# ),
cmdclass={
'set_version': SetVersion,
},
)