forked from usgs/waterdataui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
104 lines (88 loc) · 3.63 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Setuptools configuration for the Water Data For The Nation user interface.
This setup script requires that static assets have been built into the
`assets/dist` directory prior to the build.
"""
import os
from setuptools import setup, find_packages
def read_requirements():
"""
Get application requirements from
the requirements.txt file.
:return: portal_ui Python requirements
:rtype: list
"""
with open('requirements.txt', 'r') as req:
requirements = req.readlines()
install_requires = [r.strip() for r in requirements if r.find('git+') != 0]
dependency_links = [r.strip() for r in requirements if r.find('git+') == 0]
return {'install_requires': install_requires, 'dependency_links': dependency_links}
def read(filepath):
"""
Read the contents from a file.
:param str filepath: path to the file to be read
:return: file contents
:rtype: str
"""
with open(filepath, 'r') as file:
content = file.read()
return content
def identify_data_files(data_dirs, exclusions=('.gitignore', '.webassets-cache')):
"""
Recursively introspect the contents of a directory. Once the contents
have been introspected, generate a list directories and sub-directories
with their contents as lists.
Any files listed in exclusions will not be included
as a data file. Please note that the list generated by this function
will override any exclusions defined in MANIFEST.in. This
means that if one specifies a file to be excluded in MANIFEST.in,
but this function includes that file as a data file, then it's
going to be in the distributable.
:param list data_dirs: list of tuples each of the form: (`installation directory`, `source directory`)
the installation directory can be None to preserve the source directory's structure in the wheel's data
directory
:param tuple exclusions: tuple of all the files or directories NOT to include as a data file
:return: all contents of the directories as a list of tuples
:rtype: list
"""
directory_data_files = []
for installation_directory, directory_name in data_dirs:
for root, _, files in os.walk(directory_name):
pathnames = [
os.path.relpath(os.path.join(root, filename))
for filename in files
if not any(ex in os.path.join(root, filename)
for ex in exclusions)
]
if pathnames:
data_install_path = (
installation_directory if installation_directory else os.path.relpath(root).strip('../')
)
data_file_element = (data_install_path, pathnames)
directory_data_files.append(data_file_element)
return directory_data_files
setup(
name='usgs_waterdata_ui',
version='0.49.0dev',
description='USGS Water Data',
author='Mary Bucknell, Andrew Yan, Dan Naab, Janell Fry, Aaron Briggs',
author_email='[email protected]',
packages=find_packages(),
include_package_data=True,
long_description=read('README.md'),
install_requires=read_requirements()['install_requires'],
platforms='any',
test_suite='unittest:TestLoader',
zip_safe=False,
# include the tier agnostic configuration file in the distributable
# the file gets placed in site-packages upon dist installation
py_modules=['config'],
# include static files in the distributable
# they will appear in the root of the virtualenv upon dist installation
data_files=identify_data_files(
[
(None, '../assets/dist'),
('data', 'data')
]
)
)