<commit_before>#!/usr/bin/python

import os
import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand

def read(fname):
    """read file from same path as setup.py"""
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

class Tox(TestCommand):
    """proxy class that enables tox to be run with setup.py test"""
    user_options = [('tox-args=', 'a', "Arguments to pass to tox")]

    def initialize_options(self):
        """initialize the user-options"""
        TestCommand.initialize_options(self)
        self.tox_args = None

    def finalize_options(self):
        """finalize user-options"""
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        """run tox and pass on user-options"""
        # import here, cause outside the eggs aren't loaded
        import tox
        import shlex
        args = self.tox_args
        if args:
            args = shlex.split(self.tox_args)
        errno = tox.cmdline(args=args)
        sys.exit(errno)

setup(
    name='python-escpos',
    use_scm_version=True,
    url='https://github.com/python-escpos/python-escpos',
    download_url='https://github.com/python-escpos/python-escpos/archive/master.zip',
    description='Python library to manipulate ESC/POS Printers',
    bugtrack_url='https://github.com/python-escpos/python-escpos/issues',
    license='GNU GPL v3',
    long_description=read('README.rst'),
    author='Manuel F Martinez',
    author_email='manpaz@bashlinux.com',
    platforms=['linux'],
    packages=[
        'escpos',
    ],
    package_data={'': ['COPYING']},
    classifiers=[
        'Development Status :: 1 - Alpha',
        'License :: OSI Approved :: GNU GPL v3',
        'Operating System :: GNU/Linux',
        'Intended Audience :: Developers',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Topic :: System :: Peripherals',
        'Topic :: Software Development :: Libraries :: Python Modules',
    ],
    install_requires=[
        'pyusb',
        'Pillow>=2.0',
        'qrcode>=4.0',
        'pyserial',
        'six',
        'future',
    ],
    setup_requires=[
        'setuptools_scm',
    ],
    tests_require=['tox', 'nose'],
    cmdclass={'test': Tox},
)
<commit_msg>Replace future and ConfigParser with localconfig<commit_after>#!/usr/bin/python

import os
import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand

def read(fname):
    """read file from same path as setup.py"""
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

class Tox(TestCommand):
    """proxy class that enables tox to be run with setup.py test"""
    user_options = [('tox-args=', 'a', "Arguments to pass to tox")]

    def initialize_options(self):
        """initialize the user-options"""
        TestCommand.initialize_options(self)
        self.tox_args = None

    def finalize_options(self):
        """finalize user-options"""
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        """run tox and pass on user-options"""
        # import here, cause outside the eggs aren't loaded
        import tox
        import shlex
        args = self.tox_args
        if args:
            args = shlex.split(self.tox_args)
        errno = tox.cmdline(args=args)
        sys.exit(errno)

setup(
    name='python-escpos',
    use_scm_version=True,
    url='https://github.com/python-escpos/python-escpos',
    download_url='https://github.com/python-escpos/python-escpos/archive/master.zip',
    description='Python library to manipulate ESC/POS Printers',
    bugtrack_url='https://github.com/python-escpos/python-escpos/issues',
    license='GNU GPL v3',
    long_description=read('README.rst'),
    author='Manuel F Martinez',
    author_email='manpaz@bashlinux.com',
    platforms=['linux'],
    packages=[
        'escpos',
    ],
    package_data={'': ['COPYING']},
    classifiers=[
        'Development Status :: 1 - Alpha',
        'License :: OSI Approved :: GNU GPL v3',
        'Operating System :: GNU/Linux',
        'Intended Audience :: Developers',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Topic :: System :: Peripherals',
        'Topic :: Software Development :: Libraries :: Python Modules',
    ],
    install_requires=[
        'pyusb',
        'Pillow>=2.0',
        'qrcode>=4.0',
        'pyserial',
        'six',
        'appdirs',
        'localconfig',
    ],
    setup_requires=[
        'setuptools_scm',
    ],
    tests_require=['tox', 'nose'],
    cmdclass={'test': Tox},
)
<|endoftext|>


<commit_before>import os
from setuptools import setup, find_packages

LONG_DESCRIPTION = """
Mustache template engine for Django 1.8 and newer, with support for Django context processors.
"""

def parse_markdown_readme():
    """
    Convert README.md to RST via pandoc, and load into memory
    (fallback to LONG_DESCRIPTION on failure)
    """
    # Attempt to run pandoc on markdown file
    import subprocess
    try:
        subprocess.call(
            ['pandoc', '-t', 'rst', '-o', 'README.rst', 'README.md']
        )
    except OSError:
        return LONG_DESCRIPTION

    # Attempt to load output
    try:
        readme = open(os.path.join(
            os.path.dirname(__file__),
            'README.rst'
        ))
    except IOError:
        return LONG_DESCRIPTION
    return readme.read()

setup(
    name='django-mustache',
    version='1.0.0',
    author='S. Andrew Sheppard',
    author_email='andrew@wq.io',
    url='https://github.com/wq/django-mustache',
    license='MIT',
    packages=['django_mustache'],
    description=LONG_DESCRIPTION.strip(),
    long_description=parse_markdown_readme(),
    install_requires=[
        'Django>=1.8',
        'pystache',
    ],
    classifiers=[
        'Framework :: Django',
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'License :: OSI Approved :: MIT License',
        'Natural Language :: English',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Topic :: Text Processing :: Markup :: HTML',
    ],
    test_suite='tests',
    tests_require=[
        'djangorestframework'
    ],
)
<commit_msg>update version for dev<commit_after>import os
from setuptools import setup, find_packages

LONG_DESCRIPTION = """
Mustache template engine for Django 1.8 and newer, with support for Django context processors.
"""

def parse_markdown_readme():
    """
    Convert README.md to RST via pandoc, and load into memory
    (fallback to LONG_DESCRIPTION on failure)
    """
    # Attempt to run pandoc on markdown file
    import subprocess
    try:
        subprocess.call(
            ['pandoc', '-t', 'rst', '-o', 'README.rst', 'README.md']
        )
    except OSError:
        return LONG_DESCRIPTION

    # Attempt to load output
    try:
        readme = open(os.path.join(
            os.path.dirname(__file__),
            'README.rst'
        ))
    except IOError:
        return LONG_DESCRIPTION
    return readme.read()

setup(
    name='django-mustache',
    version='1.0.1-dev',
    author='S. Andrew Sheppard',
    author_email='andrew@wq.io',
    url='https://github.com/wq/django-mustache',
    license='MIT',
    packages=['django_mustache'],
    description=LONG_DESCRIPTION.strip(),
    long_description=parse_markdown_readme(),
    install_requires=[
        'Django>=1.8',
        'pystache',
    ],
    classifiers=[
        'Framework :: Django',
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'License :: OSI Approved :: MIT License',
        'Natural Language :: English',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Topic :: Text Processing :: Markup :: HTML',
    ],
    test_suite='tests',
    tests_require=[
        'djangorestframework'
    ],
)
<|endoftext|>


<commit_before>from setuptools import setup

with open('README.md') as desc:
    long_description = desc.read()
setup(name='beets-check',
      version='0.9.0-beta.2',
      description='beets plugin verifying file integrity with checksums',
      long_description=long_description,
      author='Thomas Scholtes',
      author_email='thomas-scholtes@gmx.de',
      url='http://www.github.com/geigerzaehler/beets-check',
      license='MIT',
      platforms='ALL',

      test_suite='test',

      packages=['beetsplug'],

      install_requires=[
          'beets>=1.3.4',
      ],

      classifiers=[
          'Topic :: Multimedia :: Sound/Audio',
          'Topic :: Multimedia :: Sound/Audio :: Players :: MP3',
          'License :: OSI Approved :: MIT License',
          'Environment :: Console',
          'Environment :: Web Environment',
          'Programming Language :: Python :: 2',
          'Programming Language :: Python :: 2.6',
          'Programming Language :: Python :: 2.7',
      ],
)
<commit_msg>Bump version<commit_after>from setuptools import setup

setup(
    name='beets-check',
    version='0.9.0-beta.3',
    description='beets plugin verifying file integrity with checksums',
    long_description=open('README.md').read(),
    author='Thomas Scholtes',
    author_email='thomas-scholtes@gmx.de',
    url='http://www.github.com/geigerzaehler/beets-check',
    license='MIT',
    platforms='ALL',

    test_suite='test',

    packages=['beetsplug'],

    install_requires=[
        'beets>=1.3.4',
    ],

    classifiers=[
        'Topic :: Multimedia :: Sound/Audio',
        'Topic :: Multimedia :: Sound/Audio :: Players :: MP3',
        'License :: OSI Approved :: MIT License',
        'Environment :: Console',
        'Environment :: Web Environment',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
    ],
)
<|endoftext|>


<commit_before># pyOCD debugger
# Copyright (c) 2012-2019 Arm Limited
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import os
from setuptools import setup, find_packages

open_args = { 'mode': 'r' }
if sys.version_info[0] > 2:
    # Python 3.x version requires explicitly setting the encoding.
    # Python 2.x version of open() doesn't support the encoding parameter.
    open_args['encoding'] = 'utf-8'

with open('README.md', **open_args) as f:
    readme = f.read()

