Skip to content

Commit

Permalink
Merge pull request #65 from martinRenou/improve_setup
Browse files Browse the repository at this point in the history
Improve setup.py file
  • Loading branch information
martinRenou committed Jul 15, 2020
2 parents 5585960 + ac88e9f commit a379dc8
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions {{cookiecutter.github_project_name}}/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@
import os
import sys
import platform
from distutils import log

here = os.path.dirname(os.path.abspath(__file__))
node_root = os.path.join(here, 'js')
is_repo = os.path.exists(os.path.join(here, '.git'))

npm_path = os.pathsep.join([
os.path.join(node_root, 'node_modules', '.bin'),
os.environ.get('PATH', os.defpath),
os.environ.get('PATH', os.defpath),
])

from distutils import log
log.set_verbosity(log.DEBUG)
log.info('setup.py entered')
log.info('$PATH=%s' % os.environ['PATH'])

name = '{{ cookiecutter.python_package_name }}'
LONG_DESCRIPTION = '{{ cookiecutter.project_short_description }}'


def js_prerelease(command, strict=False):
"""decorator for building minified js/css prior to another command"""
"""Decorator for building minified js/css prior to another command."""
class DecoratedCommand(command):
def run(self):
jsdeps = self.distribution.get_command_obj('jsdeps')
Expand All @@ -50,8 +52,9 @@ def run(self):
update_package_data(self.distribution)
return DecoratedCommand


def update_package_data(distribution):
"""update package_data to catch changes during setup"""
"""Update package_data to catch changes during setup."""
build_py = distribution.get_command_obj('build_py')
# distribution.package_data = find_package_data()
# re-init build_py options which load package_data
Expand All @@ -77,23 +80,21 @@ def finalize_options(self):
pass

def get_npm_name(self):
npmName = 'npm';
npm_name = 'npm';
if platform.system() == 'Windows':
npmName = 'npm.cmd';
return npmName;
npm_name = 'npm.cmd';

return npm_name;

def has_npm(self):
npmName = self.get_npm_name();
npm_name = self.get_npm_name();
try:
check_call([npmName, '--version'])
check_call([npm_name, '--version'])
return True
except:
return False

def should_run_npm_install(self):
package_json = os.path.join(node_root, 'package.json')
node_modules_exists = os.path.exists(self.node_modules)
return self.has_npm()

def run(self):
Expand All @@ -106,8 +107,8 @@ def run(self):

if self.should_run_npm_install():
log.info("Installing build dependencies with npm. This may take a while...")
npmName = self.get_npm_name();
check_call([npmName, 'install'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr)
npm_name = self.get_npm_name();
check_call([npm_name, 'install'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr)
os.utime(self.node_modules, None)

for t in self.targets:
Expand All @@ -124,41 +125,40 @@ def run(self):
with open(os.path.join(here, '{{ cookiecutter.python_package_name }}', '_version.py')) as f:
exec(f.read(), {}, version_ns)

setup_args = {
'name': '{{ cookiecutter.python_package_name }}',
'version': version_ns['__version__'],
'description': '{{ cookiecutter.project_short_description }}',
'long_description': LONG_DESCRIPTION,
'include_package_data': True,
'data_files': [
setup_args = dict(
name=name,
version=version_ns['__version__'],
description='{{ cookiecutter.project_short_description }}',
long_description=LONG_DESCRIPTION,
include_package_data=True,
data_files=[
('share/jupyter/nbextensions/{{ cookiecutter.npm_package_name }}', [
'{{ cookiecutter.python_package_name }}/static/extension.js',
'{{ cookiecutter.python_package_name }}/static/index.js',
'{{ cookiecutter.python_package_name }}/static/index.js.map',
],),
('etc/jupyter/nbconfig/notebook.d' ,['{{ cookiecutter.npm_package_name }}.json'])
],
'install_requires': [
install_requires=[
'ipywidgets>=7.0.0',
],
'packages': find_packages(),
'zip_safe': False,
'cmdclass': {
packages=find_packages(),
zip_safe=False,
cmdclass={
'build_py': js_prerelease(build_py),
'egg_info': js_prerelease(egg_info),
'sdist': js_prerelease(sdist, strict=True),
'jsdeps': NPM,
},

'author': '{{ cookiecutter.author_name }}',
'author_email': '{{ cookiecutter.author_email }}',
'url': 'https://github.com/{{ cookiecutter.github_organization_name }}/{{ cookiecutter.github_project_name }}',
'keywords': [
author='{{ cookiecutter.author_name }}',
author_email='{{ cookiecutter.author_email }}',
url='https://github.com/{{ cookiecutter.github_organization_name }}/{{ cookiecutter.github_project_name }}',
keywords=[
'ipython',
'jupyter',
'widgets',
],
'classifiers': [
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: IPython',
'Intended Audience :: Developers',
Expand All @@ -173,6 +173,6 @@ def run(self):
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
}
)

setup(**setup_args)

0 comments on commit a379dc8

Please sign in to comment.