From 0784ca5dbfb1f4f86240e53589e8424a59509f97 Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Wed, 22 Apr 2020 17:15:36 +0200 Subject: [PATCH] Refactor package build script * Download UI distribution to temporary file. * Extract UI files to the build directory. --- MANIFEST.in | 1 - setup.py | 55 ++++++++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 27 deletions(-) delete mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 0ebf8de3d1..0000000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -recursive-include galaxy_ng/app/static/galaxy_ng * diff --git a/setup.py b/setup.py index d077f2827e..9015243d55 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,39 @@ #!/usr/bin/env python3 -import setuptools.command.build_py +import os +import tempfile import tarfile import urllib.request +from distutils import log -from galaxy_ng import __version__ +from setuptools.command.build_py import build_py as _BuildPyCommand from setuptools import find_packages, setup +from galaxy_ng import __version__ + + +class BuildPyCommand(_BuildPyCommand): + """Custom build command.""" + + UI_DOWNLOAD_URL = ( + 'https://github.com/ansible/ansible-hub-ui/releases' + '/latest/download/automation-hub-ui-dist.tar.gz' + ) + + def run(self): + target_dir = os.path.join(self.build_lib, 'galaxy_ng/app/static/galaxy_ng') + + with tempfile.NamedTemporaryFile() as download_file: + log.info(f'Downloading UI distribution {download_file.name}') + urllib.request.urlretrieve(self.UI_DOWNLOAD_URL, filename=download_file.name) + + log.info(f'Extracting UI static files') + with tarfile.open(fileobj=download_file) as tfp: + tfp.extractall(target_dir) + + super().run() + + # NOTE(cutwater): Because bindings are statically generated, requirements list # from pulp-galaxy/setup.py has to be copied here and manually maintained. galaxy_pulp_requirements = [ @@ -24,30 +51,6 @@ "django-storages[boto3]", ] - -UI_DOWNLOAD_URL = 'https://github.com/ansible/ansible-hub-ui/' + \ - 'releases/latest/download/automation-hub-ui-dist.tar.gz' - - -class BuildPyCommand(setuptools.command.build_py.build_py): - """Custom build command.""" - - def run(self): - print('Downloading UI static files') - - filename, headers = urllib.request.urlretrieve( - UI_DOWNLOAD_URL, - 'automation-hub-ui-dist.tar.gz' - ) - - print('Extracting ' + filename) - tarfile.open(filename).extractall( - path='galaxy_ng/app/static/galaxy_ng' - ) - - setuptools.command.build_py.build_py.run(self) - - setup( name="galaxy-ng", version=__version__,