setup(
    name="pyocd",
    use_scm_version={
        'local_scheme': 'dirty-tag',
        'write_to': 'pyocd/_version.py'
    },
    setup_requires=[
        'setuptools>=40.0',
        'setuptools_scm!=1.5.3,!=1.5.4',
        'setuptools_scm_git_archive',
        ],
    description="Cortex-M debugger for Python",
    long_description=readme,
    long_description_content_type='text/markdown',
    author="Chris Reed, Martin Kojtal, Russ Butler",
    author_email="chris.reed@arm.com, martin.kojtal@arm.com, russ.butler@arm.com",
    url='https://github.com/mbedmicro/pyOCD',
    license="Apache 2.0",
    # Allow installation on 2.7.9+, and 3.4+ even though we officially only support 3.6+.
    python_requires=">=2.7.9, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
    install_requires = [
        'cmsis-pack-manager>=0.2.7',
        'colorama',
        'enum34>=1.0,<2.0;python_version<"3.4"',
        'hidapi;platform_system=="Darwin"',
        'intelhex>=2.0,<3.0',
        'intervaltree>=3.0.2,<4.0',
        'prettytable',
        'pyelftools',
        'pyusb>=1.0.0b2,<2.0',
        'pywinusb>=0.4.0;platform_system=="Windows"',
        'pyyaml>=5.1,<6.0',
        'six>=1.0,<2.0',
        ],
    classifiers=[
        "Development Status :: 4 - Beta",
        "License :: OSI Approved :: Apache Software License",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Topic :: Software Development :: Debuggers",
        "Topic :: Software Development :: Embedded Systems",
    ],
    extras_require={
        'dissassembler': ['capstone'],
    },
    entry_points={
        'console_scripts': [
            'pyocd = pyocd.__main__:main',

            # Keep deprecated tools for compatibility.
            'pyocd-gdbserver = pyocd.tools.gdb_server:main',
            'pyocd-flashtool = pyocd.tools.flash_tool:main',
            'pyocd-tool = pyocd.tools.pyocd:main',
        ],
    },
    packages=find_packages(),
    include_package_data=True,  # include files from MANIFEST.in
    package_data={
        'pyocd': ['debug/svd/svd_data.zip'],
    },
    zip_safe=True,
    options={
        'bdist_wheel': {
            'universal': True,
        },
    },
)
<commit_msg>Add Python 3.8 to classifiers in setup.py.<commit_after># pyOCD debugger
# Copyright (c) 2012-2019 Arm Limited
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import os
from setuptools import setup, find_packages

open_args = { 'mode': 'r' }
if sys.version_info[0] > 2:
    # Python 3.x version requires explicitly setting the encoding.
    # Python 2.x version of open() doesn't support the encoding parameter.
    open_args['encoding'] = 'utf-8'

with open('README.md', **open_args) as f:
    readme = f.read()

setup(
    name="pyocd",
    use_scm_version={
        'local_scheme': 'dirty-tag',
        'write_to': 'pyocd/_version.py'
    },
    setup_requires=[
        'setuptools>=40.0',
        'setuptools_scm!=1.5.3,!=1.5.4',
        'setuptools_scm_git_archive',
        ],
    description="Cortex-M debugger for Python",
    long_description=readme,
    long_description_content_type='text/markdown',
    author="Chris Reed, Martin Kojtal, Russ Butler",
    author_email="chris.reed@arm.com, martin.kojtal@arm.com, russ.butler@arm.com",
    url='https://github.com/mbedmicro/pyOCD',
    license="Apache 2.0",
    # Allow installation on 2.7.9+, and 3.4+ even though we officially only support 3.6+.
    python_requires=">=2.7.9, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
    install_requires = [
        'cmsis-pack-manager>=0.2.7',
        'colorama',
        'enum34>=1.0,<2.0;python_version<"3.4"',
        'hidapi;platform_system=="Darwin"',
        'intelhex>=2.0,<3.0',
        'intervaltree>=3.0.2,<4.0',
        'prettytable',
        'pyelftools',
        'pyusb>=1.0.0b2,<2.0',
        'pywinusb>=0.4.0;platform_system=="Windows"',
        'pyyaml>=5.1,<6.0',
        'six>=1.0,<2.0',
        ],
    classifiers=[
        "Development Status :: 4 - Beta",
        "License :: OSI Approved :: Apache Software License",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Topic :: Software Development :: Debuggers",
        "Topic :: Software Development :: Embedded Systems",
    ],
    extras_require={
        'dissassembler': ['capstone'],
    },
    entry_points={
        'console_scripts': [
            'pyocd = pyocd.__main__:main',

            # Keep deprecated tools for compatibility.
            'pyocd-gdbserver = pyocd.tools.gdb_server:main',
            'pyocd-flashtool = pyocd.tools.flash_tool:main',
            'pyocd-tool = pyocd.tools.pyocd:main',
        ],
    },
    packages=find_packages(),
    include_package_data=True,  # include files from MANIFEST.in
    package_data={
        'pyocd': ['debug/svd/svd_data.zip'],
    },
    zip_safe=True,
    options={
        'bdist_wheel': {
            'universal': True,
        },
    },
)
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
try:
    from setuptools import setup, find_packages
except ImportError:
    from ez_setup import use_setuptools
    use_setuptools()
    from setuptools import setup, find_packages

REQUIRES = ['six']

with open('README.md') as description_input:
    LONG_DESCRIPTION = description_input.read()

setup(
    name='stoplight',
    version='1.3.0',
    description='Input validation framework for Python',
    long_description=LONG_DESCRIPTION,
    long_description_content_type='text/x-md',
    license='Apache License 2.0',
    url='https://pypi.org/project/stoplight/',
    platforms=['OS Independent'],
    project_urls={
        'Documentation': 'http://stoplight.readthedocs.io/en/latest/',
        'Source': 'https://github.com/painterjd/stoplight',
        'Tracker': 'https://github.com/painterjd/stoplight/issues',
    },
    author='Jamie Painter',
    author_email='jamie.painter@rackspace.com',
    install_requires=REQUIRES,
    test_suite='stoplight',
    zip_safe=False,
    include_package_data=True,
    packages=find_packages(exclude=['ez_setup']),
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Topic :: Security'
    ]
)
<commit_msg>Version Bump: 1.3.0 -> 1.4.0 for dev work<commit_after># -*- coding: utf-8 -*-
try:
    from setuptools import setup, find_packages
except ImportError:
    from ez_setup import use_setuptools
    use_setuptools()
    from setuptools import setup, find_packages

REQUIRES = ['six']

with open('README.md') as description_input:
    LONG_DESCRIPTION = description_input.read()

setup(
    name='stoplight',
    version='1.4.0',
    description='Input validation framework for Python',
    long_description=LONG_DESCRIPTION,
    long_description_content_type='text/x-md',
    license='Apache License 2.0',
    url='https://pypi.org/project/stoplight/',
    platforms=['OS Independent'],
    project_urls={
        'Documentation': 'http://stoplight.readthedocs.io/en/latest/',
        'Source': 'https://github.com/painterjd/stoplight',
        'Tracker': 'https://github.com/painterjd/stoplight/issues',
    },
    author='Jamie Painter',
    author_email='jamie.painter@rackspace.com',
    install_requires=REQUIRES,
    test_suite='stoplight',
    zip_safe=False,
    include_package_data=True,
    packages=find_packages(exclude=['ez_setup']),
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Topic :: Security'
    ]
)
<|endoftext|>


<commit_before>#!/usr/bin/env python
#
# -----------------------------------------------------------------------------
# Copyright (C) 2015 Daniel Standage <daniel.standage@gmail.com>
#
# This file is part of tag (http://github.com/standage/tag) and is licensed
# under the BSD 3-clause license: see LICENSE.
# -----------------------------------------------------------------------------

from setuptools import setup
import glob
import versioneer

d = 'Genome annotation data analysis and management implemented in pure Python'
setup(name='tag',
      version=versioneer.get_version(),
      cmdclass=versioneer.get_cmdclass(),
      description=d,
      url='http://tag.readthedocs.io',
      author='Daniel Standage',
      author_email='daniel.standage@gmail.com',
      license='BSD-3',
      packages=['tag', 'tag.cli'],
      entry_points={'console_scripts': ['tag = tag.__main__:main']}
      install_requires=['intervaltree'],
      classifiers=[
          'Development Status :: 4 - Beta',
          'Environment :: Console',
          'License :: OSI Approved :: BSD License',
          'Programming Language :: Python :: 2.7',
          'Programming Language :: Python :: 3.4',
          'Programming Language :: Python :: 3.5',
          'Topic :: Scientific/Engineering :: Bio-Informatics'
      ],
      zip_safe=True)
<commit_msg>Missing comma<commit_after>#!/usr/bin/env python
#
# -----------------------------------------------------------------------------
# Copyright (C) 2015 Daniel Standage <daniel.standage@gmail.com>
#
# This file is part of tag (http://github.com/standage/tag) and is licensed
# under the BSD 3-clause license: see LICENSE.
# -----------------------------------------------------------------------------

from setuptools import setup
import glob
import versioneer

d = 'Genome annotation data analysis and management implemented in pure Python'
setup(name='tag',
      version=versioneer.get_version(),
      cmdclass=versioneer.get_cmdclass(),
      description=d,
      url='http://tag.readthedocs.io',
      author='Daniel Standage',
      author_email='daniel.standage@gmail.com',
      license='BSD-3',
      packages=['tag', 'tag.cli'],
      entry_points={'console_scripts': ['tag = tag.__main__:main']},
      install_requires=['intervaltree'],
      classifiers=[
          'Development Status :: 4 - Beta',
          'Environment :: Console',
          'License :: OSI Approved :: BSD License',
          'Programming Language :: Python :: 2.7',
          'Programming Language :: Python :: 3.4',
          'Programming Language :: Python :: 3.5',
          'Topic :: Scientific/Engineering :: Bio-Informatics'
      ],
      zip_safe=True)
<|endoftext|>


<commit_before>#!/usr/bin/env python
import os

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

from linkedin import __version__

with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
    long_description = readme.read()

