Skip to content

Commit

Permalink
Refactor package build script
Browse files Browse the repository at this point in the history
* Download UI distribution to temporary file.
* Extract UI files to the build directory.
  • Loading branch information
cutwater committed Apr 22, 2020
1 parent 55a077b commit 0784ca5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

55 changes: 29 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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__,
Expand Down

0 comments on commit 0784ca5

Please sign in to comment.