Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup setup.py #3116

Merged
merged 7 commits into from
Sep 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 26 additions & 40 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,18 @@
"""
from __future__ import absolute_import

import sys
import datetime
import json
import logging
import os.path
import datetime
import sys
from subprocess import check_output

from distutils import log
from distutils.core import Command
from setuptools import Command
from setuptools import setup, find_packages
from setuptools.command.develop import develop
from setuptools.command.install import install
from setuptools.command.sdist import sdist
from setuptools import setup, find_packages
from subprocess import check_output

import pip
if tuple(map(int, pip.__version__.split('.'))) >= (19, 3, 0):
from pip._internal.network.session import PipSession
from pip._internal.req import parse_requirements

elif tuple(map(int, pip.__version__.split('.'))) >= (10, 0, 0):
from pip._internal.download import PipSession
from pip._internal.req import parse_requirements
else:
from pip.download import PipSession
from pip.req import parse_requirements

ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__)))

Expand All @@ -44,21 +32,18 @@
with open(os.path.join(ROOT, 'lemur', '__about__.py')) as f:
exec(f.read(), about) # nosec: about file is benign

install_requires_g = parse_requirements("requirements.txt", session=PipSession())
tests_require_g = parse_requirements("requirements-tests.txt", session=PipSession())
docs_require_g = parse_requirements("requirements-docs.txt", session=PipSession())
dev_requires_g = parse_requirements("requirements-dev.txt", session=PipSession())
# Parse requirements files
with open('requirements.txt') as f:
install_requirements = f.read().splitlines()

if tuple(map(int, pip.__version__.split('.'))) >= (20, 1):
install_requires = [str(ir.requirement) for ir in install_requires_g]
tests_require = [str(ir.requirement) for ir in tests_require_g]
docs_require = [str(ir.requirement) for ir in docs_require_g]
dev_requires = [str(ir.requirement) for ir in dev_requires_g]
else:
install_requires = [str(ir.req) for ir in install_requires_g]
tests_require = [str(ir.req) for ir in tests_require_g]
docs_require = [str(ir.req) for ir in docs_require_g]
dev_requires = [str(ir.req) for ir in dev_requires_g]
with open('requirements-tests.txt') as f:
tests_requirements = f.read().splitlines()

with open('requirements-docs.txt') as f:
docs_requirements = f.read().splitlines()

with open('requirements-dev.txt') as f:
dev_requirements = f.read().splitlines()


class SmartInstall(install):
Expand All @@ -67,6 +52,7 @@ class SmartInstall(install):
If the package indicator is missing, this will also force a run of
`build_static` which is required for JavaScript assets and other things.
"""

def _needs_static(self):
return not os.path.exists(os.path.join(ROOT, 'lemur/static/dist'))

Expand Down Expand Up @@ -105,16 +91,16 @@ def finalize_options(self):
pass

def run(self):
log.info("running [npm install --quiet] in {0}".format(ROOT))
logging.info("running [npm install --quiet] in {0}".format(ROOT))
try:
check_output(['npm', 'install', '--quiet'], cwd=ROOT)

log.info("running [gulp build]")
logging.info("running [gulp build]")
check_output([os.path.join(ROOT, 'node_modules', '.bin', 'gulp'), 'build'], cwd=ROOT)
log.info("running [gulp package]")
logging.info("running [gulp package]")
check_output([os.path.join(ROOT, 'node_modules', '.bin', 'gulp'), 'package'], cwd=ROOT)
except Exception as e:
log.warn("Unable to build static content")
logging.warn("Unable to build static content")


setup(
Expand All @@ -128,11 +114,11 @@ def run(self):
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=install_requires,
install_requires=install_requirements,
extras_require={
'tests': tests_require,
'docs': docs_require,
'dev': dev_requires,
'tests': tests_requirements,
'docs': docs_requirements,
'dev': dev_requirements,
},
cmdclass={
'build_static': BuildStatic,
Expand Down