setup(name='py-linkedin',
      version=__version__,
      description = 'Python Interface for the LinkedIn API',
      long_description=long_description,
      classifiers=[
          'Development Status :: 5 - Production/Stable',
          'Environment :: Console',
          'Intended Audience :: Developers',
          'License :: OSI Approved :: MIT License',
          'Operating System :: OS Independent',
          'Programming Language :: Python :: 2.7',
          'Natural Language :: English',
      ],
      keywords='linkedin python',
      author='Ozgur Vatansever',
      author_email='ozgurvt@gmail.com',
      maintainer='Ozgur Vatansever',
      maintainer_email='ozgurvt@gmail.com',
      url='https://github.com/ozgur/python-linkedin/',
      license='MIT',
      packages=['linkedin'],
      zip_safe=False,
)
<commit_msg>setup.py fixes<commit_after>#!/usr/bin/env python
import os

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

from linkedin import __version__

with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
    long_description = readme.read()

setup(name='py-linkedin',
      version=__version__,
      description='Python Interface for the LinkedIn API',
      long_description=long_description,
      classifiers=[
          'Development Status :: 5 - Production/Stable',
          'Environment :: Console',
          'Intended Audience :: Developers',
          'License :: OSI Approved :: MIT License',
          'Operating System :: OS Independent',
          'Programming Language :: Python :: 2.7',
          'Natural Language :: English',
      ],
      keywords='linkedin python',
      author='Ozgur Vatansever',
      author_email='ozgurvt@gmail.com',
      maintainer='Ozgur Vatansever',
      maintainer_email='ozgurvt@gmail.com',
      url='http://ozgur.github.com/python-linkedin/',
      license='MIT',
      packages=['linkedin'],
      zip_safe=False,
)
<|endoftext|>


<commit_before>from setuptools import setup, find_packages

setup(
    name="pyfluka",
    version="prototype",
    packages=find_packages(),
    scripts=["pyfluka/pyfluka-exec.py",
             "pyfluka/pyfluka_merge.py"],

    # Project uses reStructuredText, so ensure that the docutils get
    # installed or upgraded on the target machine
    install_requires=['nose-exclude>=0.4.1',
                      'numpy>=1.0',
                      'matplotlib>=1.3.1',
                      'networkx>=1.11',
                      'PyYAML>=3.11',
                      'tabulate>=0.7.5',
                      'pint==0.6',
                      'yamlordereddictloader>=0.1.0',
                      'coveralls>=1.1',
                      'Cython>=0.2.0',
                      'kivy>=1.9.0'],
    package_data={
        '': ['*.p', 'test_data/*'],
    },

    # metadata for upload to PyPI
    author="Marcus Matthias Morgenstern",
    author_email="marcus.matthias.morgenstern@cern.ch",
    description="pyfluka package",
    license="MIT",
    keywords="FLUKA MC data analysis physics radiation protection",
    url="https://github.com/morgenst/pyfluka"
)<commit_msg>fix Cython version<commit_after>from setuptools import setup, find_packages

setup(
    name="pyfluka",
    version="prototype",
    packages=find_packages(),
    scripts=["pyfluka/pyfluka-exec.py",
             "pyfluka/pyfluka_merge.py"],

    # Project uses reStructuredText, so ensure that the docutils get
    # installed or upgraded on the target machine
    install_requires=['nose-exclude>=0.4.1',
                      'numpy>=1.0',
                      'matplotlib>=1.3.1',
                      'networkx>=1.11',
                      'PyYAML>=3.11',
                      'tabulate>=0.7.5',
                      'pint==0.6',
                      'yamlordereddictloader>=0.1.0',
                      'coveralls>=1.1',
                      'Cython>=0.20',
                      'kivy>=1.9.0'],
    package_data={
        '': ['*.p', 'test_data/*'],
    },

    # metadata for upload to PyPI
    author="Marcus Matthias Morgenstern",
    author_email="marcus.matthias.morgenstern@cern.ch",
    description="pyfluka package",
    license="MIT",
    keywords="FLUKA MC data analysis physics radiation protection",
    url="https://github.com/morgenst/pyfluka"
)<|endoftext|>


<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

setup(
    name = 'c2c.recipe.jarfile',
    version = '0.2',
    license = 'MIT License',

    author  = 'Frederic Junod',
    author_email = 'frederic.junod@camptocamp.com',
    url = 'http://github.com/camptocamp/c2c.recipe.jarfile',

    description = 'A buildout recipe to create or update jar archive file.',
    long_description = open('README.rst').read(),

    classifiers = [
        'Framework :: Buildout',
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Build Tools',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'License :: OSI Approved :: MIT License'
    ],

    install_requires = [],
    packages = find_packages(exclude=['ez_setup']),
    namespace_packages = ['c2c', 'c2c.recipe'],
    entry_points = {'zc.buildout' : ['default = c2c.recipe.jarfile.buildout:CreateUpdateJar']}
)
<commit_msg>version 0.3<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

setup(
    name = 'c2c.recipe.jarfile',
    version = '0.3',
    license = 'MIT License',

    author  = 'Frederic Junod',
    author_email = 'frederic.junod@camptocamp.com',
    url = 'http://github.com/camptocamp/c2c.recipe.jarfile',

    description = 'A buildout recipe to create or update jar archive file.',
    long_description = open('README.rst').read(),

    classifiers = [
        'Framework :: Buildout',
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Build Tools',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'License :: OSI Approved :: MIT License'
    ],

    install_requires = [],
    packages = find_packages(exclude=['ez_setup']),
    namespace_packages = ['c2c', 'c2c.recipe'],
    entry_points = {'zc.buildout' : ['default = c2c.recipe.jarfile.buildout:CreateUpdateJar']}
)
<|endoftext|>


<commit_before>#!/usr/bin/env python
#
# (C) Copyright 2012-2019 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
#

import io
import os

from setuptools import setup, find_packages

import ecmwfapi

def read(path):
    file_path = os.path.join(os.path.dirname(__file__), *path.split('/'))
    return io.open(file_path, encoding='utf-8').read()

setup(
    name="ecmwf-api-client",
    version=ecmwfapi.__version__,
    description=ecmwfapi.__doc__,
    long_description=read('README.md'),
    author="ECMWF",
    author_email="software.support@ecmwf.int",
    license='Apache License Version 2.0',
    url="https://github.com/ecmwf/ecmwf-api-client",

    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        "Programming Language :: Python :: 2",
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: Implementation :: CPython',
        'Programming Language :: Python :: Implementation :: PyPy',
        'Operating System :: OS Independent',
    ],

    packages=find_packages(),
    zip_safe=False,
)
<commit_msg>Expand ECMWF name and use single quotes for strings (sync with other setup.py)<commit_after>#!/usr/bin/env python
#
# (C) Copyright 2012-2019 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
#

import io
import os

from setuptools import setup, find_packages

import ecmwfapi

def read(path):
    file_path = os.path.join(os.path.dirname(__file__), *path.split('/'))
    return io.open(file_path, encoding='utf-8').read()

setup(
    name='ecmwf-api-client',
    version=ecmwfapi.__version__,
    description=ecmwfapi.__doc__,
    long_description=read('README.md'),
    author='European Centre for Medium-Range Weather Forecasts (ECMWF)',
    author_email='software.support@ecmwf.int',
    license='Apache License Version 2.0',
    url='https://github.com/ecmwf/ecmwf-api-client',
    packages=find_packages(),
    zip_safe=True,
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        "Programming Language :: Python :: 2",
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: Implementation :: CPython',
        'Programming Language :: Python :: Implementation :: PyPy',
        'Operating System :: OS Independent',
    ],
)
<|endoftext|>


<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""libvcs lives at <https://github.com/vcs-python/libvcs>."""
from setuptools import setup

about = {}
with open("libvcs/__about__.py") as fp:
    exec(fp.read(), about)

with open('requirements/base.txt') as f:
    install_reqs = [line for line in f.read().split('\n') if line]

with open('requirements/test.txt') as f:
    tests_reqs = [line for line in f.read().split('\n') if line]

readme = open('README.rst').read()
history = open('CHANGES').read().replace('.. :changelog:', '')

setup(
    name=about['__title__'],
    version=about['__version__'],
    url='http://github.com/vcs-python/libvcs/',
    download_url='https://pypi.python.org/pypi/libvcs',
    project_urls={
        'Documentation': about['__docs__'],
        'Code': about['__github__'],
        'Issue tracker': about['__tracker__'],
    },
    license=about['__license__'],
    author=about['__author__'],
    author_email=about['__email__'],
    description=about['__description__'],
    long_description=readme,
    include_package_data=True,
    install_requires=install_reqs,
    tests_require=tests_reqs,
    zip_safe=False,
    keywords=about['__title__'],
    packages=['libvcs'],
    classifiers=[
        'Development Status :: 4 - Beta',
        'License :: OSI Approved :: MIT License',
        'Environment :: Web Environment',
        'Intended Audience :: Developers',
        'Operating System :: POSIX',
        'Operating System :: MacOS :: MacOS X',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: Implementation :: PyPy',
        'Topic :: Utilities',
        'Topic :: System :: Shells',
    ],
)
<commit_msg>build: Remove setup.py<commit_after><|endoftext|>


<commit_before>#!/usr/bin/env python
from setuptools import setup, find_packages

tests_requires = [
    'ddt>=1.0.0'
]

dev_requires = [
    'Sphinx==1.2.2',
]

install_requires = [
    'pbr!=2.1.0',
    'iptools>=0.6.1',
    'nodeconductor>0.134.0',
    'python-ceilometerclient>=2.3.0',
    'python-cinderclient>=1.6.0,<2.0.0',
    'python-glanceclient>=2.0.0',
    'python-keystoneclient>=2.3.1',
    'python-neutronclient>=4.1.1',
    'python-novaclient>=3.3.0,<3.4.0',
]

