-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
306 lines (242 loc) · 9.29 KB
/
setup.py
File metadata and controls
306 lines (242 loc) · 9.29 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/usr/bin/env python
"""
Setup configuration for WaveVerify package.
This module handles the installation and packaging of WaveVerify, an audio
watermarking library designed for media authentication and deepfake detection.
It manages dependencies, package discovery, and metadata configuration.
Author: Aditya Pujari and Ajita Rattani
License: MIT (see LICENSE file for details)
"""
# =============================================================================
# IMPORTS
# =============================================================================
import logging
import sys
from pathlib import Path
from typing import Dict, List, Optional, Any
from setuptools import setup, find_packages
# =============================================================================
# LOGGING CONFIGURATION
# =============================================================================
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# =============================================================================
# CONSTANTS
# =============================================================================
PACKAGE_NAME: str = "waveverify"
VERSION: str = "0.1.0"
AUTHOR: str = "Aditya Pujari and Ajita Rattani"
AUTHOR_EMAIL: str = ""
DESCRIPTION: str = "Audio watermarking for media authentication and combatting deepfakes"
URL: str = "https://github.com/pujariaditya/WaveVerify"
LICENSE: str = "MIT"
PYTHON_REQUIRES: str = ">=3.8"
# File paths
PROJECT_ROOT: Path = Path(__file__).parent.resolve()
README_PATH: Path = PROJECT_ROOT / "README.md"
REQUIREMENTS_PATH: Path = PROJECT_ROOT / "requirements.txt"
# Package configuration
KEYWORDS: List[str] = [
"audio", "watermarking", "deepfake", "detection",
"authentication", "watermark", "embedding"
]
CLASSIFIERS: List[str] = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Multimedia :: Sound/Audio :: Analysis",
f"License :: OSI Approved :: {LICENSE} License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Operating System :: OS Independent",
]
PROJECT_URLS: Dict[str, str] = {
"Bug Tracker": f"{URL}/issues",
"Documentation": URL,
"Source Code": URL,
}
# =============================================================================
# HELPER FUNCTIONS
# =============================================================================
def read_file_content(file_path: Path, encoding: str = "utf-8") -> str:
"""
Read content from a file with proper error handling.
Args:
file_path: Path to the file to read
encoding: File encoding (default: utf-8)
Returns:
Content of the file as string, empty string if file doesn't exist
Raises:
SystemExit: If critical file reading error occurs
"""
try:
if not file_path.exists():
logger.warning(f"File not found: {file_path}")
return ""
with open(file_path, encoding=encoding) as file:
content = file.read()
logger.info(f"Successfully read {file_path}")
return content
except PermissionError as e:
logger.error(f"Permission denied reading {file_path}: {str(e)}", exc_info=True)
return ""
except UnicodeDecodeError as e:
logger.error(f"Encoding error reading {file_path}: {str(e)}", exc_info=True)
return ""
except Exception as e:
logger.error(f"Unexpected error reading {file_path}: {str(e)}", exc_info=True)
sys.exit(1)
def get_requirements(requirements_path: Path) -> List[str]:
"""
Parse requirements from requirements.txt file.
Args:
requirements_path: Path to requirements.txt file
Returns:
List of requirement strings, excluding comments and empty lines
Notes:
- Filters out empty lines and comments (lines starting with #)
- Strips whitespace from each requirement
- Returns empty list if file doesn't exist
"""
requirements: List[str] = []
try:
content = read_file_content(requirements_path)
if not content:
logger.warning("No requirements.txt found or file is empty")
return requirements
# Parse requirements line by line
for line_num, line in enumerate(content.splitlines(), 1):
line = line.strip()
# Skip empty lines and comments
if line and not line.startswith("#"):
requirements.append(line)
logger.debug(f"Added requirement from line {line_num}: {line}")
logger.info(f"Loaded {len(requirements)} requirements")
return requirements
except Exception as e:
logger.error(f"Error parsing requirements: {str(e)}", exc_info=True)
return []
def get_long_description(readme_path: Path) -> str:
"""
Read and return the long description from README file.
Args:
readme_path: Path to README.md file
Returns:
Content of README file or default description if not found
"""
long_description = read_file_content(readme_path)
if not long_description:
logger.warning("README.md not found, using default description")
return DESCRIPTION
return long_description
def find_packages_config() -> List[str]:
"""
Configure package discovery with proper includes.
Returns:
List of packages to include in distribution
Notes:
Includes main package and all submodules explicitly
"""
# Define packages to include
include_patterns = [
PACKAGE_NAME,
f"{PACKAGE_NAME}.*",
"model",
"model.*",
"modules",
"modules.*",
"utils",
"utils.*"
]
try:
packages = find_packages(include=include_patterns)
logger.info(f"Found {len(packages)} packages: {', '.join(packages[:5])}...")
return packages
except Exception as e:
logger.error(f"Error finding packages: {str(e)}", exc_info=True)
# Fallback to minimal package list
return [PACKAGE_NAME]
def get_package_data() -> Dict[str, List[str]]:
"""
Define package data files to include.
Returns:
Dictionary mapping package names to data file patterns
"""
return {
PACKAGE_NAME: ["data/*.yml"],
}
def get_entry_points() -> Dict[str, List[str]]:
"""
Define console script entry points.
Returns:
Dictionary of entry point configurations
Notes:
Currently empty but structured for future CLI commands
"""
return {
"console_scripts": [
# Future CLI commands will be added here
# Example: "waveverify=waveverify.cli:main"
],
}
# =============================================================================
# MAIN SETUP CONFIGURATION
# =============================================================================
def main() -> None:
"""
Execute the setup configuration for WaveVerify package.
This function orchestrates the entire setup process, including:
- Loading requirements and documentation
- Configuring package discovery
- Setting up metadata and classifiers
- Handling any setup errors gracefully
"""
try:
logger.info(f"Starting setup for {PACKAGE_NAME} v{VERSION}")
# Load dynamic content
requirements = get_requirements(REQUIREMENTS_PATH)
long_description = get_long_description(README_PATH)
packages = find_packages_config()
# Execute setup
setup(
# Basic metadata
name=PACKAGE_NAME,
version=VERSION,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
description=DESCRIPTION,
long_description=long_description,
long_description_content_type="text/markdown",
license=LICENSE,
# URLs
url=URL,
project_urls=PROJECT_URLS,
# Classification
classifiers=CLASSIFIERS,
keywords=" ".join(KEYWORDS),
# Package configuration
packages=packages,
include_package_data=True,
package_data=get_package_data(),
# Dependencies
install_requires=requirements,
python_requires=PYTHON_REQUIRES,
# Entry points
entry_points=get_entry_points(),
)
logger.info(f"Setup completed successfully for {PACKAGE_NAME} v{VERSION}")
except Exception as e:
logger.error(f"Setup failed: {str(e)}", exc_info=True)
sys.exit(1)
# =============================================================================
# ENTRY POINT
# =============================================================================
if __name__ == "__main__":
main()