Add utility to generate a setup.py with updated
requirements. GitLab issue #200 #149 Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
4
Makefile
4
Makefile
@@ -6,6 +6,7 @@ help:
|
||||
@echo "clean-build - Remove build artifacts."
|
||||
@echo "clean-pyc - Remove Python artifacts."
|
||||
@echo "clean - Remove Python and build artifacts."
|
||||
@echo "generate_setup - Create and updated setup.py"
|
||||
|
||||
@echo "test-all - Run all tests."
|
||||
@echo "test MODULE=<python module name> - Run tests for a single app, module or test class."
|
||||
@@ -163,6 +164,9 @@ requirements_docs:
|
||||
requirements_testing:
|
||||
pip install -r requirements/testing.txt
|
||||
|
||||
generate_setup:
|
||||
@./generate_setup.py
|
||||
@echo "Complete."
|
||||
|
||||
# Releases
|
||||
|
||||
|
||||
51
generate_setup.py
Executable file
51
generate_setup.py
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django.template import Template, Context
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
REQUIREMENTS_FILE = 'requirements.txt'
|
||||
SETUP_TEMPLATE = 'setup.py.tmpl'
|
||||
|
||||
|
||||
def get_requirements(base_directory, filename):
|
||||
result = []
|
||||
|
||||
with open(os.path.join(base_directory, filename)) as file_object:
|
||||
for line in file_object:
|
||||
if line.startswith('-r'):
|
||||
line = line.split('\n')[0][3:]
|
||||
directory, filename = os.path.split(line)
|
||||
result.extend(
|
||||
get_requirements(
|
||||
base_directory=os.path.join(base_directory, directory), filename=filename
|
||||
)
|
||||
)
|
||||
elif not line.startswith('\n'):
|
||||
result.append(line.split('\n')[0])
|
||||
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mayan.settings')
|
||||
django.setup()
|
||||
|
||||
requirements = get_requirements(
|
||||
base_directory=BASE_DIR, filename=REQUIREMENTS_FILE
|
||||
)
|
||||
|
||||
with open(SETUP_TEMPLATE) as file_object:
|
||||
template = file_object.read()
|
||||
result = Template(template).render(
|
||||
context=Context({'requirements': requirements})
|
||||
)
|
||||
|
||||
with open('setup.py', 'w') as file_object:
|
||||
file_object.write(result)
|
||||
@@ -1,2 +1,2 @@
|
||||
-r base.txt
|
||||
Django==1.10.7
|
||||
-r base.txt
|
||||
|
||||
5
setup.py
5
setup.py
@@ -56,11 +56,11 @@ def find_packages(directory):
|
||||
return packages
|
||||
|
||||
install_requires = """
|
||||
Django==1.10.7
|
||||
Pillow==4.2.0
|
||||
PyYAML==3.12
|
||||
celery==3.1.24
|
||||
cssmin==0.2.0
|
||||
Django==1.10.7
|
||||
django-activity-stream==0.6.3
|
||||
django-autoadmin==1.1.1
|
||||
django-celery==3.2.1
|
||||
@@ -82,8 +82,8 @@ djangorestframework==3.3.2
|
||||
djangorestframework-recursive==0.1.1
|
||||
fusepy==2.0.4
|
||||
pdfminer==20140328
|
||||
PyPDF2==1.26.0
|
||||
pycountry==1.20
|
||||
PyPDF2==1.26.0
|
||||
pyocr==0.4.5
|
||||
python-dateutil==2.5.3
|
||||
python-gnupg==0.3.9
|
||||
@@ -111,7 +111,6 @@ setup(
|
||||
'License :: OSI Approved :: Apache Software License',
|
||||
'Natural Language :: English',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Topic :: Internet :: WWW/HTTP',
|
||||
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
|
||||
|
||||
98
setup.py.tmpl
Normal file
98
setup.py.tmpl
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
from setuptools import setup
|
||||
except ImportError:
|
||||
from distutils.core import setup
|
||||
|
||||
import mayan
|
||||
|
||||
PACKAGE_NAME = 'mayan-edms'
|
||||
PACKAGE_DIR = 'mayan'
|
||||
|
||||
if sys.argv[-1] == 'publish':
|
||||
os.system('python setup.py sdist upload')
|
||||
sys.exit()
|
||||
|
||||
|
||||
def fullsplit(path, result=None):
|
||||
"""
|
||||
Split a pathname into components (the opposite of os.path.join) in a
|
||||
platform-neutral way.
|
||||
"""
|
||||
if result is None:
|
||||
result = []
|
||||
head, tail = os.path.split(path)
|
||||
if head == '':
|
||||
return [tail] + result
|
||||
if head == path:
|
||||
return result
|
||||
return fullsplit(head, [tail] + result)
|
||||
|
||||
|
||||
def find_packages(directory):
|
||||
# Compile the list of packages available, because distutils doesn't have
|
||||
# an easy way to do this.
|
||||
packages, data_files = [], []
|
||||
root_dir = os.path.dirname(__file__)
|
||||
if root_dir != '':
|
||||
os.chdir(root_dir)
|
||||
|
||||
for dirpath, dirnames, filenames in os.walk(directory):
|
||||
if not dirpath.startswith('mayan/media'):
|
||||
# Ignore dirnames that start with '.'
|
||||
if os.path.basename(dirpath).startswith('.'):
|
||||
continue
|
||||
if '__init__.py' in filenames:
|
||||
packages.append('.'.join(fullsplit(dirpath)))
|
||||
elif filenames:
|
||||
data_files.append(
|
||||
[dirpath, [os.path.join(dirpath, f) for f in filenames]]
|
||||
)
|
||||
|
||||
return packages
|
||||
|
||||
install_requires = """
|
||||
{% for requirement in requirements %}{{ requirement|safe }}
|
||||
{% endfor %}""".split()
|
||||
|
||||
with open('README.rst') as f:
|
||||
readme = f.read()
|
||||
|
||||
with open('HISTORY.rst') as f:
|
||||
history = f.read()
|
||||
|
||||
setup(
|
||||
author='Roberto Rosario',
|
||||
author_email='roberto.rosario@mayan-edms.com',
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Environment :: Web Environment',
|
||||
'Framework :: Django',
|
||||
'Intended Audience :: Education',
|
||||
'Intended Audience :: Developers',
|
||||
'Intended Audience :: Information Technology',
|
||||
'License :: OSI Approved :: Apache Software License',
|
||||
'Natural Language :: English',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Topic :: Internet :: WWW/HTTP',
|
||||
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
|
||||
'Topic :: Communications :: File Sharing',
|
||||
],
|
||||
description='Free Open Source Electronic Document Management System',
|
||||
include_package_data=True,
|
||||
install_requires=install_requires,
|
||||
license='Apache 2.0',
|
||||
long_description=readme + '\n\n' + history,
|
||||
name=PACKAGE_NAME,
|
||||
packages=find_packages(PACKAGE_DIR),
|
||||
platforms=['any'],
|
||||
scripts=['mayan/bin/mayan-edms.py'],
|
||||
url='https://gitlab.com/mayan-edms/mayan-edms',
|
||||
version=mayan.__version__,
|
||||
zip_safe=False,
|
||||
)
|
||||
Reference in New Issue
Block a user