setup(
    name='nodeconductor-openstack',
    version='0.23.2',
    author='OpenNode Team',
    author_email='info@opennodecloud.com',
    url='http://nodeconductor.com',
    description='NodeConductor plugin for managing OpenStack resources.',
    long_description=open('README.rst').read(),
    package_dir={'': 'src'},
    packages=find_packages('src', exclude=['*.tests', '*.tests.*', 'tests.*', 'tests']),
    install_requires=install_requires,
    zip_safe=False,
    extras_require={
        'dev': dev_requires,
        'tests': tests_requires,
    },
    entry_points={
        'nodeconductor_extensions': (
            'openstack = nodeconductor_openstack.openstack.extension:OpenStackExtension',
            'openstack_tenant = nodeconductor_openstack.openstack_tenant.extension:OpenStackTenantExtension',
        ),
    },
    include_package_data=True,
    classifiers=[
        'Framework :: Django',
        'Intended Audience :: Developers',
        'Intended Audience :: System Administrators',
        'Operating System :: OS Independent',
        'License :: OSI Approved :: MIT License',
    ],
)
<commit_msg>Add Babel dependency for osc-lib compatibility [WAL-698]<commit_after>#!/usr/bin/env python
from setuptools import setup, find_packages

tests_requires = [
    'ddt>=1.0.0'
]

dev_requires = [
    'Sphinx==1.2.2',
]

install_requires = [
    'pbr!=2.1.0',
    'Babel!=2.4.0,>=2.3.4',
    'iptools>=0.6.1',
    'nodeconductor>0.134.0',
    'python-ceilometerclient>=2.3.0',
    'python-cinderclient>=1.6.0,<2.0.0',
    'python-glanceclient>=2.0.0',
    'python-keystoneclient>=2.3.1',
    'python-neutronclient>=4.1.1',
    'python-novaclient>=3.3.0,<3.4.0',
]

setup(
    name='nodeconductor-openstack',
    version='0.23.2',
    author='OpenNode Team',
    author_email='info@opennodecloud.com',
    url='http://nodeconductor.com',
    description='NodeConductor plugin for managing OpenStack resources.',
    long_description=open('README.rst').read(),
    package_dir={'': 'src'},
    packages=find_packages('src', exclude=['*.tests', '*.tests.*', 'tests.*', 'tests']),
    install_requires=install_requires,
    zip_safe=False,
    extras_require={
        'dev': dev_requires,
        'tests': tests_requires,
    },
    entry_points={
        'nodeconductor_extensions': (
            'openstack = nodeconductor_openstack.openstack.extension:OpenStackExtension',
            'openstack_tenant = nodeconductor_openstack.openstack_tenant.extension:OpenStackTenantExtension',
        ),
    },
    include_package_data=True,
    classifiers=[
        'Framework :: Django',
        'Intended Audience :: Developers',
        'Intended Audience :: System Administrators',
        'Operating System :: OS Independent',
        'License :: OSI Approved :: MIT License',
    ],
)
<|endoftext|>


<commit_before># (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.

# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import getpass
import multiprocessing
import os
import socket
import sys

from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.executor.connection_info import ConnectionInformation
from ansible.executor.play_iterator import PlayIterator
from ansible.executor.process.worker import WorkerProcess
from ansible.executor.process.result import ResultProcess
from ansible.executor.stats import AggregateStats
from ansible.plugins import callback_loader, strategy_loader
from ansible.template import Templar

from ansible.utils.debug import debug

__all__ = ['TaskQueueManager']

class TaskQueueManager:

    '''
    This class handles the multiprocessing requirements of Ansible by
    creating a pool of worker forks, a result handler fork, and a
    manager object with shared datastructures/queues for coordinating
    work between all processes.

    The queue manager is responsible for loading the play strategy plugin,
    which dispatches the Play's tasks to hosts.
    '''

    def __init__(self, inventory, variable_manager, loader, display, options, passwords, stdout_callback=None):

        self._inventory        = inventory
        self._variable_manager = variable_manager
        self._loader           = loader
        self._display          = display
        self._options          = options
        self._stats            = AggregateStats()
        self.passwords         = passwords
        self._stdout_callback  = stdout_callback
        self._callback_plugins = []

        self.load_callbacks()

        # a special flag to help us exit cleanly
        self._terminated = False

        # this dictionary is used to keep track of notified handlers
        self._notified_handlers = dict()

        # dictionaries to keep track of failed/unreachable hosts
        self._failed_hosts      = dict()
        self._unreachable_hosts = dict()

        self._final_q = multiprocessing.Queue()

        # create the pool of worker threads, based on the number of forks specified
        try:
            fileno = sys.stdin.fileno()
        except ValueError:
            fileno = None

        self._workers = []
        for i in range(self._options.forks):
            main_q = multiprocessing.Queue()
            rslt_q = multiprocessing.Queue()

            prc = WorkerProcess(self, main_q, rslt_q, loader)
            prc.start()

            self._workers.append((prc, main_q, rslt_q))

        self._result_prc = ResultProcess(self._final_q, self._workers)
        self._result_prc.start()

    def _initialize_notified_handlers(self, handlers):
        '''
        Clears and initializes the shared notified handlers dict with entries
        for each handler in the play, which is an empty array that will contain
        inventory hostnames for those hosts triggering the handler.
        '''

        # Zero the dictionary first by removing any entries there.
        # Proxied dicts don't support iteritems, so we have to use keys()
        for key in self._notified_handlers.keys():
            del self._notified_handlers[key]

        # FIXME: there is a block compile helper for this...
        handler_list = []
        for handler_block in handlers:
            for handler in handler_block.block:
                handler_list.append(handler)

        # then initialize it with the handler names from the handler list
        for handler in handler_list:
            self._notified_handlers[handler.get_name()] = []

    def load_callbacks(self):
        '''
        Loads all available callbacks, with the exception of those which
        utilize the CALLBACK_TYPE option. When CALLBACK_TYPE is set to 'stdout',
        only one such callback plugin will be loaded.
        '''

        stdout_callback_loaded = False
        if self._stdout_callback is None:
            self._stdout_callback = C.DEFAULT_STDOUT_CALLBACK

        if self._stdout_callback not in callback_loader:
            raise AnsibleError("Invalid callback for stdout specified: %s" % self._stdout_callback)

        for callback_plugin in callback_loader.all(class_only=True):
            if hasattr(callback_plugin, 'CALLBACK_VERSION') and callback_plugin.CALLBACK_VERSION >= 2.0:
                # we only allow one callback of type 'stdout' to be loaded, so check
                # the name of the current plugin and type to see if we need to skip
                # loading this callback plugin
                callback_type = getattr(callback_plugin, 'CALLBACK_TYPE', None)
                (callback_name, _) = os.path.splitext(os.path.basename(callback_plugin._original_path))
                if callback_type == 'stdout':
                    if callback_name != self._stdout_callback or stdout_callback_loaded:
                        continue
                    stdout_callback_loaded = True
                elif C.DEFAULT_CALLBACK_WHITELIST is None or callback_name not in C.DEFAULT_CALLBACK_WHITELIST:
                    continue

                self._callback_plugins.append(callback_plugin(self._display))
            else:
                self._callback_plugins.append(callback_plugin())

    def _do_var_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):

        if prompt and default is not None:
            msg = "%s [%s]: " % (prompt, default)
        elif prompt:
            msg = "%s: " % prompt
        else:
            msg = 'input for %s: ' % varname

        def do_prompt(prompt, private):
            if sys.stdout.encoding:
                msg = prompt.encode(sys.stdout.encoding)
            else:
                # when piping the output, or at other times when stdout
                # may not be the standard file descriptor, the stdout
                # encoding may not be set, so default to something sane
                msg = prompt.encode(locale.getpreferredencoding())
            if private:
                return getpass.getpass(msg)
            return raw_input(msg)

        if confirm:
            while True:
                result = do_prompt(msg, private)
                second = do_prompt("confirm " + msg, private)
                if result == second:
                    break
                display("***** VALUES ENTERED DO NOT MATCH ****")
        else:
            result = do_prompt(msg, private)

        # if result is false and default is not None
        if not result and default is not None:
            result = default

        # FIXME: make this work with vault or whatever this old method was
        #if encrypt:
        #    result = utils.do_encrypt(result, encrypt, salt_size, salt)

        # handle utf-8 chars
        # FIXME: make this work
        #result = to_unicode(result, errors='strict')
        return result

    def run(self, play):
        '''
        Iterates over the roles/tasks in a play, using the given (or default)
        strategy for queueing tasks. The default is the linear strategy, which
        operates like classic Ansible by keeping all hosts in lock-step with
        a given task (meaning no hosts move on to the next task until all hosts
        are done with the current task).
        '''

        if play.vars_prompt:
            for var in play.vars_prompt:
                if 'name' not in var:
                    raise AnsibleError("'vars_prompt' item is missing 'name:'", obj=play._ds)

                vname     = var['name']
                prompt    = var.get("prompt", vname)
                default   = var.get("default", None)
                private   = var.get("private", True)

                confirm   = var.get("confirm", False)
                encrypt   = var.get("encrypt", None)
                salt_size = var.get("salt_size", None)
                salt      = var.get("salt", None)

                if vname not in play.vars:
                    self.send_callback('v2_playbook_on_vars_prompt', vname, private, prompt, encrypt, confirm, salt_size, salt, default)
                    play.vars[vname] = self._do_var_prompt(vname, private, prompt, encrypt, confirm, salt_size, salt, default)

        all_vars = self._variable_manager.get_vars(loader=self._loader, play=play)
        templar = Templar(loader=self._loader, variables=all_vars)

        new_play = play.copy()
        new_play.post_validate(templar)

        connection_info = ConnectionInformation(new_play, self._options, self.passwords)
        for callback_plugin in self._callback_plugins:
            if hasattr(callback_plugin, 'set_connection_info'):
                callback_plugin.set_connection_info(connection_info)

        self.send_callback('v2_playbook_on_play_start', new_play)

        # initialize the shared dictionary containing the notified handlers
        self._initialize_notified_handlers(new_play.handlers)

        # load the specified strategy (or the default linear one)
        strategy = strategy_loader.get(new_play.strategy, self)
        if strategy is None:
            raise AnsibleError("Invalid play strategy specified: %s" % new_play.strategy, obj=play._ds)

        # build the iterator
        iterator = PlayIterator(inventory=self._inventory, play=new_play, connection_info=connection_info, all_vars=all_vars)

        # and run the play using the strategy
        return strategy.run(iterator, connection_info)

    def cleanup(self):
        debug("RUNNING CLEANUP")

        self.terminate()

        self._final_q.close()
        self._result_prc.terminate()

        for (worker_prc, main_q, rslt_q) in self._workers:
            rslt_q.close()
            main_q.close()
            worker_prc.terminate()

    def get_inventory(self):
        return self._inventory

    def get_variable_manager(self):
        return self._variable_manager

    def get_loader(self):
        return self._loader

    def get_notified_handlers(self):
        return self._notified_handlers

    def get_workers(self):
        return self._workers[:]

    def terminate(self):
        self._terminated = True

    def send_callback(self, method_name, *args, **kwargs):
        for callback_plugin in self._callback_plugins:
            # a plugin that set self.disabled to True will not be called
            # see osx_say.py example for such a plugin
            if getattr(callback_plugin, 'disabled', False):
                continue
            methods = [
                getattr(callback_plugin, method_name, None),
                getattr(callback_plugin, 'on_any', None)
            ]
            for method in methods:
                if method is not None:
                    method(*args, **kwargs)

