forked from ansible/galaxy_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
194 lines (164 loc) · 6.6 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/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.10.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()
# FIXME: this currently works for CI and dev env, but pip-tools misses dependencies when
# generating requirements.*.txt files. This needs to be fixed before use in the master branch.
def _format_pulp_requirement(plugin, specifier=None, ref=None, gh_namespace="pulp"):
"""
Formats the pulp plugin requirement.
The plugin template is VERY picky about the format we use for git refs. This will
help format git refs in a way that won't break CI when we need to pin to development
branches of pulp.
example:
_format_pulp_requirement("pulpcore", specifier=">=3.18.1,<3.19.0")
_format_pulp_requirement("pulpcore", ref="6e44fb2fe609f92dc1f502b19c67abd08879148f")
"""
if specifier:
return plugin + specifier
else:
repo = plugin.replace("-", "_")
return (
f"{plugin}@git+https://[email protected]/"
f"{gh_namespace}/{repo}.git@{ref}#egg={plugin}"
)
requirements = [
"galaxy-importer>=0.4.18,<0.5.0",
"pulpcore>=3.28.12,<3.29.0",
"pulp_ansible>=0.20.0,<0.21.0",
"django-prometheus>=2.0.0",
"drf-spectacular",
"pulp-container>=2.15.0,<2.16.0",
"social-auth-core>=4.4.2",
"social-auth-app-django>=5.2.0",
"dynaconf>=3.1.12,<3.1.13",
"django-auth-ldap==4.0.0",
"insights_analytics_collector>=0.3.0",
"boto3",
"distro",
# 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
# next line can be replaced via sed in ci scripts/post_before_install.sh
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
"""
DEV_SOURCE_PATH = os.getenv(
"DEV_SOURCE_PATH",
default="pulpcore:pulp_ansible:pulp_container:galaxy_importer"
).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",
license="GPLv2+",
author="Red Hat, Inc.",
author_email="[email protected]",
url="https://github.com/ansible/galaxy_ng/",
python_requires=">=3.8",
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,
},
)