-
Notifications
You must be signed in to change notification settings - Fork 134
/
setup.py
178 lines (151 loc) · 6.01 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
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
#!/usr/bin/env python3
import os
import tempfile
import tarfile
import shutil
import urllib.request
import urllib.error
from distutils import log
from setuptools import find_packages, setup, Command
from setuptools.command.build_py import build_py as _BuildPyCommand
from setuptools.command.sdist import sdist as _SDistCommand
package_name = os.environ.get("GALAXY_NG_ALTERNATE_NAME", "galaxy-ng")
version = "4.11.0dev"
class PrepareStaticCommand(Command):
DEV_UI_DOWNLOAD_URL = (
"https://github.com/ansible/ansible-hub-ui/"
"releases/download/dev/automation-hub-ui-dist.tar.gz"
)
ALTERNATE_UI_DOWNLOAD_URL = os.environ.get("ALTERNATE_UI_DOWNLOAD_URL")
UI_DOWNLOAD_URL = (
"https://github.com/ansible/ansible-hub-ui/"
f"releases/download/{version}/automation-hub-ui-dist.tar.gz"
)
TARGET_DIR = "galaxy_ng/app/static/galaxy_ng"
user_options = [
(
"force-download-ui",
None,
"Replace any existing static files with the ones downloaded from github.",
),
]
def initialize_options(self):
self.force_download_ui = False
def finalize_options(self):
pass
def run(self):
if os.path.exists(self.TARGET_DIR):
if self.force_download_ui:
log.warn(f"Removing {self.TARGET_DIR} and re downloading the UI.")
shutil.rmtree(self.TARGET_DIR)
else:
log.warn(f"Static directory {self.TARGET_DIR} already exists, skipping. ")
return
with tempfile.NamedTemporaryFile() as download_file:
log.info(f"Downloading UI distribution to temporary file: {download_file.name}")
if self.ALTERNATE_UI_DOWNLOAD_URL:
log.info(f"Downloading UI from {self.ALTERNATE_UI_DOWNLOAD_URL}")
self._download_tarball(self.ALTERNATE_UI_DOWNLOAD_URL, download_file)
else:
log.info(f"Attempting to download UI for version {version}")
try:
self._download_tarball(self.UI_DOWNLOAD_URL, download_file)
except urllib.error.HTTPError:
log.warn(f"Failed to retrieve UI for {version}. Downloading latest UI.")
self._download_tarball(self.DEV_UI_DOWNLOAD_URL, download_file)
log.info(f"Extracting UI static files to {self.TARGET_DIR}")
with tarfile.open(fileobj=download_file) as tfp:
tfp.extractall(self.TARGET_DIR)
def _download_tarball(self, url, download_file):
urllib.request.urlretrieve(url, filename=download_file.name)
class SDistCommand(_SDistCommand):
def run(self):
self.run_command("prepare_static")
return super().run()
class BuildPyCommand(_BuildPyCommand):
def run(self):
self.run_command("prepare_static")
return super().run()
django_ansible_base_branch = os.getenv('DJANGO_ANSIBLE_BASE_BRANCH', '2024.10.17')
django_ansible_base_dependency = (
'django-ansible-base[jwt_consumer] @ '
f'git+https://github.com/ansible/django-ansible-base@{django_ansible_base_branch}'
)
requirements = [
"galaxy-importer>=0.4.26,<0.5.0",
"pulpcore>=3.49.0,<3.50.0",
"pulp_ansible>=0.22.2,<0.23.0",
"pulp-container>=2.19.2,<2.20.0",
"django-prometheus>=2.0.0",
"social-auth-core>=4.4.2",
"social-auth-app-django>=5.2.0",
"django-auth-ldap==4.0.0",
"drf-spectacular",
"dynaconf>=3.2.6",
"insights_analytics_collector>=0.3.0",
"boto3",
"distro",
django_ansible_base_dependency, # noqa 501
"django-crum==0.7.9",
# From vendored automated_logging
"marshmallow<4.0.0,>=3.6.1",
"django-picklefield<4.0.0,>=3.0.1",
"django-ipware<4.0.0,>=3.0.0",
]
# https://softwareengineering.stackexchange.com/questions/223634/what-is-meant-by-now-you-have-two-problems
def strip_package_name(spec):
operators = ["=", ">", "<", "~", "!", "^", "@"]
for idc, char in enumerate(spec):
if char in operators:
return spec[:idc]
return spec
unpin_requirements = os.getenv("LOCK_REQUIREMENTS") == "0"
if unpin_requirements:
"""
To enable the installation of local dependencies e.g: a local fork of
pulp_ansible checked out to specific branch/version.
The paths listed on DEV_SOURCE_PATH must be unpinned to avoid pip
VersionConflict error.
ref: https://github.com/ansible/galaxy_ng/wiki/Development-Setup
#steps-to-run-dev-environment-with-specific-upstream-branch
"""
DEFAULT = "pulpcore:pulp_ansible:pulp_container:galaxy_importer:django-ansible-base"
DEV_SOURCE_PATH = os.getenv(
"DEV_SOURCE_PATH", default=DEFAULT
).split(":")
DEV_SOURCE_PATH += [path.replace("_", "-") for path in DEV_SOURCE_PATH]
requirements = [
strip_package_name(req) if req.lower().startswith(tuple(DEV_SOURCE_PATH)) else req
for req in requirements
]
print("Installing with unpinned DEV_SOURCE_PATH requirements", requirements)
setup(
name=package_name,
version=version,
description="galaxy-ng plugin for the Pulp Project",
long_description="galaxy-ng plugin for the Pulp Project",
license="GPLv2+",
author="Red Hat, Inc.",
author_email="[email protected]",
url="https://github.com/ansible/galaxy_ng/",
python_requires=">=3.9",
setup_requires=["wheel"],
install_requires=requirements,
include_package_data=True,
packages=find_packages(exclude=["tests", "tests.*"]),
classifiers=(
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Operating System :: POSIX :: Linux",
"Framework :: Django",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
),
entry_points={"pulpcore.plugin": ["galaxy_ng = galaxy_ng:default_app_config"]},
cmdclass={
"prepare_static": PrepareStaticCommand,
"build_py": BuildPyCommand,
"sdist": SDistCommand,
},
)