<commit_msg>Revert "load callbacks on init again as they did not seem to load with new call from executor"<commit_after># (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.

# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import getpass
import multiprocessing
import os
import socket
import sys

from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.executor.connection_info import ConnectionInformation
from ansible.executor.play_iterator import PlayIterator
from ansible.executor.process.worker import WorkerProcess
from ansible.executor.process.result import ResultProcess
from ansible.executor.stats import AggregateStats
from ansible.plugins import callback_loader, strategy_loader
from ansible.template import Templar

from ansible.utils.debug import debug

__all__ = ['TaskQueueManager']

class TaskQueueManager:

    '''
    This class handles the multiprocessing requirements of Ansible by
    creating a pool of worker forks, a result handler fork, and a
    manager object with shared datastructures/queues for coordinating
    work between all processes.

    The queue manager is responsible for loading the play strategy plugin,
    which dispatches the Play's tasks to hosts.
    '''

    def __init__(self, inventory, variable_manager, loader, display, options, passwords, stdout_callback=None):

        self._inventory        = inventory
        self._variable_manager = variable_manager
        self._loader           = loader
        self._display          = display
        self._options          = options
        self._stats            = AggregateStats()
        self.passwords         = passwords
        self._stdout_callback  = stdout_callback
        self._callback_plugins = []

        # a special flag to help us exit cleanly
        self._terminated = False

        # this dictionary is used to keep track of notified handlers
        self._notified_handlers = dict()

        # dictionaries to keep track of failed/unreachable hosts
        self._failed_hosts      = dict()
        self._unreachable_hosts = dict()

        self._final_q = multiprocessing.Queue()

        # create the pool of worker threads, based on the number of forks specified
        try:
            fileno = sys.stdin.fileno()
        except ValueError:
            fileno = None

        self._workers = []
        for i in range(self._options.forks):
            main_q = multiprocessing.Queue()
            rslt_q = multiprocessing.Queue()

            prc = WorkerProcess(self, main_q, rslt_q, loader)
            prc.start()

            self._workers.append((prc, main_q, rslt_q))

        self._result_prc = ResultProcess(self._final_q, self._workers)
        self._result_prc.start()

    def _initialize_notified_handlers(self, handlers):
        '''
        Clears and initializes the shared notified handlers dict with entries
        for each handler in the play, which is an empty array that will contain
        inventory hostnames for those hosts triggering the handler.
        '''

        # Zero the dictionary first by removing any entries there.
        # Proxied dicts don't support iteritems, so we have to use keys()
        for key in self._notified_handlers.keys():
            del self._notified_handlers[key]

        # FIXME: there is a block compile helper for this...
        handler_list = []
        for handler_block in handlers:
            for handler in handler_block.block:
                handler_list.append(handler)

        # then initialize it with the handler names from the handler list
        for handler in handler_list:
            self._notified_handlers[handler.get_name()] = []

    def load_callbacks(self):
        '''
        Loads all available callbacks, with the exception of those which
        utilize the CALLBACK_TYPE option. When CALLBACK_TYPE is set to 'stdout',
        only one such callback plugin will be loaded.
        '''

        stdout_callback_loaded = False
        if self._stdout_callback is None:
            self._stdout_callback = C.DEFAULT_STDOUT_CALLBACK

        if self._stdout_callback not in callback_loader:
            raise AnsibleError("Invalid callback for stdout specified: %s" % self._stdout_callback)

        for callback_plugin in callback_loader.all(class_only=True):
            if hasattr(callback_plugin, 'CALLBACK_VERSION') and callback_plugin.CALLBACK_VERSION >= 2.0:
                # we only allow one callback of type 'stdout' to be loaded, so check
                # the name of the current plugin and type to see if we need to skip
                # loading this callback plugin
                callback_type = getattr(callback_plugin, 'CALLBACK_TYPE', None)
                (callback_name, _) = os.path.splitext(os.path.basename(callback_plugin._original_path))
                if callback_type == 'stdout':
                    if callback_name != self._stdout_callback or stdout_callback_loaded:
                        continue
                    stdout_callback_loaded = True
                elif C.DEFAULT_CALLBACK_WHITELIST is None or callback_name not in C.DEFAULT_CALLBACK_WHITELIST:
                    continue

                self._callback_plugins.append(callback_plugin(self._display))
            else:
                self._callback_plugins.append(callback_plugin())

    def _do_var_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):

        if prompt and default is not None:
            msg = "%s [%s]: " % (prompt, default)
        elif prompt:
            msg = "%s: " % prompt
        else:
            msg = 'input for %s: ' % varname

        def do_prompt(prompt, private):
            if sys.stdout.encoding:
                msg = prompt.encode(sys.stdout.encoding)
            else:
                # when piping the output, or at other times when stdout
                # may not be the standard file descriptor, the stdout
                # encoding may not be set, so default to something sane
                msg = prompt.encode(locale.getpreferredencoding())
            if private:
                return getpass.getpass(msg)
            return raw_input(msg)

        if confirm:
            while True:
                result = do_prompt(msg, private)
                second = do_prompt("confirm " + msg, private)
                if result == second:
                    break
                display("***** VALUES ENTERED DO NOT MATCH ****")
        else:
            result = do_prompt(msg, private)

        # if result is false and default is not None
        if not result and default is not None:
            result = default

        # FIXME: make this work with vault or whatever this old method was
        #if encrypt:
        #    result = utils.do_encrypt(result, encrypt, salt_size, salt)

        # handle utf-8 chars
        # FIXME: make this work
        #result = to_unicode(result, errors='strict')
        return result

    def run(self, play):
        '''
        Iterates over the roles/tasks in a play, using the given (or default)
        strategy for queueing tasks. The default is the linear strategy, which
        operates like classic Ansible by keeping all hosts in lock-step with
        a given task (meaning no hosts move on to the next task until all hosts
        are done with the current task).
        '''

        if play.vars_prompt:
            for var in play.vars_prompt:
                if 'name' not in var:
                    raise AnsibleError("'vars_prompt' item is missing 'name:'", obj=play._ds)

                vname     = var['name']
                prompt    = var.get("prompt", vname)
                default   = var.get("default", None)
                private   = var.get("private", True)

                confirm   = var.get("confirm", False)
                encrypt   = var.get("encrypt", None)
                salt_size = var.get("salt_size", None)
                salt      = var.get("salt", None)

                if vname not in play.vars:
                    self.send_callback('v2_playbook_on_vars_prompt', vname, private, prompt, encrypt, confirm, salt_size, salt, default)
                    play.vars[vname] = self._do_var_prompt(vname, private, prompt, encrypt, confirm, salt_size, salt, default)

        all_vars = self._variable_manager.get_vars(loader=self._loader, play=play)
        templar = Templar(loader=self._loader, variables=all_vars)

        new_play = play.copy()
        new_play.post_validate(templar)

        connection_info = ConnectionInformation(new_play, self._options, self.passwords)
        for callback_plugin in self._callback_plugins:
            if hasattr(callback_plugin, 'set_connection_info'):
                callback_plugin.set_connection_info(connection_info)

        self.send_callback('v2_playbook_on_play_start', new_play)

        # initialize the shared dictionary containing the notified handlers
        self._initialize_notified_handlers(new_play.handlers)

        # load the specified strategy (or the default linear one)
        strategy = strategy_loader.get(new_play.strategy, self)
        if strategy is None:
            raise AnsibleError("Invalid play strategy specified: %s" % new_play.strategy, obj=play._ds)

        # build the iterator
        iterator = PlayIterator(inventory=self._inventory, play=new_play, connection_info=connection_info, all_vars=all_vars)

        # and run the play using the strategy
        return strategy.run(iterator, connection_info)

    def cleanup(self):
        debug("RUNNING CLEANUP")

        self.terminate()

        self._final_q.close()
        self._result_prc.terminate()

        for (worker_prc, main_q, rslt_q) in self._workers:
            rslt_q.close()
            main_q.close()
            worker_prc.terminate()

    def get_inventory(self):
        return self._inventory

    def get_variable_manager(self):
        return self._variable_manager

    def get_loader(self):
        return self._loader

    def get_notified_handlers(self):
        return self._notified_handlers

    def get_workers(self):
        return self._workers[:]

    def terminate(self):
        self._terminated = True

    def send_callback(self, method_name, *args, **kwargs):
        for callback_plugin in self._callback_plugins:
            # a plugin that set self.disabled to True will not be called
            # see osx_say.py example for such a plugin
            if getattr(callback_plugin, 'disabled', False):
                continue
            methods = [
                getattr(callback_plugin, method_name, None),
                getattr(callback_plugin, 'on_any', None)
            ]
            for method in methods:
                if method is not None:
                    method(*args, **kwargs)

<|endoftext|>


<commit_before>import biokbase.narrative.clients as clients
from .specmanager import SpecManager
from biokbase.narrative.app_util import map_inputs_from_job, map_outputs_from_state
import json
import uuid
from jinja2 import Template
from pprint import pprint

"""
KBase job class
"""
__author__ = "Bill Riehl <wjriehl@lbl.gov>"

COMPLETED_STATUS = "completed"
TERMINAL_STATES = [COMPLETED_STATUS, "terminated", "error"]

EXCLUDED_JOB_STATE_FIELDS = [
    "authstrat",
    "condor_job_ads",
    "job_input",
    "scheduler_type",
    "scheduler_id",
]

EXTRA_JOB_STATE_FIELDS = ["batch_id", "cell_id", "run_id"]

JOB_DEFAULTS = {
    "app_id": None,
    "app_version": None,
    "batch_id": None,
    "batch_job": False,
    "child_jobs": [],
    "cell_id": None,
    "extra_data": None,
    "params": None,
    "owner": None,
    "run_id": None,
    "tag": "release",
}

ALL_JOB_ATTRS = list(JOB_DEFAULTS.keys())
ALL_JOB_ATTRS.append("job_id")

class Job(object):
    app_id = None
    app_version = None
    batch_id = None
    cell_id = None
    job_id = None
    params = None
    run_id = None
    _job_logs = list()
    _last_state = None

    def __init__(self, **kwargs):
        """
        Initializes a new Job with the attributes supplied in the kwargs.
        The app_id and app_version should both align with what's available in
        the Narrative Method Store service.
        """
        if kwargs.get("job_id", None) is None:
            raise ValueError("Cannot create a job without a job ID!")
        else:
            self.job_id = kwargs.get("job_id")

        # parent job: set the batch_id
        if kwargs.get("batch_job", False) is True:
            kwargs["batch_id"] = self.job_id

        for key, value in JOB_DEFAULTS.items():
            setattr(self, key, kwargs.get(key, value))

        ee2_state = kwargs.get("ee2_state", None)
        if not ee2_state:
            ee2_state = {
                "job_id": self.job_id,
            }
            # reconstruct the ee2 job state object
            for key in ["batch_id", "batch_job", "child_jobs", "owner"]:
                if key in kwargs:
                    ee2_state[key] = kwargs[key]

        self.update_state(ee2_state)

    @classmethod
    def from_state(cls, job_state):
        """
        Parameters:
        -----------
        job_state - dict
            the job information returned from ee2.check_job
        """
        job_input = job_state.get("job_input", {})
        narr_cell_info = job_input.get("narrative_cell_info", {})
        return cls(
            app_id=job_input.get("app_id", JOB_DEFAULTS["app_id"]),
            app_version=job_input.get("service_ver", JOB_DEFAULTS["app_version"]),
            batch_id=job_state.get("batch_id", JOB_DEFAULTS["batch_id"]),
            batch_job=job_state.get("batch_job", JOB_DEFAULTS["batch_job"]),
            cell_id=narr_cell_info.get("cell_id", JOB_DEFAULTS["cell_id"]),
            child_jobs=job_state.get("child_jobs", JOB_DEFAULTS["child_jobs"]),
            ee2_state=job_state,
            job_id=job_state.get("job_id"),
            owner=job_state.get("user", JOB_DEFAULTS["owner"]),
            params=job_input.get("params", JOB_DEFAULTS["params"]),
            run_id=narr_cell_info.get("run_id", JOB_DEFAULTS["run_id"]),
            tag=narr_cell_info.get("tag", JOB_DEFAULTS["tag"]),
        )

    # can be removed -- unused
    @classmethod
    def map_viewer_params(cls, job_state, job_inputs, app_id, app_tag):
        # get app spec.
        if job_state is None or job_state.get("status", "") != COMPLETED_STATUS:
            return None

        spec = SpecManager().get_spec(app_id, app_tag)
        (output_widget, widget_params) = map_outputs_from_state(
            job_state, map_inputs_from_job(job_inputs, spec), spec
        )
        return {"name": output_widget, "tag": app_tag, "params": widget_params}

    @property
    def final_state(self):
        if self.terminal_state is True:
            return self._last_state
        return None

    def info(self):
        spec = self.app_spec()
        print(f"App name (id): {spec['info']['name']} ({self.app_id})")
        print(f"Version: {spec['info']['ver']}")

        try:
            state = self.state()
            print(f"Status: {state['status']}")
            print("Inputs:\n------")
            pprint(self.params)
        except BaseException:
            print("Unable to retrieve current running state!")

    def app_spec(self):
        return SpecManager().get_spec(self.app_id, self.tag)

    def status(self):
        return self.state().get("status", "unknown")

    def parameters(self):
        """
        Returns the parameters used to start the job. Job tries to use its params field, but
        if that's None, then it makes a call to njs.

        If no exception is raised, this only returns the list of parameters, NOT the whole
        object fetched from ee2.get_job_params
        """
        if self.params is not None:
            return self.params
        else:
            try:
                self.params = clients.get("execution_engine2").get_job_params(
                    self.job_id
                )["params"]
                return self.params
            except Exception as e:
                raise Exception(
                    f"Unable to fetch parameters for job {self.job_id} - {e}"
                )

    def update_state(self, state=None):
        """
        given a state data structure (as emitted by ee2), update the stored state in the job object
        """
        if not state or state == {}:
            return

        if "job_id" in state and state["job_id"] != self.job_id:
            raise ValueError(
                f"Job ID mismatch in update_state: job ID: {self.job_id}; state ID: {state['job_id']}"
            )

        # TODO: add in a check for the case where this is a batch parent job
        # batch parent jobs with where all children have status "completed" are in a terminal state
        # otherwise, child jobs may be retried
        self.terminal_state = (
            True if state.get("status", "unknown") in TERMINAL_STATES else False
        )

        if self._last_state is None:
            self._last_state = state
        else:
            # TODO: implement batch job code updates here
            self._last_state.update(state)

        return self._last_state

    def reset_state(self):
        """
        reset the internal job state by removing the stored state and resetting self.terminal_state
        """
        self._last_state = None
        self.terminal_state = False

    def _augment_ee2_state(self, state):
        output_state = {key: value for key, value in state.items()}
        for field in EXCLUDED_JOB_STATE_FIELDS:
            if field in output_state:
                del output_state[field]
        if "job_output" not in output_state:
            output_state["job_output"] = {}
        for arg in EXTRA_JOB_STATE_FIELDS:
            output_state[arg] = getattr(self, arg)
        return dict(output_state)

    def state(self):
        """
        Queries the job service to see the status of the current job.
        Returns a <something> stating its status. (string? enum type? different traitlet?)
        """

        if self.terminal_state:
            return self._augment_ee2_state(self._last_state)

        try:
            state = clients.get("execution_engine2").check_job(
                {"job_id": self.job_id, "exclude_fields": EXCLUDED_JOB_STATE_FIELDS}
            )
            self.update_state(state)
            return self._augment_ee2_state(state)

        except Exception as e:
            raise Exception(f"Unable to fetch info for job {self.job_id} - {e}")

    def show_output_widget(self, state=None):
        """
        For a complete job, returns the job results.
        An incomplete job throws an exception
        """
        from biokbase.narrative.widgetmanager import WidgetManager

        if state is None:
            state = self.state()
        if state["status"] == COMPLETED_STATUS and "job_output" in state:
            (output_widget, widget_params) = self._get_output_info(state)
            return WidgetManager().show_output_widget(
                output_widget, widget_params, tag=self.tag
            )
        else:
            return f"Job is incomplete! It has status '{state['status']}'"

    def get_viewer_params(self, state):
        """
        Maps job state 'result' onto the inputs for a viewer.
        """
        if state is None or state["status"] != COMPLETED_STATUS:
            return None
        (output_widget, widget_params) = self._get_output_info(state)
        return {"name": output_widget, "tag": self.tag, "params": widget_params}

    def _get_output_info(self, state):
        spec = self.app_spec()
        return map_outputs_from_state(
            state, map_inputs_from_job(self.parameters(), spec), spec
        )

    def log(self, first_line=0, num_lines=None):
        """
        Fetch a list of Job logs from the Job Service.
        This returns a 2-tuple (number of available log lines, list of log lines)
        Each log 'line' is a dict with two properties:
        is_error - boolean
            True if the line reflects an error returned by the method (e.g. stdout)
        line - string
            The actual log line
        Parameters:
        -----------
        first_line - int
            First line of log to return (0-indexed). If < 0, starts at the beginning. If > total
            lines, returns an empty list.
        num_lines - int or None
            Limit on the number of lines to return (if None, return everything). If <= 0,
            returns no lines.
        Usage:
        ------
        The parameters are kwargs, so the following cases can be true:
        log() - returns all available log lines
        log(first_line=5) - returns every line available starting with line 5
        log(num_lines=100) - returns the first 100 lines (or all lines available if < 100)
        """
        self._update_log()
        num_available_lines = len(self._job_logs)

        if first_line < 0:
            first_line = 0
        if num_lines is None:
            num_lines = num_available_lines - first_line
        if num_lines < 0:
            num_lines = 0

        if first_line >= num_available_lines or num_lines <= 0:
            return (num_available_lines, list())
        return (
            num_available_lines,
            self._job_logs[first_line : first_line + num_lines],
        )

    def _update_log(self):
        log_update = clients.get("execution_engine2").get_job_logs(
            {"job_id": self.job_id, "skip_lines": len(self._job_logs)}
        )
        if log_update["lines"]:
            self._job_logs = self._job_logs + log_update["lines"]

    def is_finished(self):
        """
        Returns True if the job is finished (in any state, including errors or canceled),
        False if its running/queued.
        """
        status = self.status()
        return status.lower() in TERMINAL_STATES

    def __repr__(self):
        return "KBase Narrative Job - " + str(self.job_id)

    def _repr_javascript_(self):
        tmpl = """
        element.html("

");

        require(['jquery', 'kbaseNarrativeJobStatus'], function($, KBaseNarrativeJobStatus) {
            var w = new KBaseNarrativeJobStatus($('#{{elem_id}}'), {'jobId': '{{job_id}}', 'state': {{state}}, 'info': {{info}}, 'outputWidgetInfo': {{output_widget_info}}});
        });
        """
        output_widget_info = None
        try:
            state = self.state()
            spec = self.app_spec()
            if state.get("status", "") == COMPLETED_STATUS:
                (output_widget, widget_params) = self._get_output_info(state)
                output_widget_info = {"name": output_widget, "params": widget_params}

            info = {
                "app_id": spec["info"]["id"],
                "version": spec["info"].get("ver", None),
                "name": spec["info"]["name"],
            }
        except Exception:
            state = {}
            info = {"app_id": None, "version": None, "name": "Unknown App"}
        return Template(tmpl).render(
            job_id=self.job_id,
            elem_id=f"kb-job-{self.job_id}-{uuid.uuid4()}",
            state=json.dumps(state),
            info=json.dumps(info),
            output_widget_info=json.dumps(output_widget_info),
        )

    def dump(self):
        """
        Display job info without having to iterate through the attributes
        """

        return {attr: getattr(self, attr) for attr in [*ALL_JOB_ATTRS, "_last_state"]}
<commit_msg>Adding docs to job constructor; removing unneeded method<commit_after>import biokbase.narrative.clients as clients
from .specmanager import SpecManager
from biokbase.narrative.app_util import map_inputs_from_job, map_outputs_from_state
import json
import uuid
from jinja2 import Template
from pprint import pprint

"""
KBase job class
"""
__author__ = "Bill Riehl <wjriehl@lbl.gov>"

COMPLETED_STATUS = "completed"
TERMINAL_STATES = [COMPLETED_STATUS, "terminated", "error"]

EXCLUDED_JOB_STATE_FIELDS = [
    "authstrat",
    "condor_job_ads",
    "job_input",
    "scheduler_type",
    "scheduler_id",
]

EXTRA_JOB_STATE_FIELDS = ["batch_id", "cell_id", "run_id"]

JOB_DEFAULTS = {
    "app_id": None,
    "app_version": None,
    "batch_id": None,
    "batch_job": False,
    "child_jobs": [],
    "cell_id": None,
    "extra_data": None,
    "params": None,
    "owner": None,
    "run_id": None,
    "tag": "release",
}

ALL_JOB_ATTRS = list(JOB_DEFAULTS.keys())
ALL_JOB_ATTRS.append("job_id")

class Job(object):
    app_id = None
    app_version = None
    batch_id = None
    cell_id = None
    job_id = None
    params = None
    run_id = None
    _job_logs = list()
    _last_state = None

    def __init__(self, **kwargs):
        """
        Initializes a new Job with the attributes supplied in the kwargs.
        The app_id and app_version should both align with what's available in
        the Narrative Method Store service.

        required args:
        job_id (str): the ID of the job

        optional args:
        app_id (str): identifier for the app
        app_version (str): service version string
        batch_id (str): for batch jobs, the ID of the parent job
        batch_job (bool): whether or not this is a batch job
        child_jobs (list[str]): IDs of child jobs in a batch
        cell_id (str): ID of the cell that initiated the job (if applicable)
        extra_data (dict): currently only used by the legacy batch job interface;
            format:
                batch_app: ID of app being run,
                batch_tag: app tag
                batch_size: number of jobs being run
        params (dict): input parameters
        owner (str): the user who started the job
        run_id (str): unique run ID for the job
        tag (str): the application tag (dev/beta/release)

        """
        if kwargs.get("job_id", None) is None:
            raise ValueError("Cannot create a job without a job ID!")
        else:
            self.job_id = kwargs.get("job_id")

        # parent job: set the batch_id
        if kwargs.get("batch_job", False) is True:
            kwargs["batch_id"] = self.job_id

        for key, value in JOB_DEFAULTS.items():
            setattr(self, key, kwargs.get(key, value))

        ee2_state = kwargs.get("ee2_state", None)
        if not ee2_state:
            ee2_state = {
                "job_id": self.job_id,
            }
            # reconstruct the ee2 job state object
            for key in ["batch_id", "batch_job", "child_jobs", "owner"]:
                if key in kwargs:
                    ee2_state[key] = kwargs[key]

        self.update_state(ee2_state)

    @classmethod
    def from_state(cls, job_state):
        """
        Parameters:
        -----------
        job_state - dict
            the job information returned from ee2.check_job

        """
        job_input = job_state.get("job_input", {})
        narr_cell_info = job_input.get("narrative_cell_info", {})
        return cls(
            app_id=job_input.get("app_id", JOB_DEFAULTS["app_id"]),
            app_version=job_input.get("service_ver", JOB_DEFAULTS["app_version"]),
            batch_id=job_state.get("batch_id", JOB_DEFAULTS["batch_id"]),
            batch_job=job_state.get("batch_job", JOB_DEFAULTS["batch_job"]),
            cell_id=narr_cell_info.get("cell_id", JOB_DEFAULTS["cell_id"]),
            child_jobs=job_state.get("child_jobs", JOB_DEFAULTS["child_jobs"]),
            ee2_state=job_state,
            job_id=job_state.get("job_id"),
            owner=job_state.get("user", JOB_DEFAULTS["owner"]),
            params=job_input.get("params", JOB_DEFAULTS["params"]),
            run_id=narr_cell_info.get("run_id", JOB_DEFAULTS["run_id"]),
            tag=narr_cell_info.get("tag", JOB_DEFAULTS["tag"]),
        )

    @property
    def final_state(self):
        if self.terminal_state is True:
            return self._last_state
        return None

    def info(self):
        spec = self.app_spec()
        print(f"App name (id): {spec['info']['name']} ({self.app_id})")
        print(f"Version: {spec['info']['ver']}")

        try:
            state = self.state()
            print(f"Status: {state['status']}")
            print("Inputs:\n------")
            pprint(self.params)
        except BaseException:
            print("Unable to retrieve current running state!")

    def app_spec(self):
        return SpecManager().get_spec(self.app_id, self.tag)

    def status(self):
        return self.state().get("status", "unknown")

    def parameters(self):
        """
        Returns the parameters used to start the job. Job tries to use its params field, but
        if that's None, then it makes a call to njs.

        If no exception is raised, this only returns the list of parameters, NOT the whole
        object fetched from ee2.get_job_params
        """
        if self.params is not None:
            return self.params
        else:
            try:
                self.params = clients.get("execution_engine2").get_job_params(
                    self.job_id
                )["params"]
                return self.params
            except Exception as e:
                raise Exception(
                    f"Unable to fetch parameters for job {self.job_id} - {e}"
                )

    def update_state(self, state=None):
        """
        given a state data structure (as emitted by ee2), update the stored state in the job object
        """
        if not state or state == {}:
            return

        if "job_id" in state and state["job_id"] != self.job_id:
            raise ValueError(
                f"Job ID mismatch in update_state: job ID: {self.job_id}; state ID: {state['job_id']}"
            )

        # TODO: add in a check for the case where this is a batch parent job
        # batch parent jobs with where all children have status "completed" are in a terminal state
        # otherwise, child jobs may be retried
        self.terminal_state = (
            True if state.get("status", "unknown") in TERMINAL_STATES else False
        )

        if self._last_state is None:
            self._last_state = state
        else:
            # TODO: implement batch job code updates here
            self._last_state.update(state)

        return self._last_state

    def reset_state(self):
        """
        reset the internal job state by removing the stored state and resetting self.terminal_state
        """
        self._last_state = None
        self.terminal_state = False

    def _augment_ee2_state(self, state):
        output_state = {key: value for key, value in state.items()}
        for field in EXCLUDED_JOB_STATE_FIELDS:
            if field in output_state:
                del output_state[field]
        if "job_output" not in output_state:
            output_state["job_output"] = {}
        for arg in EXTRA_JOB_STATE_FIELDS:
            output_state[arg] = getattr(self, arg)
        return dict(output_state)

    def state(self):
        """
        Queries the job service to see the status of the current job.
        Returns a <something> stating its status. (string? enum type? different traitlet?)
        """

        if self.terminal_state:
            return self._augment_ee2_state(self._last_state)

        try:
            state = clients.get("execution_engine2").check_job(
                {"job_id": self.job_id, "exclude_fields": EXCLUDED_JOB_STATE_FIELDS}
            )
            self.update_state(state)
            return self._augment_ee2_state(state)

        except Exception as e:
            raise Exception(f"Unable to fetch info for job {self.job_id} - {e}")

    def show_output_widget(self, state=None):
        """
        For a complete job, returns the job results.
        An incomplete job throws an exception
        """
        from biokbase.narrative.widgetmanager import WidgetManager

        if state is None:
            state = self.state()
        if state["status"] == COMPLETED_STATUS and "job_output" in state:
            (output_widget, widget_params) = self._get_output_info(state)
            return WidgetManager().show_output_widget(
                output_widget, widget_params, tag=self.tag
            )
        else:
            return f"Job is incomplete! It has status '{state['status']}'"

    def get_viewer_params(self, state):
        """
        Maps job state 'result' onto the inputs for a viewer.
        """
        if state is None or state["status"] != COMPLETED_STATUS:
            return None
        (output_widget, widget_params) = self._get_output_info(state)
        return {"name": output_widget, "tag": self.tag, "params": widget_params}

    def _get_output_info(self, state):
        spec = self.app_spec()
        return map_outputs_from_state(
            state, map_inputs_from_job(self.parameters(), spec), spec
        )

    def log(self, first_line=0, num_lines=None):
        """
        Fetch a list of Job logs from the Job Service.
        This returns a 2-tuple (number of available log lines, list of log lines)
        Each log 'line' is a dict with two properties:
        is_error - boolean
            True if the line reflects an error returned by the method (e.g. stdout)
        line - string
            The actual log line
        Parameters:
        -----------
        first_line - int
            First line of log to return (0-indexed). If < 0, starts at the beginning. If > total
            lines, returns an empty list.
        num_lines - int or None
            Limit on the number of lines to return (if None, return everything). If <= 0,
            returns no lines.
        Usage:
        ------
        The parameters are kwargs, so the following cases can be true:
        log() - returns all available log lines
        log(first_line=5) - returns every line available starting with line 5
        log(num_lines=100) - returns the first 100 lines (or all lines available if < 100)
        """
        self._update_log()
        num_available_lines = len(self._job_logs)

        if first_line < 0:
            first_line = 0
        if num_lines is None:
            num_lines = num_available_lines - first_line
        if num_lines < 0:
            num_lines = 0

        if first_line >= num_available_lines or num_lines <= 0:
            return (num_available_lines, list())
        return (
            num_available_lines,
            self._job_logs[first_line : first_line + num_lines],
        )

    def _update_log(self):
        log_update = clients.get("execution_engine2").get_job_logs(
            {"job_id": self.job_id, "skip_lines": len(self._job_logs)}
        )
        if log_update["lines"]:
            self._job_logs = self._job_logs + log_update["lines"]

    def is_finished(self):
        """
        Returns True if the job is finished (in any state, including errors or canceled),
        False if its running/queued.
        """
        status = self.status()
        return status.lower() in TERMINAL_STATES

    def __repr__(self):
        return "KBase Narrative Job - " + str(self.job_id)

    def _repr_javascript_(self):
        tmpl = """
        element.html("

");

        require(['jquery', 'kbaseNarrativeJobStatus'], function($, KBaseNarrativeJobStatus) {
            var w = new KBaseNarrativeJobStatus($('#{{elem_id}}'), {'jobId': '{{job_id}}', 'state': {{state}}, 'info': {{info}}, 'outputWidgetInfo': {{output_widget_info}}});
        });
        """
        output_widget_info = None
        try:
            state = self.state()
            spec = self.app_spec()
            if state.get("status", "") == COMPLETED_STATUS:
                (output_widget, widget_params) = self._get_output_info(state)
                output_widget_info = {"name": output_widget, "params": widget_params}

            info = {
                "app_id": spec["info"]["id"],
                "version": spec["info"].get("ver", None),
                "name": spec["info"]["name"],
            }
        except Exception:
            state = {}
            info = {"app_id": None, "version": None, "name": "Unknown App"}
        return Template(tmpl).render(
            job_id=self.job_id,
            elem_id=f"kb-job-{self.job_id}-{uuid.uuid4()}",
            state=json.dumps(state),
            info=json.dumps(info),
            output_widget_info=json.dumps(output_widget_info),
        )

    def dump(self):
        """
        Display job info without having to iterate through the attributes
        """

        return {attr: getattr(self, attr) for attr in [*ALL_JOB_ATTRS, "_last_state"]}
<|endoftext|>


<commit_before>#!/usr/bin/env python

#from distutils.core import setup

from setuptools import setup, find_packages
import glob
import os

home = os.path.expanduser("~")

setup(
    name='cloudmesh',
    version=__import__('cloudmesh').version(),
    description='A tool to simplify managing multiple clouds including bare metal provisioning',
    # description-file =
    #    README.rst
    author='Cloudmesh Team',
    author_email='laszewski@gmail.com',
    url='http://github.org/cloudmesh/cloudmesh',
    classifiers=[
        'Intended Audience :: Developers',
        'Intended Audience :: Education',
        'Intended Audience :: Science/Research',
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Operating System :: POSIX :: Linux :: MacOS :: MacOS X',
        'Programming Language :: Python :: 2.7',
        'Topic :: Database',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Topic :: Scientific/Engineering',
        'Topic :: System :: Clustering',
        'Topic :: System :: Distributed Computing',
        'Topic :: System :: Boot',
        'Topic :: System :: Systems Administration',
        'Framework :: Flask',
        'Environment :: OpenStack',
    ],
    packages=find_packages(),
    include_package_data=True,
    data_files=[
        (home + '/.cloudmesh', [
            'etc/FGLdapCacert.pem',
            'etc/sierra-cacert.pem',
            'etc/cloudmesh_flavor.yaml']),
        (home + '/.cloudmesh/etc', [
            'etc/cloudmesh.yaml',
            'etc/me-none.yaml',
            'etc/cloudmesh.yaml',
            'etc/cloudmesh_server.yaml',
            'etc/cloudmesh_rack.yaml',
            'etc/cloudmesh_celery.yaml',
            'etc/cloudmesh_mac.yaml',
            'etc/cloudmesh_flavor.yaml',
            'etc/ipython_notebook_config.py']),
        (home + '/.cloudmesh/etc/racks/diag', glob.glob('etc/racks/*'))
    ],
    #               'cloudmesh/etc/racks/diag = etc/racks/*
    entry_points={'console_scripts': [
        'cm-manage = cloudmesh.config.cm_manage:main',
        'cm-iu = cloudmesh_install.futuregrid:main',
        'cm-init = cloudmesh.config.cm_init:main',
        'cm-image  = cloudmesh.image.cm_image:main',
        'cm-metric = cloudmesh.metric.cm_metric:main',
        'cm-rain = cloudmesh.rain.cobbler.cobbler_rain:main',
    ]},

)
<commit_msg>installing india openstack cacert<commit_after>#!/usr/bin/env python

#from distutils.core import setup

from setuptools import setup, find_packages
import glob
import os

home = os.path.expanduser("~")

setup(
    name='cloudmesh',
    version=__import__('cloudmesh').version(),
    description='A tool to simplify managing multiple clouds including bare metal provisioning',
    # description-file =
    #    README.rst
    author='Cloudmesh Team',
    author_email='laszewski@gmail.com',
    url='http://github.org/cloudmesh/cloudmesh',
    classifiers=[
        'Intended Audience :: Developers',
        'Intended Audience :: Education',
        'Intended Audience :: Science/Research',
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Apache Software License',
        'Operating System :: POSIX :: Linux :: MacOS :: MacOS X',
        'Programming Language :: Python :: 2.7',
        'Topic :: Database',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Topic :: Scientific/Engineering',
        'Topic :: System :: Clustering',
        'Topic :: System :: Distributed Computing',
        'Topic :: System :: Boot',
        'Topic :: System :: Systems Administration',
        'Framework :: Flask',
        'Environment :: OpenStack',
    ],
    packages=find_packages(),
    include_package_data=True,
    data_files=[
        (home + '/.cloudmesh', [
            'etc/FGLdapCacert.pem',
            'etc/sierra-cacert.pem',
            'etc/india-havana-cacert.pem',
            'etc/cloudmesh_flavor.yaml']),
        (home + '/.cloudmesh/etc', [
            'etc/cloudmesh.yaml',
            'etc/me-none.yaml',
            'etc/cloudmesh.yaml',
            'etc/cloudmesh_server.yaml',
            'etc/cloudmesh_rack.yaml',
            'etc/cloudmesh_celery.yaml',
            'etc/cloudmesh_mac.yaml',
            'etc/cloudmesh_flavor.yaml',
            'etc/ipython_notebook_config.py']),
        (home + '/.cloudmesh/etc/racks/diag', glob.glob('etc/racks/*'))
    ],
    #               'cloudmesh/etc/racks/diag = etc/racks/*
    entry_points={'console_scripts': [
        'cm-manage = cloudmesh.config.cm_manage:main',
        'cm-iu = cloudmesh_install.futuregrid:main',
        'cm-init = cloudmesh.config.cm_init:main',
        'cm-image  = cloudmesh.image.cm_image:main',
        'cm-metric = cloudmesh.metric.cm_metric:main',
        'cm-rain = cloudmesh.rain.cobbler.cobbler_rain:main',
    ]},

)
<|endoftext|>