<commit_before># -*- coding: utf-8 -*-
"""install mythril and deploy source-dist and wheel to pypi.python.org.

deps (requires up2date version):
    *) pip install --upgrade pip wheel setuptools twine
publish to pypi w/o having to convert Readme.md to RST:
    1) #> python setup.py sdist bdist_wheel
    2) #> twine upload dist/*   #<specify bdist_wheel version to upload>; #optional --repository <testpypi> or  --repository-url <testpypi-url>
"""
from setuptools import setup, find_packages
from setuptools.command.install import install
from pathlib import Path
import sys
import os

# To make lint checkers happy we set VERSION here, but
# it is redefined by the exec below
VERSION = None

# Package version (vX.Y.Z). It must match git tag being used for CircleCI
# deployment; otherwise the build will failed.

version_path = (Path(__file__).parent / "mythril" / "version.py").absolute()
exec(open(str(version_path), "r").read())

class VerifyVersionCommand(install):
    """Custom command to verify that the git tag matches our version."""

    description = "verify that the git tag matches our version"

    def run(self):
        """"""
        tag = os.getenv("CIRCLE_TAG")

        if tag != VERSION:
            info = "Git tag: {0} does not match the version of this app: {1}".format(
                tag, VERSION
            )
            sys.exit(info)

def read_file(fname):
    """return file contents.

    :param fname: path relative to setup.py
    :return: file contents
    """
    with open(os.path.join(os.path.dirname(__file__), fname), "r") as fd:
        return fd.read()

setup(
    name="mythril",
    version=VERSION[1:],
    description="Security analysis tool for Ethereum smart contracts",
    long_description=read_file("README.md") if os.path.isfile("README.md") else "",
    long_description_content_type="text/markdown",  # requires twine and recent setuptools
    url="https://github.com/b-mueller/mythril",
    author="Bernhard Mueller",
    author_email="bernhard.mueller11@gmail.com",
    license="MIT",
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Science/Research",
        "Topic :: Software Development :: Disassemblers",
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
    ],
    keywords="hacking disassembler security ethereum",
    packages=find_packages(exclude=["contrib", "docs", "tests"]),
    install_requires=[
        "coloredlogs>=10.0",
        "py_ecc==1.4.2",
        "ethereum>=2.3.2",
        "z3-solver-mythril>=4.8.4.1",
        "requests",
        "py-solc",
        "plyvel",
        "eth_abi==1.3.0",
        "eth-utils>=1.0.1",
        "eth-account>=0.1.0a2",
        "eth-hash>=0.1.0",
        "eth-keyfile>=0.5.1",
        "eth-keys>=0.2.0b3",
        "eth-rlp>=0.1.0",
        "eth-tester==0.1.0b32",
        "eth-typing>=2.0.0",
        "coverage",
        "jinja2>=2.9",
        "rlp>=1.0.1",
        "transaction>=2.2.1",
        "py-flags",
        "mock",
        "configparser>=3.5.0",
        "persistent>=4.2.0",
        "ethereum-input-decoder>=0.2.2",
        "matplotlib"
    ],
    tests_require=["mypy", "pytest>=3.6.0", "pytest_mock", "pytest-cov"],
    python_requires=">=3.5",
    extras_require={},
    package_data={"mythril.analysis.templates": ["*"], "mythril.support.assets": ["*"]},
    include_package_data=True,
    entry_points={"console_scripts": ["myth=mythril.interfaces.cli:main"]},
    cmdclass={"verify": VerifyVersionCommand},
)
<commit_msg>remove dependency from setup<commit_after># -*- coding: utf-8 -*-
"""install mythril and deploy source-dist and wheel to pypi.python.org.

deps (requires up2date version):
    *) pip install --upgrade pip wheel setuptools twine
publish to pypi w/o having to convert Readme.md to RST:
    1) #> python setup.py sdist bdist_wheel
    2) #> twine upload dist/*   #<specify bdist_wheel version to upload>; #optional --repository <testpypi> or  --repository-url <testpypi-url>
"""
from setuptools import setup, find_packages
from setuptools.command.install import install
from pathlib import Path
import sys
import os

# To make lint checkers happy we set VERSION here, but
# it is redefined by the exec below
VERSION = None

# Package version (vX.Y.Z). It must match git tag being used for CircleCI
# deployment; otherwise the build will failed.

version_path = (Path(__file__).parent / "mythril" / "version.py").absolute()
exec(open(str(version_path), "r").read())

class VerifyVersionCommand(install):
    """Custom command to verify that the git tag matches our version."""

    description = "verify that the git tag matches our version"

    def run(self):
        """"""
        tag = os.getenv("CIRCLE_TAG")

        if tag != VERSION:
            info = "Git tag: {0} does not match the version of this app: {1}".format(
                tag, VERSION
            )
            sys.exit(info)

def read_file(fname):
    """return file contents.

    :param fname: path relative to setup.py
    :return: file contents
    """
    with open(os.path.join(os.path.dirname(__file__), fname), "r") as fd:
        return fd.read()

setup(
    name="mythril",
    version=VERSION[1:],
    description="Security analysis tool for Ethereum smart contracts",
    long_description=read_file("README.md") if os.path.isfile("README.md") else "",
    long_description_content_type="text/markdown",  # requires twine and recent setuptools
    url="https://github.com/b-mueller/mythril",
    author="Bernhard Mueller",
    author_email="bernhard.mueller11@gmail.com",
    license="MIT",
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Science/Research",
        "Topic :: Software Development :: Disassemblers",
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
    ],
    keywords="hacking disassembler security ethereum",
    packages=find_packages(exclude=["contrib", "docs", "tests"]),
    install_requires=[
        "coloredlogs>=10.0",
        "py_ecc==1.4.2",
        "ethereum>=2.3.2",
        "z3-solver-mythril>=4.8.4.1",
        "requests",
        "py-solc",
        "plyvel",
        "eth_abi==1.3.0",
        "eth-utils>=1.0.1",
        "eth-account>=0.1.0a2",
        "eth-hash>=0.1.0",
        "eth-keyfile>=0.5.1",
        "eth-keys>=0.2.0b3",
        "eth-rlp>=0.1.0",
        "eth-tester==0.1.0b32",
        "eth-typing>=2.0.0",
        "coverage",
        "jinja2>=2.9",
        "rlp>=1.0.1",
        "transaction>=2.2.1",
        "py-flags",
        "mock",
        "configparser>=3.5.0",
        "persistent>=4.2.0",
        "ethereum-input-decoder>=0.2.2",
    ],
    tests_require=["mypy", "pytest>=3.6.0", "pytest_mock", "pytest-cov"],
    python_requires=">=3.5",
    extras_require={},
    package_data={"mythril.analysis.templates": ["*"], "mythril.support.assets": ["*"]},
    include_package_data=True,
    entry_points={"console_scripts": ["myth=mythril.interfaces.cli:main"]},
    cmdclass={"verify": VerifyVersionCommand},
)
<|endoftext|>


<commit_before># -*- encoding: utf8 -*-
from setuptools import setup, find_packages

import os

setup(
    name = "manhole",
    version = "0.2",
    url = 'https://github.com/ionelmc/python-manhole',
    download_url = '',
    license = 'BSD',
    description = "Inpection manhole for python applications. Connection is done via unix domain sockets.",
    long_description = file(os.path.join(os.path.dirname(__file__), 'README.rst')).read(),
    author = 'Ionel Cristian Mărieș',
    author_email = 'contact@ionelmc.ro',
    package_dir = {'':'src'},
    py_modules = ['manhole'],
    include_package_data = True,
    zip_safe = False,
    classifiers = [
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Internet :: WWW/HTTP',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 2 :: Only',
        'Programming Language :: Python :: Implementation :: CPython',
    ],
    install_requires=[
    ]
)
<commit_msg>Up version.<commit_after># -*- encoding: utf8 -*-
from setuptools import setup, find_packages

import os

setup(
    name = "manhole",
    version = "0.3.0",
    url = 'https://github.com/ionelmc/python-manhole',
    download_url = '',
    license = 'BSD',
    description = "Inpection manhole for python applications. Connection is done via unix domain sockets.",
    long_description = file(os.path.join(os.path.dirname(__file__), 'README.rst')).read(),
    author = 'Ionel Cristian Mărieș',
    author_email = 'contact@ionelmc.ro',
    package_dir = {'':'src'},
    py_modules = ['manhole'],
    include_package_data = True,
    zip_safe = False,
    classifiers = [
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Internet :: WWW/HTTP',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 2 :: Only',
        'Programming Language :: Python :: Implementation :: CPython',
    ],
    install_requires=[
    ]
)
<|endoftext|>


<commit_before>import sys

from setuptools import find_packages, setup

VERSION = sys.version_info[:2]

install_requires = [
    'six',
]
if VERSION < (2, 7):
    install_requires += [
        'argparse',
        'configparser',
    ]

setup(
    name='django-local-settings',
    version='1.0a1',
    author='Wyatt Baldwin',
    author_email='wyatt.baldwin@pdx.edu',
    packages=find_packages(),
    install_requires=install_requires,
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Framework :: Django',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
    ],
    entry_points="""
    [console_scripts]
    make-local-settings = local_settings:make_local_settings

    """,
)
<commit_msg>Add description and long_description to setup()<commit_after>import sys

from setuptools import find_packages, setup

VERSION = sys.version_info[:2]

with open('README.md') as fp:
    long_description = fp.read()

install_requires = [
    'six',
]
if VERSION < (2, 7):
    install_requires += [
        'argparse',
        'configparser',
    ]

setup(
    name='django-local-settings',
    version='1.0a1',
    author='Wyatt Baldwin',
    author_email='wyatt.baldwin@pdx.edu',
    description='A system for dealing with local settings in Django projects',
    long_description=long_description,
    packages=find_packages(),
    install_requires=install_requires,
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Framework :: Django',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
    ],
    entry_points="""
    [console_scripts]
    make-local-settings = local_settings:make_local_settings

    """,
)
<|endoftext|>


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

# The MIT License (MIT)
#
# Copyright (c) 2014 Storj Labs
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

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

version = '0.2.3'

install_requirements = [
    'pycrypto>=2.6.1'
]

test_requirements = [
    'pytest',
    'pytest-pep8',
    'pytest-cache',
    'coveralls'
]

class PyTest(TestCommand):
    user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]

    def initialize_options(self):
        TestCommand.initialize_options(self)
        self.pytest_args = []

    def finalize_options(self):
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        # Import PyTest here because outside, the eggs are not loaded.
        import pytest
        import sys
        errno = pytest.main(self.pytest_args)
        sys.exit(errno)

setup(
    name='file_encryptor',
    version=version,
    url='https://github.com/Storj/file-encryptor',
    download_url='https://github.com/storj/file-encryptor/tarball/'+version,
    license='MIT',
    author='Storj Labs',
    author_email='hello@storj.io',
    description='Tool for convergently encrypting files used by MetaDisk.',
    packages=['file_encryptor'],
    cmdclass={'test': PyTest},
    install_requires=install_requirements,
    tests_require=test_requirements,
    keywords = ['storj', 'metadisk', 'convergent encryption']
)
<commit_msg>Version bump<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# The MIT License (MIT)
#
# Copyright (c) 2014 Storj Labs
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

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

version = '0.2.4'

install_requirements = [
    'pycrypto>=2.6.1'
]

test_requirements = [
    'pytest',
    'pytest-pep8',
    'pytest-cache',
    'coveralls'
]

class PyTest(TestCommand):
    user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]

    def initialize_options(self):
        TestCommand.initialize_options(self)
        self.pytest_args = []

    def finalize_options(self):
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        # Import PyTest here because outside, the eggs are not loaded.
        import pytest
        import sys
        errno = pytest.main(self.pytest_args)
        sys.exit(errno)

setup(
    name='file_encryptor',
    version=version,
    url='https://github.com/Storj/file-encryptor',
    download_url='https://github.com/storj/file-encryptor/tarball/'+version,
    license='MIT',
    author='Storj Labs',
    author_email='hello@storj.io',
    description='Tool for convergently encrypting files used by MetaDisk.',
    packages=['file_encryptor'],
    cmdclass={'test': PyTest},
    install_requires=install_requirements,
    tests_require=test_requirements,
    keywords = ['storj', 'metadisk', 'convergent encryption']
)
<|endoftext|>


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

import os
import re
import sys

from codecs import open

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

here = os.path.abspath(os.path.dirname(__file__))

class PyTest(TestCommand):
    user_options = [('pytest-args=', 'a', "Arguments to pass into py.test")]

    def initialize_options(self):
        TestCommand.initialize_options(self)
        self.pytest_args = []

    def finalize_options(self):
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        import pytest

        errno = pytest.main(self.pytest_args)
        sys.exit(errno)

# 'setup.py publish' shortcut.
if sys.argv[-1] == 'publish':
    os.system('python setup.py sdist bdist_wheel')
    os.system('twine upload dist/*')
    sys.exit()

packages = ['requests']

requires = [
    'chardet>=3.0.2,<3.1.0',
    'idna>=2.5,<2.6',
    'urllib3>=1.21.1,<1.22',
    'certifi>=2017.4.17'

]
test_requirements = ['pytest>=2.8.0', 'pytest-httpbin==0.0.7', 'pytest-cov', 'pytest-mock', 'pytest-xdist', 'PySocks>=1.5.6, !=1.5.7']

about = {}
with open(os.path.join(here, 'requests', '__version__.py'), 'r', 'utf-8') as f:
    exec(f.read(), about)

with open('README.rst', 'r', 'utf-8') as f:
    readme = f.read()
with open('HISTORY.rst', 'r', 'utf-8') as f:
    history = f.read()

setup(
    name=about['__title__'],
    version=about['__version__'],
    description=about['__description__'],
    long_description=readme + '\n\n' + history,
    author=about['__author__'],
    author_email=about['__author_email__'],
    url=about['__url__'],
    packages=packages,
    package_data={'': ['LICENSE', 'NOTICE'], 'requests': ['*.pem']},
    package_dir={'requests': 'requests'},
    include_package_data=True,
    install_requires=requires,
    license=about['__license__'],
    zip_safe=False,
    classifiers=(
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Natural Language :: English',
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: Implementation :: CPython',
        'Programming Language :: Python :: Implementation :: PyPy'
    ),
    cmdclass={'test': PyTest},
    tests_require=test_requirements,
    extras_require={
        'security': ['pyOpenSSL>=0.14', 'cryptography>=1.3.4', 'idna>=2.0.0'],
        'socks': ['PySocks>=1.5.6, !=1.5.7'],
        'socks:sys_platform == "win32" and (python_version == "2.7" or python_version == "2.6")': ['win_inet_pton'],
    },
)

<commit_msg>see if that fixes things<commit_after>#!/usr/bin/env python

import os
import re
import sys

from codecs import open

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

here = os.path.abspath(os.path.dirname(__file__))

class PyTest(TestCommand):
    user_options = [('pytest-args=', 'a', "Arguments to pass into py.test")]

    def initialize_options(self):
        TestCommand.initialize_options(self)
        self.pytest_args = []

    def finalize_options(self):
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        import pytest

        errno = pytest.main(self.pytest_args)
        sys.exit(errno)

# 'setup.py publish' shortcut.
if sys.argv[-1] == 'publish':
    os.system('python setup.py sdist bdist_wheel')
    os.system('twine upload dist/*')
    sys.exit()

packages = ['requests']

requires = [
    'chardet>=3.0.2,<3.1.0',
    'idna>=2.5,<2.6',
    'urllib3>=1.21.1,<1.22',
    'certifi>=2017.4.17'

]
test_requirements = ['pytest-httpbin==0.0.7', 'pytest-cov', 'pytest-mock', 'pytest-xdist', 'PySocks>=1.5.6, !=1.5.7', 'pytest>=2.8.0']

about = {}
with open(os.path.join(here, 'requests', '__version__.py'), 'r', 'utf-8') as f:
    exec(f.read(), about)

with open('README.rst', 'r', 'utf-8') as f:
    readme = f.read()
with open('HISTORY.rst', 'r', 'utf-8') as f:
    history = f.read()

setup(
    name=about['__title__'],
    version=about['__version__'],
    description=about['__description__'],
    long_description=readme + '\n\n' + history,
    author=about['__author__'],
    author_email=about['__author_email__'],
    url=about['__url__'],
    packages=packages,
    package_data={'': ['LICENSE', 'NOTICE'], 'requests': ['*.pem']},
    package_dir={'requests': 'requests'},
    include_package_data=True,
    install_requires=requires,
    license=about['__license__'],
    zip_safe=False,
    classifiers=(
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Natural Language :: English',
        'License :: OSI Approved :: Apache Software License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: Implementation :: CPython',
        'Programming Language :: Python :: Implementation :: PyPy'
    ),
    cmdclass={'test': PyTest},
    tests_require=test_requirements,
    extras_require={
        'security': ['pyOpenSSL>=0.14', 'cryptography>=1.3.4', 'idna>=2.0.0'],
        'socks': ['PySocks>=1.5.6, !=1.5.7'],
        'socks:sys_platform == "win32" and (python_version == "2.7" or python_version == "2.6")': ['win_inet_pton'],
    },
)

<|endoftext|>


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

from setuptools import setup, find_packages

descript = 'A Python library for parsing frame ranges and file ' \
                  'sequences based on a similar library found in Katana.'

setup(name='Fileseq',
      version='1.1.2',

      package_dir = {'': 'src'},
      packages=find_packages('src'),

      test_suite="test.run",

      author='Matt Chambers',
      author_email='yougotrooted@gmail.com',
      url='https://github.com/sqlboy/fileseq',
      description=descript
     )
<commit_msg>Bump v1.1.3<commit_after>#!/usr/bin/env python

from setuptools import setup, find_packages

descript = 'A Python library for parsing frame ranges and file ' \
                  'sequences based on a similar library found in Katana.'

setup(name='Fileseq',
      version='1.1.3',

      package_dir = {'': 'src'},
      packages=find_packages('src'),

      test_suite="test.run",

      author='Matt Chambers',
      author_email='yougotrooted@gmail.com',
      url='https://github.com/sqlboy/fileseq',
      description=descript
     )
<|endoftext|>


<commit_before>import collections
from typing import Any, Dict, Optional, Sequence, Set, Tuple

import click
from click import get_current_context
from click.core import Context, Option
from click.formatting import HelpFormatter
from valohai_yaml.objs import Step
from valohai_yaml.objs.input import Input
from valohai_yaml.objs.parameter import Parameter

from valohai_cli import git as git
from valohai_cli.api import request
from valohai_cli.exceptions import CLIException, NoGitRepo
from valohai_cli.messages import success, warn
from valohai_cli.models.project import Project
from valohai_cli.utils import humanize_identifier, sanitize_option_name
from valohai_cli.utils.file_input import read_data_file
from valohai_cli.utils.friendly_option_parser import FriendlyOptionParser

from .excs import ExecutionCreationAPIError

def generate_sanitized_options(name: str) -> Set[str]:
    sanitized_name = sanitize_option_name(name)
    return {
        choice
        for choice in
        (
            f'--{sanitized_name}',
            f'--{sanitized_name}'.lower(),
        )
        if ' ' not in choice
    }

class RunCommand(click.Command):
    """
    A dynamically-generated subcommand that has Click options for parameters and inputs.
    """
    parameter_type_map = {
        'integer': click.INT,
        'float': click.FLOAT,
        'flag': click.BOOL,
    }

    def __init__(
        self,
        project: Project,
        step: Step,
        commit: Optional[str],
        environment: Optional[str] = None,
        image: Optional[str] = None,
        title: Optional[str] = None,
        watch: bool = False,
        download_directory: Optional[str] = None,
        environment_variables: Optional[Dict[str, str]] = None,
        tags: Optional[Sequence[str]] = None
    ):

        """
        Initialize the dynamic run command.

        :param environment_variables:
        :param project: Project object
        :param step: YAML step object
        :param commit: Commit identifier
        :param environment: Environment identifier (slug or UUID)
        :param environment_variables: Mapping of environment variables
        :param tags: Tags to apply
        :param watch: Whether to chain to `exec watch` afterwards
        :param image: Image override
        :param download_directory: Where to (if somewhere) to download execution outputs (sync mode)
        """
        assert isinstance(step, Step)
        self.project = project
        self.step = step
        self.commit = commit
        self.environment = environment
        self.image = image
        self.watch = bool(watch)
        self.download_directory = download_directory
        self.title = title
        self.environment_variables = dict(environment_variables or {})
        self.tags = list(tags or [])
        super().__init__(
            name=sanitize_option_name(step.name.lower()),
            callback=self.execute,
            epilog='Multiple files per input: --my-input=myurl --my-input=myotherurl',
            add_help_option=True,
        )
        self.params.append(click.Option(
            ['--parameter-file'],
            type=click.Path(exists=True, dir_okay=False),
            help='Read parameter values from JSON/YAML file',
        ))
        for parameter in step.parameters.values():
            self.params.append(self.convert_param_to_option(parameter))
        for input in step.inputs.values():
            self.params.append(self.convert_input_to_option(input))
        for name, value in step.environment_variables.items():
            if name not in self.environment_variables:
                self.environment_variables[name] = value.default

    def format_options(self, ctx: Context, formatter: HelpFormatter) -> None:
        opts_by_group = collections.defaultdict(list)
        for param in self.get_params(ctx):
            rv = param.get_help_record(ctx)
            if rv is not None:
                opts_by_group[getattr(param, 'help_group', None)].append(rv)

        for group_name, opts in sorted(opts_by_group.items(), key=lambda pair: (pair[0] or '')):
            with formatter.section(group_name or 'Options'):
                formatter.write_dl(opts)

    def convert_param_to_option(self, parameter: Parameter) -> Option:
        """
        Convert a Parameter into a click Option.
        """
        assert isinstance(parameter, Parameter)
        option = click.Option(
            param_decls=list(generate_sanitized_options(parameter.name)),
            required=False,  # This is done later
            default=parameter.default,
            help=parameter.description,
            type=self.parameter_type_map.get(parameter.type, click.STRING),
        )
        option.name = f'~{parameter.name}'  # Tildify so we can pick these out of kwargs easily
        option.help_group = 'Parameter Options'  # type: ignore[attr-defined]
        return option

    def convert_input_to_option(self, input: Input) -> Option:
        """
        Convert an Input into a click Option.
        """
        assert isinstance(input, Input)
        default_as_list = input.default if isinstance(input.default, list) else [input.default]

        option = click.Option(
            param_decls=list(generate_sanitized_options(input.name)),
            required=(input.default is None and not input.optional),
            default=(default_as_list if input.default else []),
            metavar='URL',
            multiple=True,
            help=f'Input "{humanize_identifier(input.name)}"',
        )
        option.name = f'^{input.name}'  # Caretize so we can pick these out of kwargs easily
        option.help_group = 'Input Options'  # type: ignore[attr-defined]
        return option

    def execute(self, **kwargs: Any) -> None:
        """
        Execute the creation of the execution. (Heh.)

        This is the Click callback for this command.

        :param kwargs: Assorted kwargs (as passed in by Click).
        :return: Naught
        """
        options, parameters, inputs = self._sift_kwargs(kwargs)
        commit = self.resolve_commit(self.commit)

        payload = {
            'commit': commit,
            'inputs': inputs,
            'parameters': parameters,
            'project': self.project.id,
            'step': self.step.name,
        }
        if self.environment:
            payload['environment'] = self.environment
        if self.image:
            payload['image'] = self.image
        if self.title:
            payload['title'] = self.title
        if self.environment_variables:
            payload['environment_variables'] = self.environment_variables
        if self.tags:
            payload['tags'] = self.tags

        resp = request(
            method='post',
            url='/api/v0/executions/',
            json=payload,
            api_error_class=ExecutionCreationAPIError,
        ).json()
        success('Execution #{counter} created. See {link}'.format(
            counter=resp['counter'],
            link=resp['urls']['display'],
        ))

        ctx = get_current_context()

        if self.download_directory:
            from valohai_cli.commands.execution.outputs import outputs as outputs_command
            ctx.invoke(
                outputs_command,
                counter=resp['counter'],
                sync=True,
                download_directory=self.download_directory,
            )

        if self.watch:
            from valohai_cli.commands.execution.watch import watch
            ctx.invoke(watch, counter=resp['counter'])

    def _sift_kwargs(self, kwargs: Dict[str, str]) -> Tuple[dict, dict, dict]:
        # Sift kwargs into params, options, and inputs
        options = {}
        params = {}
        inputs = {}
        for key, value in kwargs.items():
            if key.startswith('~'):
                params[key[1:]] = value
            elif key.startswith('^'):
                inputs[key[1:]] = value
            else:
                options[key] = value
        self._process_parameters(params, parameter_file=options.get('parameter_file'))
        return (options, params, inputs)

    def _process_parameters(self, parameters: Dict[str, Any], parameter_file: Optional[str]) -> None:
        if parameter_file:
            parameter_file_data = read_data_file(parameter_file)
            if not isinstance(parameter_file_data, dict):
                raise CLIException('Parameter file could not be parsed as a dictionary')

            for name, parameter in self.step.parameters.items():
                # See if we can match the name or the sanitized name to an option
                for key in (name, sanitize_option_name(name)):
                    if key not in parameter_file_data:
                        continue
                    value = parameter_file_data.pop(key)
                    type = self.parameter_type_map.get(parameter.type, click.STRING)
                    value = type.convert(value, param=None, ctx=None)
                    parameters[name] = value

            if parameter_file_data:  # Not everything was popped off
                unparsed_parameter_names = ', '.join(sorted(str(k) for k in parameter_file_data))
                warn(f'Parameters ignored in parameter file: {unparsed_parameter_names}')

        missing_required_parameters = set()
        for name, parameter in self.step.parameters.items():
            if name in parameters:
                # Clean out default-less flag parameters whose value would be None
                if parameter.type == 'flag' and parameters[name] is None:
                    del parameters[name]
            else:
                required = (parameter.default is None and not parameter.optional)
                if required:
                    missing_required_parameters.add(name)
        if missing_required_parameters:
            raise CLIException(f'Required parameters missing: {missing_required_parameters}')

    def resolve_commit(self, commit_identifier: Optional[str]) -> str:
        if not commit_identifier:
            try:
                commit_identifier = git.get_current_commit(self.project.directory)
            except NoGitRepo:
                warn(
                    'The directory is not a Git repository. \n'
                    'Would you like to just run using the latest commit known by Valohai?'
                )
                if not click.confirm('Use latest commit?', default=True):
                    raise click.Abort()

        if commit_identifier and commit_identifier.startswith('~'):
            # Assume ad-hoc commits are qualified already
            return commit_identifier

        try:
            commit_obj = self.project.resolve_commit(commit_identifier=commit_identifier)
        except KeyError:
            warn(f'Commit {commit_identifier} is not known for the project. Have you pushed it?')
            raise click.Abort()
        except IndexError:
            warn('No commits are known for the project.')
            raise click.Abort()

        resolved_commit_identifier: str = commit_obj['identifier']
        if not commit_identifier:
            click.echo(f'Resolved to commit {resolved_commit_identifier}', err=True)

        return resolved_commit_identifier

    def make_parser(self, ctx: Context) -> FriendlyOptionParser:
        parser: FriendlyOptionParser = super().make_parser(ctx)  # type: ignore[assignment]
        # This is somewhat naughty, but allows us to easily hook into here.
        # Besides, FriendlyOptionParser does inherit from OptionParser anyway,
        # and just overrides that one piece of behavior...
        parser.__class__ = FriendlyOptionParser
        return parser
<commit_msg>Fix a couple of small type errors<commit_after>import collections
from typing import Any, Dict, Optional, Sequence, Set, Tuple

import click
from click import get_current_context
from click.core import Context, Option
from click.formatting import HelpFormatter
from valohai_yaml.objs import Step
from valohai_yaml.objs.input import Input
from valohai_yaml.objs.parameter import Parameter
from valohai_yaml.utils import listify

from valohai_cli import git as git
from valohai_cli.api import request
from valohai_cli.exceptions import CLIException, NoGitRepo
from valohai_cli.messages import success, warn
from valohai_cli.models.project import Project
from valohai_cli.utils import humanize_identifier, sanitize_option_name
from valohai_cli.utils.file_input import read_data_file
from valohai_cli.utils.friendly_option_parser import FriendlyOptionParser

from .excs import ExecutionCreationAPIError

def generate_sanitized_options(name: str) -> Set[str]:
    sanitized_name = sanitize_option_name(name)
    return {
        choice
        for choice in
        (
            f'--{sanitized_name}',
            f'--{sanitized_name}'.lower(),
        )
        if ' ' not in choice
    }

class RunCommand(click.Command):
    """
    A dynamically-generated subcommand that has Click options for parameters and inputs.
    """
    parameter_type_map = {
        'integer': click.INT,
        'float': click.FLOAT,
        'flag': click.BOOL,
    }

    def __init__(
        self,
        project: Project,
        step: Step,
        commit: Optional[str],
        environment: Optional[str] = None,
        image: Optional[str] = None,
        title: Optional[str] = None,
        watch: bool = False,
        download_directory: Optional[str] = None,
        environment_variables: Optional[Dict[str, str]] = None,
        tags: Optional[Sequence[str]] = None
    ):

        """
        Initialize the dynamic run command.

        :param environment_variables:
        :param project: Project object
        :param step: YAML step object
        :param commit: Commit identifier
        :param environment: Environment identifier (slug or UUID)
        :param environment_variables: Mapping of environment variables
        :param tags: Tags to apply
        :param watch: Whether to chain to `exec watch` afterwards
        :param image: Image override
        :param download_directory: Where to (if somewhere) to download execution outputs (sync mode)
        """
        assert isinstance(step, Step)
        self.project = project
        self.step = step
        self.commit = commit
        self.environment = environment
        self.image = image
        self.watch = bool(watch)
        self.download_directory = download_directory
        self.title = title
        self.environment_variables = dict(environment_variables or {})
        self.tags = list(tags or [])
        super().__init__(
            name=sanitize_option_name(step.name.lower()),
            callback=self.execute,
            epilog='Multiple files per input: --my-input=myurl --my-input=myotherurl',
            add_help_option=True,
        )
        self.params.append(click.Option(
            ['--parameter-file'],
            type=click.Path(exists=True, dir_okay=False),
            help='Read parameter values from JSON/YAML file',
        ))
        for parameter in step.parameters.values():
            self.params.append(self.convert_param_to_option(parameter))
        for input in step.inputs.values():
            self.params.append(self.convert_input_to_option(input))
        for name, value in step.environment_variables.items():
            if name not in self.environment_variables and value.default is not None:
                self.environment_variables[name] = value.default

    def format_options(self, ctx: Context, formatter: HelpFormatter) -> None:
        opts_by_group = collections.defaultdict(list)
        for param in self.get_params(ctx):
            rv = param.get_help_record(ctx)
            if rv is not None:
                opts_by_group[getattr(param, 'help_group', None)].append(rv)

        for group_name, opts in sorted(opts_by_group.items(), key=lambda pair: (pair[0] or '')):
            with formatter.section(group_name or 'Options'):
                formatter.write_dl(opts)

    def convert_param_to_option(self, parameter: Parameter) -> Option:
        """
        Convert a Parameter into a click Option.
        """
        assert isinstance(parameter, Parameter)
        option = click.Option(
            param_decls=list(generate_sanitized_options(parameter.name)),
            required=False,  # This is done later
            default=parameter.default,
            help=parameter.description,
            type=self.parameter_type_map.get(parameter.type, click.STRING),
        )
        option.name = f'~{parameter.name}'  # Tildify so we can pick these out of kwargs easily
        option.help_group = 'Parameter Options'  # type: ignore[attr-defined]
        return option

    def convert_input_to_option(self, input: Input) -> Option:
        """
        Convert an Input into a click Option.
        """
        assert isinstance(input, Input)

        option = click.Option(
            param_decls=list(generate_sanitized_options(input.name)),
            required=(input.default is None and not input.optional),
            default=listify(input.default),
            metavar='URL',
            multiple=True,
            help=f'Input "{humanize_identifier(input.name)}"',
        )
        option.name = f'^{input.name}'  # Caretize so we can pick these out of kwargs easily
        option.help_group = 'Input Options'  # type: ignore[attr-defined]
        return option

    def execute(self, **kwargs: Any) -> None:
        """
        Execute the creation of the execution. (Heh.)

        This is the Click callback for this command.

        :param kwargs: Assorted kwargs (as passed in by Click).
        :return: Naught
        """
        options, parameters, inputs = self._sift_kwargs(kwargs)
        commit = self.resolve_commit(self.commit)

        payload = {
            'commit': commit,
            'inputs': inputs,
            'parameters': parameters,
            'project': self.project.id,
            'step': self.step.name,
        }
        if self.environment:
            payload['environment'] = self.environment
        if self.image:
            payload['image'] = self.image
        if self.title:
            payload['title'] = self.title
        if self.environment_variables:
            payload['environment_variables'] = self.environment_variables
        if self.tags:
            payload['tags'] = self.tags

        resp = request(
            method='post',
            url='/api/v0/executions/',
            json=payload,
            api_error_class=ExecutionCreationAPIError,
        ).json()
        success('Execution #{counter} created. See {link}'.format(
            counter=resp['counter'],
            link=resp['urls']['display'],
        ))

        ctx = get_current_context()

        if self.download_directory:
            from valohai_cli.commands.execution.outputs import outputs as outputs_command
            ctx.invoke(
                outputs_command,
                counter=resp['counter'],
                sync=True,
                download_directory=self.download_directory,
            )

        if self.watch:
            from valohai_cli.commands.execution.watch import watch
            ctx.invoke(watch, counter=resp['counter'])

    def _sift_kwargs(self, kwargs: Dict[str, str]) -> Tuple[dict, dict, dict]:
        # Sift kwargs into params, options, and inputs
        options = {}
        params = {}
        inputs = {}
        for key, value in kwargs.items():
            if key.startswith('~'):
                params[key[1:]] = value
            elif key.startswith('^'):
                inputs[key[1:]] = value
            else:
                options[key] = value
        self._process_parameters(params, parameter_file=options.get('parameter_file'))
        return (options, params, inputs)

    def _process_parameters(self, parameters: Dict[str, Any], parameter_file: Optional[str]) -> None:
        if parameter_file:
            parameter_file_data = read_data_file(parameter_file)
            if not isinstance(parameter_file_data, dict):
                raise CLIException('Parameter file could not be parsed as a dictionary')

            for name, parameter in self.step.parameters.items():
                # See if we can match the name or the sanitized name to an option
                for key in (name, sanitize_option_name(name)):
                    if key not in parameter_file_data:
                        continue
                    value = parameter_file_data.pop(key)
                    type = self.parameter_type_map.get(parameter.type, click.STRING)
                    value = type.convert(value, param=None, ctx=None)
                    parameters[name] = value

            if parameter_file_data:  # Not everything was popped off
                unparsed_parameter_names = ', '.join(sorted(str(k) for k in parameter_file_data))
                warn(f'Parameters ignored in parameter file: {unparsed_parameter_names}')

        missing_required_parameters = set()
        for name, parameter in self.step.parameters.items():
            if name in parameters:
                # Clean out default-less flag parameters whose value would be None
                if parameter.type == 'flag' and parameters[name] is None:
                    del parameters[name]
            else:
                required = (parameter.default is None and not parameter.optional)
                if required:
                    missing_required_parameters.add(name)
        if missing_required_parameters:
            raise CLIException(f'Required parameters missing: {missing_required_parameters}')

    def resolve_commit(self, commit_identifier: Optional[str]) -> str:
        if not commit_identifier:
            try:
                commit_identifier = git.get_current_commit(self.project.directory)
            except NoGitRepo:
                warn(
                    'The directory is not a Git repository. \n'
                    'Would you like to just run using the latest commit known by Valohai?'
                )
                if not click.confirm('Use latest commit?', default=True):
                    raise click.Abort()

        if commit_identifier and commit_identifier.startswith('~'):
            # Assume ad-hoc commits are qualified already
            return commit_identifier

        try:
            commit_obj = self.project.resolve_commit(commit_identifier=commit_identifier)
        except KeyError:
            warn(f'Commit {commit_identifier} is not known for the project. Have you pushed it?')
            raise click.Abort()
        except IndexError:
            warn('No commits are known for the project.')
            raise click.Abort()

        resolved_commit_identifier: str = commit_obj['identifier']
        if not commit_identifier:
            click.echo(f'Resolved to commit {resolved_commit_identifier}', err=True)

        return resolved_commit_identifier

    def make_parser(self, ctx: Context) -> FriendlyOptionParser:
        parser: FriendlyOptionParser = super().make_parser(ctx)  # type: ignore[assignment]
        # This is somewhat naughty, but allows us to easily hook into here.
        # Besides, FriendlyOptionParser does inherit from OptionParser anyway,
        # and just overrides that one piece of behavior...
        parser.__class__ = FriendlyOptionParser
        return parser
<|endoftext|>


<commit_before># Copyright 2015 Google Inc.
#
# 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.

from codecs import open

from setuptools import setup

long_description = open('README.rst', 'r', encoding='utf-8').read()

setup(
    name='psq',

    version='0.2.1',

    description='A simple task queue using Google Cloud Pub/Sub',
    long_description=long_description,

    url='https://github.com/GoogleCloudPlatform/psq',

    author='Jon Wayne Parrott',
    author_email='jonwayne@google.com',

    license='Apache Software License',

    classifiers=[
        'Development Status :: 3 - Alpha',

        # Indicate who your project is intended for
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Topic :: Internet',
        'Topic :: Scientific/Engineering',
        'Topic :: System :: Distributed Computing',

        'License :: OSI Approved :: Apache Software License',

        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.4',

        'Operating System :: POSIX',
        'Operating System :: MacOS',
        'Operating System :: Unix',
    ],

    keywords='queue tasks background worker',

    packages=['psq'],

    install_requires=[
        'gcloud>=0.9.0',
        'retrying>=1.0.0,<2.0.0',
        'werkzeug>=0.10.0,<1.0.0',
        'click>=4.0,<5.0',
        'colorlog>=2.6.0,<3.0.0'],

    entry_points={
        'console_scripts': [
            'psqworker=psq.psqworker:main',
        ],
    },
)
<commit_msg>Updating version number to 0.3.0<commit_after># Copyright 2015 Google Inc.
#
# 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.

from codecs import open

from setuptools import setup

long_description = open('README.rst', 'r', encoding='utf-8').read()

setup(
    name='psq',

    version='0.3.0',

    description='A simple task queue using Google Cloud Pub/Sub',
    long_description=long_description,

    url='https://github.com/GoogleCloudPlatform/psq',

    author='Jon Wayne Parrott',
    author_email='jonwayne@google.com',

    license='Apache Software License',

    classifiers=[
        'Development Status :: 3 - Alpha',

        # Indicate who your project is intended for
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Topic :: Internet',
        'Topic :: Scientific/Engineering',
        'Topic :: System :: Distributed Computing',

        'License :: OSI Approved :: Apache Software License',

        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.4',

        'Operating System :: POSIX',
        'Operating System :: MacOS',
        'Operating System :: Unix',
    ],

    keywords='queue tasks background worker',

    packages=['psq'],

    install_requires=[
        'gcloud>=0.9.0',
        'retrying>=1.0.0,<2.0.0',
        'werkzeug>=0.10.0,<1.0.0',
        'click>=4.0,<5.0',
        'colorlog>=2.6.0,<3.0.0'],

    entry_points={
        'console_scripts': [
            'psqworker=psq.psqworker:main',
        ],
    },
)
<|endoftext|>


<commit_before>from distutils.core import setup

setup(
    name='Axelrod',
    version='0.0.8',
    author='Vince Knight, Owen Campbell, Karol Langner',
    author_email=('axelrod-python@googlegroups.com'),
    packages=['axelrod', 'axelrod.strategies', 'axelrod.tests'],
    scripts=['run_axelrod'],
    url='http://axelrod.readthedocs.org/',
    license='The MIT License (MIT)',
    description='Reproduce the Axelrod iterated prisoners dilemma tournament',
    install_requires=[
        "matplotlib >= 1.4.2",
    ],
)
<commit_msg>Updating version number<commit_after>from distutils.core import setup

setup(
    name='Axelrod',
    version='0.0.9',
    author='Vince Knight, Owen Campbell, Karol Langner',
    author_email=('axelrod-python@googlegroups.com'),
    packages=['axelrod', 'axelrod.strategies', 'axelrod.tests'],
    scripts=['run_axelrod'],
    url='http://axelrod.readthedocs.org/',
    license='The MIT License (MIT)',
    description='Reproduce the Axelrod iterated prisoners dilemma tournament',
    install_requires=[
        "matplotlib >= 1.4.2",
    ],
)
<|endoftext|>


<commit_before># Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class PyDictdiffer(PythonPackage):
    """Dictdiffer is a helper module that helps you to diff and patch dictionares."""

    homepage = "https://github.com/inveniosoftware/dictdiffer"
    pypi     = "dictdiffer/dictdiffer-0.8.1.tar.gz"

    version('0.8.1', sha256='1adec0d67cdf6166bda96ae2934ddb5e54433998ceab63c984574d187cc563d2')

    depends_on('python@3.4:', type=('build', 'run'))
    depends_on('py-setuptools', type=('build', 'run'))
    depends_on('py-setuptools-scm@3.1.0:', type=('build'))
<commit_msg>py-dictdiffer: fix offline dependencies (#21345)<commit_after># Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class PyDictdiffer(PythonPackage):
    """Dictdiffer is a helper module that helps you to diff and patch dictionares."""

    homepage = "https://github.com/inveniosoftware/dictdiffer"
    pypi     = "dictdiffer/dictdiffer-0.8.1.tar.gz"

    version('0.8.1', sha256='1adec0d67cdf6166bda96ae2934ddb5e54433998ceab63c984574d187cc563d2')

    depends_on('python@2.7:2.8,3.4:', type=('build', 'run'))
    depends_on('py-setuptools', type=('build', 'run'))
    depends_on('py-setuptools-scm@3.1.0:', type='build')
    depends_on('py-pytest-runner@2.7:', type='build')
<|endoftext|>


<commit_before>"""
orgco

Copyright (c) 2013, Friedrich Paetzke (f.paetzke@gmail.com)
All rights reserved.

"""
from distutils.core import setup

setup(name='orgco',
      description='',
      version='0.0.0.4',
      author='Friedrich Paetzke',
      author_email='f.paetzke@gmail.com',
      url='https://github.com/paetzke/orgco',
      packages=['orgco'])
<commit_msg>Release version 0.0.1.0<commit_after>"""
orgco

Copyright (c) 2013, Friedrich Paetzke (f.paetzke@gmail.com)
All rights reserved.

"""
from distutils.core import setup

setup(name='orgco',
      description='',
      version='0.0.1.0',
      author='Friedrich Paetzke',
      author_email='f.paetzke@gmail.com',
      url='https://github.com/paetzke/orgco',
      packages=['orgco'])
<|endoftext|>


<commit_before># Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class PySimplejson(PythonPackage):
    """Simplejson is a simple, fast, extensible JSON encoder/decoder for
    Python"""

    homepage = "https://github.com/simplejson/simplejson"
    url      = "https://pypi.io/packages/source/s/simplejson/simplejson-3.10.0.tar.gz"

    version('3.10.0', sha256='953be622e88323c6f43fad61ffd05bebe73b9fd9863a46d68b052d2aa7d71ce2')
    version('3.9.0',  sha256='e9abeee37424f4bfcd27d001d943582fb8c729ffc0b74b72bd0e9b626ed0d1b6')
    version('3.8.2',  sha256='d58439c548433adcda98e695be53e526ba940a4b9c44fb9a05d92cd495cdd47f')
    version('3.8.1',  sha256='428ac8f3219c78fb04ce05895d5dff9bd813c05a9a7922c53dc879cd32a12493')
    version('3.8.0',  sha256='217e4797da3a9a4a9fbe6722e0db98070b8443a88212d7acdbd241a7668141d9')

    depends_on('py-setuptools', type='build')
<commit_msg>New version of simplejson (#15325)<commit_after># Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class PySimplejson(PythonPackage):
    """Simplejson is a simple, fast, extensible JSON encoder/decoder for
    Python"""

    homepage = "https://github.com/simplejson/simplejson"
    url      = "https://pypi.io/packages/source/s/simplejson/simplejson-3.10.0.tar.gz"

    version('3.16.0', sha256='b1f329139ba647a9548aa05fb95d046b4a677643070dc2afc05fa2e975d09ca5')
    version('3.10.0', sha256='953be622e88323c6f43fad61ffd05bebe73b9fd9863a46d68b052d2aa7d71ce2')
    version('3.9.0',  sha256='e9abeee37424f4bfcd27d001d943582fb8c729ffc0b74b72bd0e9b626ed0d1b6')
    version('3.8.2',  sha256='d58439c548433adcda98e695be53e526ba940a4b9c44fb9a05d92cd495cdd47f')
    version('3.8.1',  sha256='428ac8f3219c78fb04ce05895d5dff9bd813c05a9a7922c53dc879cd32a12493')
    version('3.8.0',  sha256='217e4797da3a9a4a9fbe6722e0db98070b8443a88212d7acdbd241a7668141d9')

    depends_on('py-setuptools', type='build')
<|endoftext|>


<commit_before>#!/usr/bin/env python
descr = """Python Control Systems Library

The Python Control Systems Library, python-control,
is a python module that implements basic operations
for analysis and design of feedback control systems.

Features:
Linear input/output systems in state space and frequency domain
Block diagram algebra: serial, parallel and feedback interconnections
Time response: initial, step, impulse
Frequency response: Bode and Nyquist plots
Control analysis: stability, reachability, observability, stability margins
Control design: eigenvalue placement, linear quadratic regulator
Estimator design: linear quadratic estimator (Kalman filter)

"""

MAJOR = 0
MINOR = 6
MICRO = 5
ISRELEASED = True
DISTNAME            = 'control'
DESCRIPTION         = 'Python control systems library'
LONG_DESCRIPTION    = descr
AUTHOR              = 'Richard Murray'
AUTHOR_EMAIL        = 'murray@cds.caltech.edu'
MAINTAINER          = AUTHOR
MAINTAINER_EMAIL    = AUTHOR_EMAIL
URL                 = 'http://python-control.sourceforge.net'
LICENSE             = 'BSD'
DOWNLOAD_URL        = URL
PACKAGE_NAME        = 'control'
EXTRA_INFO          = dict(
    install_requires=['numpy', 'scipy', 'matplotlib'],
    tests_require=['scipy', 'matplotlib', 'nose']
)

VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)

import os
import sys
import subprocess

from setuptools import setup, find_packages

CLASSIFIERS = """\
Development Status :: 3 - Alpha
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Programming Language :: Python
Programming Language :: Python :: 3
Topic :: Software Development
Topic :: Scientific/Engineering
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
Operating System :: MacOS
"""

# Return the git revision as a string
def git_version():
    def _minimal_ext_cmd(cmd):
        # construct minimal environment
        env = {}
        for k in ['SYSTEMROOT', 'PATH']:
            v = os.environ.get(k)
            if v is not None:
                env[k] = v
        # LANGUAGE is used on win32
        env['LANGUAGE'] = 'C'
        env['LANG'] = 'C'
        env['LC_ALL'] = 'C'
        out = subprocess.Popen(
            cmd,
            stdout=subprocess.PIPE,
            env=env).communicate()[0]
        return out

    try:
        out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
        GIT_REVISION = out.strip().decode('ascii')
    except OSError:
        GIT_REVISION = "Unknown"

    return GIT_REVISION

def get_version_info():
    # Adding the git rev number needs to be done inside write_version_py(),
    # otherwise the import of package.version messes up
    # the build under Python 3.
    FULLVERSION = VERSION
    if os.path.exists('.git'):
        GIT_REVISION = git_version()
    elif os.path.exists('control/version.py'):
        # must be a source distribution, use existing version file
        try:
            from control.version import git_revision as GIT_REVISION
        except ImportError:
            raise ImportError("Unable to import git_revision. Try removing "
                              "control/version.py and the build directory "
                              "before building.")
    else:
        GIT_REVISION = "Unknown"

    if not ISRELEASED:
        FULLVERSION += '.dev-' + GIT_REVISION[:7]

    return FULLVERSION, GIT_REVISION

def write_version_py(filename='control/version.py'):
    cnt = """
# THIS FILE IS GENERATED FROM SETUP.PY
short_version = '%(version)s'
version = '%(version)s'
full_version = '%(full_version)s'
git_revision = '%(git_revision)s'
release = %(isrelease)s

if not release:
    version = full_version
"""
    FULLVERSION, GIT_REVISION = get_version_info()

    a = open(filename, 'w')
    try:
        a.write(cnt % {'version': VERSION,
                       'full_version': FULLVERSION,
                       'git_revision': GIT_REVISION,
                       'isrelease': str(ISRELEASED)})
    finally:
        a.close()

def setup_package():
    src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
    old_path = os.getcwd()
    os.chdir(src_path)
    sys.path.insert(0, src_path)

    # Rewrite the version file everytime
    write_version_py()

    metadata = dict(
        name=DISTNAME,
        author=AUTHOR,
        author_email=AUTHOR_EMAIL,
        maintainer=MAINTAINER,
        maintainer_email=MAINTAINER_EMAIL,
        description=DESCRIPTION,
        license=LICENSE,
        url=URL,
        download_url=DOWNLOAD_URL,
        long_description=LONG_DESCRIPTION,
        classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
        platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
        install_requires=['numpy', 'scipy'],
        tests_require=['nose'],
        test_suite='nose.collector',
        packages=find_packages(
            exclude=['*.tests']
        ),
    )

    FULLVERSION, GIT_REVISION = get_version_info()
    metadata['version'] = FULLVERSION

    try:
        setup(**metadata)
    finally:
        del sys.path[0]
        os.chdir(old_path)
    return

if __name__ == '__main__':
    setup_package()
<commit_msg>Fix setup.py to work with runtests.py<commit_after>#!/usr/bin/env python
descr = """Python Control Systems Library

The Python Control Systems Library, python-control,
is a python module that implements basic operations
for analysis and design of feedback control systems.

Features:
Linear input/output systems in state space and frequency domain
Block diagram algebra: serial, parallel and feedback interconnections
Time response: initial, step, impulse
Frequency response: Bode and Nyquist plots
Control analysis: stability, reachability, observability, stability margins
Control design: eigenvalue placement, linear quadratic regulator
Estimator design: linear quadratic estimator (Kalman filter)

"""

MAJOR = 0
MINOR = 6
MICRO = 5
ISRELEASED = True
DISTNAME            = 'control'
DESCRIPTION         = 'Python control systems library'
LONG_DESCRIPTION    = descr
AUTHOR              = 'Richard Murray'
AUTHOR_EMAIL        = 'murray@cds.caltech.edu'
MAINTAINER          = AUTHOR
MAINTAINER_EMAIL    = AUTHOR_EMAIL
URL                 = 'http://python-control.sourceforge.net'
LICENSE             = 'BSD'
DOWNLOAD_URL        = URL
PACKAGE_NAME        = 'control'
EXTRA_INFO          = dict(
    install_requires=['numpy', 'scipy', 'matplotlib'],
    tests_require=['scipy', 'matplotlib', 'nose']
)

VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)

import os
import sys
import subprocess

CLASSIFIERS = """\
Development Status :: 3 - Alpha
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Programming Language :: Python
Programming Language :: Python :: 3
Topic :: Software Development
Topic :: Scientific/Engineering
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
Operating System :: MacOS
"""

# Return the git revision as a string
def git_version():
    def _minimal_ext_cmd(cmd):
        # construct minimal environment
        env = {}
        for k in ['SYSTEMROOT', 'PATH']:
            v = os.environ.get(k)
            if v is not None:
                env[k] = v
        # LANGUAGE is used on win32
        env['LANGUAGE'] = 'C'
        env['LANG'] = 'C'
        env['LC_ALL'] = 'C'
        out = subprocess.Popen(
            cmd,
            stdout=subprocess.PIPE,
            env=env).communicate()[0]
        return out

    try:
        out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
        GIT_REVISION = out.strip().decode('ascii')
    except OSError:
        GIT_REVISION = "Unknown"

    return GIT_REVISION

def get_version_info():
    # Adding the git rev number needs to be done inside write_version_py(),
    # otherwise the import of package.version messes up
    # the build under Python 3.
    FULLVERSION = VERSION
    if os.path.exists('.git'):
        GIT_REVISION = git_version()
    elif os.path.exists('control/version.py'):
        # must be a source distribution, use existing version file
        try:
            from control.version import git_revision as GIT_REVISION
        except ImportError:
            raise ImportError("Unable to import git_revision. Try removing "
                              "control/version.py and the build directory "
                              "before building.")
    else:
        GIT_REVISION = "Unknown"

    if not ISRELEASED:
        FULLVERSION += '.dev-' + GIT_REVISION[:7]

    return FULLVERSION, GIT_REVISION

def write_version_py(filename='control/version.py'):
    cnt = """
# THIS FILE IS GENERATED FROM SETUP.PY
short_version = '%(version)s'
version = '%(version)s'
full_version = '%(full_version)s'
git_revision = '%(git_revision)s'
release = %(isrelease)s

if not release:
    version = full_version
"""
    FULLVERSION, GIT_REVISION = get_version_info()

    a = open(filename, 'w')
    try:
        a.write(cnt % {'version': VERSION,
                       'full_version': FULLVERSION,
                       'git_revision': GIT_REVISION,
                       'isrelease': str(ISRELEASED)})
    finally:
        a.close()

def configuration(parent_package='',top_path=None):
    from numpy.distutils.misc_util import Configuration

    config = Configuration(None, parent_package, top_path)
    config.set_options(ignore_setup_xxx_py=True,
                       assume_default_configuration=True,
                       delegate_options_to_subpackages=True,
                       quiet=True)

    config.add_subpackage(PACKAGE_NAME)

    config.get_version(PACKAGE_NAME + '/version.py') # sets config.version

    return config

def setup_package():
    src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
    old_path = os.getcwd()
    os.chdir(src_path)
    sys.path.insert(0, src_path)

    # Rewrite the version file everytime
    write_version_py()

    metadata = dict(
        name=DISTNAME,
        author=AUTHOR,
        author_email=AUTHOR_EMAIL,
        maintainer=MAINTAINER,
        maintainer_email=MAINTAINER_EMAIL,
        description=DESCRIPTION,
        license=LICENSE,
        url=URL,
        download_url=DOWNLOAD_URL,
        long_description=LONG_DESCRIPTION,
        classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
        platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
        install_requires=['numpy', 'scipy'],
        tests_require=['nose'],
        test_suite='nose.collector',
        packages=[PACKAGE_NAME],
    )

    # Run build
    if len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or
            sys.argv[1] in ('--help-commands', 'egg_info', '--version',
                            'clean')):
        # Use setuptools for these commands (they don't work well or at all
        # with distutils).  For normal builds use distutils.
        try:
            from setuptools import setup
        except ImportError:
            from distutils.core import setup

        FULLVERSION, GIT_REVISION = get_version_info()
        metadata['version'] = FULLVERSION
    else:
        if len(sys.argv) >= 2 and sys.argv[1] == 'bdist_wheel':
            # bdist_wheel needs setuptools
            import setuptools
        from numpy.distutils.core import setup
        cwd = os.path.abspath(os.path.dirname(__file__))
        metadata['configuration'] = configuration

    try:
        setup(**metadata)
    finally:
        del sys.path[0]
        os.chdir(old_path)
    return

if __name__ == '__main__':
    setup_package()
<|endoftext|>


<commit_before>import os
import sys

from fnmatch import fnmatchcase

from distutils.util import convert_path
from setuptools import setup, find_packages

VERSION = __import__('pinax').__version__

def read(*path):
    return open(os.path.join(os.path.abspath(os.path.dirname(__file__)), *path)).read()

# Provided as an attribute, so you can append to these instead
# of replicating them:
standard_exclude = ["*.py", "*.pyc", "*~", ".*", "*.bak"]
standard_exclude_directories = [
    ".*", "CVS", "_darcs", "./build",
    "./dist", "EGG-INFO", "*.egg-info"
]

# Copied from paste/util/finddata.py
def find_package_data(where=".", package="", exclude=standard_exclude,
        exclude_directories=standard_exclude_directories,
        only_in_packages=True, show_ignored=False):
    """
    Return a dictionary suitable for use in ``package_data``
    in a distutils ``setup.py`` file.

    The dictionary looks like::

        {"package": [files]}

    Where ``files`` is a list of all the files in that package that
    don't match anything in ``exclude``.

    If ``only_in_packages`` is true, then top-level directories that
    are not packages won't be included (but directories under packages
    will).

    Directories matching any pattern in ``exclude_directories`` will
    be ignored; by default directories with leading ``.``, ``CVS``,
    and ``_darcs`` will be ignored.

    If ``show_ignored`` is true, then all the files that aren't
    included in package data are shown on stderr (for debugging
    purposes).

    Note patterns use wildcards, or can be exact paths (including
    leading ``./``), and all searching is case-insensitive.
    """

    out = {}
    stack = [(convert_path(where), "", package, only_in_packages)]
    while stack:
        where, prefix, package, only_in_packages = stack.pop(0)
        for name in os.listdir(where):
            fn = os.path.join(where, name)
            if os.path.isdir(fn):
                bad_name = False
                for pattern in exclude_directories:
                    if (fnmatchcase(name, pattern)
                        or fn.lower() == pattern.lower()):
                        bad_name = True
                        if show_ignored:
                            print >> sys.stderr, (
                                "Directory %s ignored by pattern %s"
                                % (fn, pattern))
                        break
                if bad_name:
                    continue
                if (os.path.isfile(os.path.join(fn, "__init__.py"))
                    and not prefix):
                    if not package:
                        new_package = name
                    else:
                        new_package = package + "." + name
                    stack.append((fn, "", new_package, False))
                else:
                    stack.append((fn, prefix + name + "/", package, only_in_packages))
            elif package or not only_in_packages:
                # is a file
                bad_name = False
                for pattern in exclude:
                    if (fnmatchcase(name, pattern)
                        or fn.lower() == pattern.lower()):
                        bad_name = True
                        if show_ignored:
                            print >> sys.stderr, (
                                "File %s ignored by pattern %s"
                                % (fn, pattern))
                        break
                if bad_name:
                    continue
                out.setdefault(package, []).append(prefix+name)
    return out

excluded_directories = standard_exclude_directories + ["./requirements", "./scripts"]
package_data = find_package_data(exclude_directories=excluded_directories)

setup(
    name="Pinax",
    version=VERSION,
    description="Pinax is an open-source collection of re-usable apps for the Django Web Framework",
    long_description=read("docs", "intro.txt"),
    author="James Tauber",
    author_email="jtauber@jtauber.com",
    maintainer="Brian Rosner",
    maintainer_email="brosner@gmail.com",
    url="http://pinaxproject.com/",
    packages=find_packages(),
    package_data=package_data,
    zip_safe=False,
    entry_points={
        "console_scripts": [
            "pinax-admin = pinax.core.management:execute_from_command_line",
        ],
    },
    classifiers=[
        "Development Status :: 4 - Beta",
        "Environment :: Web Environment",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Framework :: Django",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2.4",
        "Programming Language :: JavaScript",
    ],
)
<commit_msg>Added download_url<commit_after>import os
import sys

from fnmatch import fnmatchcase

from distutils.util import convert_path
from setuptools import setup, find_packages

VERSION = __import__('pinax').__version__

def read(*path):
    return open(os.path.join(os.path.abspath(os.path.dirname(__file__)), *path)).read()

# Provided as an attribute, so you can append to these instead
# of replicating them:
standard_exclude = ["*.py", "*.pyc", "*~", ".*", "*.bak"]
standard_exclude_directories = [
    ".*", "CVS", "_darcs", "./build",
    "./dist", "EGG-INFO", "*.egg-info"
]

# Copied from paste/util/finddata.py
def find_package_data(where=".", package="", exclude=standard_exclude,
        exclude_directories=standard_exclude_directories,
        only_in_packages=True, show_ignored=False):
    """
    Return a dictionary suitable for use in ``package_data``
    in a distutils ``setup.py`` file.

    The dictionary looks like::

        {"package": [files]}

    Where ``files`` is a list of all the files in that package that
    don't match anything in ``exclude``.

    If ``only_in_packages`` is true, then top-level directories that
    are not packages won't be included (but directories under packages
    will).

    Directories matching any pattern in ``exclude_directories`` will
    be ignored; by default directories with leading ``.``, ``CVS``,
    and ``_darcs`` will be ignored.

    If ``show_ignored`` is true, then all the files that aren't
    included in package data are shown on stderr (for debugging
    purposes).

    Note patterns use wildcards, or can be exact paths (including
    leading ``./``), and all searching is case-insensitive.
    """

    out = {}
    stack = [(convert_path(where), "", package, only_in_packages)]
    while stack:
        where, prefix, package, only_in_packages = stack.pop(0)
        for name in os.listdir(where):
            fn = os.path.join(where, name)
            if os.path.isdir(fn):
                bad_name = False
                for pattern in exclude_directories:
                    if (fnmatchcase(name, pattern)
                        or fn.lower() == pattern.lower()):
                        bad_name = True
                        if show_ignored:
                            print >> sys.stderr, (
                                "Directory %s ignored by pattern %s"
                                % (fn, pattern))
                        break
                if bad_name:
                    continue
                if (os.path.isfile(os.path.join(fn, "__init__.py"))
                    and not prefix):
                    if not package:
                        new_package = name
                    else:
                        new_package = package + "." + name
                    stack.append((fn, "", new_package, False))
                else:
                    stack.append((fn, prefix + name + "/", package, only_in_packages))
            elif package or not only_in_packages:
                # is a file
                bad_name = False
                for pattern in exclude:
                    if (fnmatchcase(name, pattern)
                        or fn.lower() == pattern.lower()):
                        bad_name = True
                        if show_ignored:
                            print >> sys.stderr, (
                                "File %s ignored by pattern %s"
                                % (fn, pattern))
                        break
                if bad_name:
                    continue
                out.setdefault(package, []).append(prefix+name)
    return out

excluded_directories = standard_exclude_directories + ["./requirements", "./scripts"]
package_data = find_package_data(exclude_directories=excluded_directories)

setup(
    name="Pinax",
    version=VERSION,
    description="Pinax is an open-source collection of re-usable apps for the Django Web Framework",
    long_description=read("docs", "intro.txt"),
    author="James Tauber",
    author_email="jtauber@jtauber.com",
    maintainer="Brian Rosner",
    maintainer_email="brosner@gmail.com",
    url="http://pinaxproject.com/",
    download_url="http://pinaxproject.com/downloads/",
    packages=find_packages(),
    package_data=package_data,
    zip_safe=False,
    entry_points={
        "console_scripts": [
            "pinax-admin = pinax.core.management:execute_from_command_line",
        ],
    },
    classifiers=[
        "Development Status :: 4 - Beta",
        "Environment :: Web Environment",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Framework :: Django",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2.4",
        "Programming Language :: JavaScript",
    ],
)
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
from os import path, pardir, chdir
from setuptools import setup, find_packages

README = open(path.join(path.dirname(__file__), 'README.rst')).read()
# requirements.txt must be included in MANIFEST.in and include_package_data must be True
# in order for this to work; ensures that tox can use the setup to enforce requirements
REQUIREMENTS = '\n'.join(open(path.join(path.dirname(__file__), 'requirements.txt')).readlines())
# allow setup.py to be run from any path
chdir(path.normpath(path.join(path.abspath(__file__), pardir)))

setup(
    name="django-onfido",
    version="0.9.0",
    packages=find_packages(),
    install_requires=REQUIREMENTS,
    include_package_data=True,
    description='Django app for integration with Onfido.',
    long_description=README,
    url='https://github.com/yunojuno/django-onfido',
    author='Hugo Rodger-Brown',
    author_email='code@yunojuno.com',
    maintainer='Hugo Rodger-Brown',
    maintainer_email='hugo@yunojuno.com',
    classifiers=[
        'Environment :: Web Environment',
        'Framework :: Django',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Topic :: Internet :: WWW/HTTP',
        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
    ],
)
<commit_msg>Bump version to v0.9.1<commit_after># -*- coding: utf-8 -*-
from os import path, pardir, chdir
from setuptools import setup, find_packages

README = open(path.join(path.dirname(__file__), 'README.rst')).read()
# requirements.txt must be included in MANIFEST.in and include_package_data must be True
# in order for this to work; ensures that tox can use the setup to enforce requirements
REQUIREMENTS = '\n'.join(open(path.join(path.dirname(__file__), 'requirements.txt')).readlines())
# allow setup.py to be run from any path
chdir(path.normpath(path.join(path.abspath(__file__), pardir)))

setup(
    name="django-onfido",
    version="0.9.1",
    packages=find_packages(),
    install_requires=REQUIREMENTS,
    include_package_data=True,
    description='Django app for integration with Onfido.',
    long_description=README,
    url='https://github.com/yunojuno/django-onfido',
    author='Hugo Rodger-Brown',
    author_email='code@yunojuno.com',
    maintainer='Hugo Rodger-Brown',
    maintainer_email='hugo@yunojuno.com',
    classifiers=[
        'Environment :: Web Environment',
        'Framework :: Django',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Topic :: Internet :: WWW/HTTP',
        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
    ],
)
<|endoftext|>


<commit_before>from __future__ import unicode_literals

import logging

from django.conf import settings
from django.db import models

from algoliasearch import algoliasearch

logger = logging.getLogger(__name__)

class AlgoliaIndexError(Exception):
    '''Something went wrong with an Algolia Index.'''

class AlgoliaIndex(object):
    '''An index in the Algolia backend.'''

    # Use to specify a custom field that will be used for the objectID.
    # This field should be unique.
    custom_objectID = None

    # Use to specify the fields that should be included in the index.
    fields = ()

    # Use to specify the geo-fields that should be used for location search.
    # The attribute should be a callable that returns a tuple.
    geo_field = None

    # Use to specify the field that should be used for filtering by tag.
    tags = None

    # Use to specify the index to target on Algolia.
    index_name = None

    # Use to specify the settings of the index.
    settings = {}

    # Use to specify a callable that say if the instance should be indexed.
    # The attribute should be a callable that returns a boolean.
    should_index = None

    # Instance of the index from algoliasearch client
    __index = None

    def __init__(self, model, client):
        '''Initializes the index.'''
        self.model = model
        self.__client = client
        self.__set_index(client)

        all_fields = model._meta.get_all_field_names()

        # Avoid error when there is only one field to index
        if isinstance(self.fields, str):
            self.fields = (self.fields, )

        # Check fields
        for field in self.fields:
            if not (hasattr(model, field) or (field in all_fields)):
                raise AlgoliaIndexError(
                    '{} is not an attribute of {}.'.format(field, model))

        # If no fields are specified, index all the fields of the model
        if not self.fields:
            self.fields = all_fields
            self.fields.remove('id')

        # Check custom_objectID
        if self.custom_objectID:
            if not (hasattr(model, self.custom_objectID) or
                    (self.custom_objectID in all_fields)):
                raise AlgoliaIndexError('{} is not an attribute of {}.'.format(
                    self.custom_objectID, model))

        # Check tags
        if self.tags:
            if not (hasattr(model, self.tags) or (self.tags in all_fields)):
                raise AlgoliaIndexError('{} is not an attribute of {}'.format(
                    self.tags, model))

        # Check geo_field
        if self.geo_field:
            if hasattr(model, self.geo_field):
                attr = getattr(model, self.geo_field)
                if not callable(attr):
                    raise AlgoliaIndexError('{} should be a callable.'.format(
                        self.geo_field))
            else:
                raise AlgoliaIndexError('{} is not an attribute of {}.'.format(
                    self.geo_field, model))

        if self.should_index:
            if hasattr(model, self.should_index):
                attr = getattr(model, self.should_index)
                if not callable(attr):
                    raise AlgoliaIndexError('{} should be a callable.'.format(
                        self.should_index))
            else:
                raise AlgoliaIndexError('{} is not an attribute of {}.'.format(
                    self.should_index, model))

    def __set_index(self, client):
        '''Get an instance of Algolia Index'''
        params = getattr(settings, 'ALGOLIA', None)

        if not self.index_name:
            self.index_name = self.model.__name__

        if params:
            if 'INDEX_PREFIX' in params:
                self.index_name = params['INDEX_PREFIX'] + '_' + self.index_name
            if 'INDEX_SUFFIX' in params:
                self.index_name += '_' + params['INDEX_SUFFIX']
        else:
            # @Deprecated: 1.1.0
            if hasattr(settings, 'ALGOLIA_INDEX_PREFIX'):
                self.index_name = settings.ALGOLIA_INDEX_PREFIX + '_' + self.index_name
            if hasattr(settings, 'ALGOLIA_INDEX_SUFFIX'):
                self.index_name += '_' + settings.ALGOLIA_INDEX_SUFFIX

        self.__index = client.init_index(self.index_name)
        self.__tmp_index = client.init_index(self.index_name + '_tmp')

    def __get_objectID(self, instance):
        '''Return the objectID of an instance.'''
        if self.custom_objectID:
            attr = getattr(instance, self.custom_objectID)
            if callable(attr):
                attr = attr()
            return attr
        else:
            return instance.pk

    def _build_object(self, instance):
        '''Build the JSON object.'''
        tmp = {'objectID': self.__get_objectID(instance)}
        if isinstance(self.fields, dict):
            for key, value in self.fields.items():
                attr = getattr(instance, key)
                if callable(attr):
                    attr = attr()
                tmp[value] = attr
        else:
            for field in self.fields:
                attr = getattr(instance, field)
                if callable(attr):
                    attr = attr()
                tmp[field] = attr

        if self.geo_field:
            attr = getattr(instance, self.geo_field)
            if callable(attr):
                attr = attr()
            tmp['_geoloc'] = {'lat': attr[0], 'lng': attr[1]}

        if self.tags:
            attr = getattr(instance, self.tags)
            if callable(attr):
                attr = attr()
            if not isinstance(attr, list):
                attr = list(attr)
            tmp['_tags'] = attr

        logger.debug('BUILD %s FROM %s', tmp['objectID'], self.model)
        return tmp

    def update_obj_index(self, instance):
        '''Update the object.'''
        if self.should_index:
            attr = getattr(instance, self.should_index)
            if not attr():
                # Should not index, but since we don't now the state of the
                # instance, we need to send a DELETE request to ensure that if
                # the instance was previously indexed, it will be removed.
                self.delete_obj_index(self, instance)
                return

        obj = self._build_object(instance)
        self.__index.save_object(obj)
        logger.debug('UPDATE %s FROM %s', obj['objectID'], self.model)

    def delete_obj_index(self, instance):
        '''Delete the object.'''
        objectID = self.__get_objectID(instance)
        self.__index.delete_object(objectID)
        logger.debug('DELETE %s FROM %s', objectID, self.model)

    def raw_search(self, query='', params={}):
        return self.__index.search(query, params)

    def set_settings(self):
        '''Apply the settings to the index.'''
        if self.settings:
            self.__index.set_settings(self.settings)
            logger.debug('APPLY SETTINGS ON %s', self.index_name)

    def clear_index(self):
        '''Clear the index.'''
        self.__index.clear_index()
        logger.debug('CLEAR INDEX %s', self.index_name)

    def reindex_all(self, batch_size=1000):
        '''Reindex all records.'''
        if self.settings:
            self.__tmp_index.set_settings(self.settings)
            logger.debug('APPLY SETTINGS ON %s_tmp', self.index_name)
        self.__tmp_index.clear_index()
        logger.debug('CLEAR INDEX %s_tmp', self.index_name)

        result = None
        counts = 0
        batch = []
        for instance in self.model.objects.all():
            if self.should_index:
                attr = getattr(instance, self.should_index)
                if not attr():
                    continue # should not index

            batch.append(self._build_object(instance))
            if len(batch) >= batch_size:
                result = self.__tmp_index.save_objects(batch)
                logger.info('SAVE %d OBJECTS TO %s_tmp', len(batch),
                            self.index_name)
                batch = []
            counts += 1
        if len(batch) > 0:
            result = self.__tmp_index.save_objects(batch)
            logger.info('SAVE %d OBJECTS TO %s_tmp', len(batch),
                        self.index_name)
        if result:
            self.__client.move_index(self.index_name + '_tmp', self.index_name)
            logger.info('MOVE INDEX %s_tmp TO %s', self.index_name,
                        self.index_name)
        return counts
<commit_msg>little optimization<commit_after>from __future__ import unicode_literals

import logging

from django.conf import settings
from django.db import models

from algoliasearch import algoliasearch

logger = logging.getLogger(__name__)

class AlgoliaIndexError(Exception):
    '''Something went wrong with an Algolia Index.'''

class AlgoliaIndex(object):
    '''An index in the Algolia backend.'''

    # Use to specify a custom field that will be used for the objectID.
    # This field should be unique.
    custom_objectID = None

    # Use to specify the fields that should be included in the index.
    fields = ()

    # Use to specify the geo-fields that should be used for location search.
    # The attribute should be a callable that returns a tuple.
    geo_field = None

    # Use to specify the field that should be used for filtering by tag.
    tags = None

    # Use to specify the index to target on Algolia.
    index_name = None

    # Use to specify the settings of the index.
    settings = {}

    # Use to specify a callable that say if the instance should be indexed.
    # The attribute should be a callable that returns a boolean.
    should_index = None

    # Instance of the index from algoliasearch client
    __index = None

    def __init__(self, model, client):
        '''Initializes the index.'''
        self.model = model
        self.__client = client
        self.__set_index(client)

        all_fields = model._meta.get_all_field_names()

        # Avoid error when there is only one field to index
        if isinstance(self.fields, str):
            self.fields = (self.fields, )

        # Check fields
        for field in self.fields:
            if not (hasattr(model, field) or (field in all_fields)):
                raise AlgoliaIndexError(
                    '{} is not an attribute of {}.'.format(field, model))

        # If no fields are specified, index all the fields of the model
        if not self.fields:
            self.fields = all_fields
            self.fields.remove('id')

        # Check custom_objectID
        if self.custom_objectID:
            if not (hasattr(model, self.custom_objectID) or
                    (self.custom_objectID in all_fields)):
                raise AlgoliaIndexError('{} is not an attribute of {}.'.format(
                    self.custom_objectID, model))

        # Check tags
        if self.tags:
            if not (hasattr(model, self.tags) or (self.tags in all_fields)):
                raise AlgoliaIndexError('{} is not an attribute of {}'.format(
                    self.tags, model))

        # Check geo_field + get the callable
        if self.geo_field:
            if hasattr(model, self.geo_field):
                attr = getattr(model, self.geo_field)
                if callable(attr):
                    self.geo_field = attr
                else:
                    raise AlgoliaIndexError('{} should be a callable.'.format(
                        self.geo_field))
            else:
                raise AlgoliaIndexError('{} is not an attribute of {}.'.format(
                    self.geo_field, model))

        # Check should_index + get the callable
        if self.should_index:
            if hasattr(model, self.should_index):
                attr = getattr(model, self.should_index)
                if callable(attr):
                    self.should_index = attr
                else:
                    raise AlgoliaIndexError('{} should be a callable.'.format(
                        self.should_index))
            else:
                raise AlgoliaIndexError('{} is not an attribute of {}.'.format(
                    self.should_index, model))

    def __set_index(self, client):
        '''Get an instance of Algolia Index'''
        params = getattr(settings, 'ALGOLIA', None)

        if not self.index_name:
            self.index_name = self.model.__name__

        if params:
            if 'INDEX_PREFIX' in params:
                self.index_name = params['INDEX_PREFIX'] + '_' + self.index_name
            if 'INDEX_SUFFIX' in params:
                self.index_name += '_' + params['INDEX_SUFFIX']
        else:
            # @Deprecated: 1.1.0
            if hasattr(settings, 'ALGOLIA_INDEX_PREFIX'):
                self.index_name = settings.ALGOLIA_INDEX_PREFIX + '_' + self.index_name
            if hasattr(settings, 'ALGOLIA_INDEX_SUFFIX'):
                self.index_name += '_' + settings.ALGOLIA_INDEX_SUFFIX

        self.__index = client.init_index(self.index_name)
        self.__tmp_index = client.init_index(self.index_name + '_tmp')

    def __get_objectID(self, instance):
        '''Return the objectID of an instance.'''
        if self.custom_objectID:
            attr = getattr(instance, self.custom_objectID)
            if callable(attr):
                attr = attr()
            return attr
        else:
            return instance.pk

    def _build_object(self, instance):
        '''Build the JSON object.'''
        tmp = {'objectID': self.__get_objectID(instance)}
        if isinstance(self.fields, dict):
            for key, value in self.fields.items():
                attr = getattr(instance, key)
                if callable(attr):
                    attr = attr()
                tmp[value] = attr
        else:
            for field in self.fields:
                attr = getattr(instance, field)
                if callable(attr):
                    attr = attr()
                tmp[field] = attr

        if self.geo_field:
            loc = self.geo_field(instance)
            tmp['_geoloc'] = {'lat': loc[0], 'lng': loc[1]}

        if self.tags:
            attr = getattr(instance, self.tags)
            if callable(attr):
                attr = attr()
            if not isinstance(attr, list):
                attr = list(attr)
            tmp['_tags'] = attr

        logger.debug('BUILD %s FROM %s', tmp['objectID'], self.model)
        return tmp

    def update_obj_index(self, instance):
        '''Update the object.'''
        if self.should_index:
            if not self.should_index(instance):
                # Should not index, but since we don't now the state of the
                # instance, we need to send a DELETE request to ensure that if
                # the instance was previously indexed, it will be removed.
                self.delete_obj_index(self, instance)
                return

        obj = self._build_object(instance)
        self.__index.save_object(obj)
        logger.debug('UPDATE %s FROM %s', obj['objectID'], self.model)

    def delete_obj_index(self, instance):
        '''Delete the object.'''
        objectID = self.__get_objectID(instance)
        self.__index.delete_object(objectID)
        logger.debug('DELETE %s FROM %s', objectID, self.model)

    def raw_search(self, query='', params={}):
        '''Return the raw JSON.'''
        return self.__index.search(query, params)

    def set_settings(self):
        '''Apply the settings to the index.'''
        if self.settings:
            self.__index.set_settings(self.settings)
            logger.debug('APPLY SETTINGS ON %s', self.index_name)

    def clear_index(self):
        '''Clear the index.'''
        self.__index.clear_index()
        logger.debug('CLEAR INDEX %s', self.index_name)

    def reindex_all(self, batch_size=1000):
        '''Reindex all records.'''
        if self.settings:
            self.__tmp_index.set_settings(self.settings)
            logger.debug('APPLY SETTINGS ON %s_tmp', self.index_name)
        self.__tmp_index.clear_index()
        logger.debug('CLEAR INDEX %s_tmp', self.index_name)

        result = None
        counts = 0
        batch = []
        for instance in self.model.objects.all():
            if self.should_index:
                if not self.should_index(instance):
                    continue # should not index

            batch.append(self._build_object(instance))
            if len(batch) >= batch_size:
                result = self.__tmp_index.save_objects(batch)
                logger.info('SAVE %d OBJECTS TO %s_tmp', len(batch),
                            self.index_name)
                batch = []
            counts += 1
        if len(batch) > 0:
            result = self.__tmp_index.save_objects(batch)
            logger.info('SAVE %d OBJECTS TO %s_tmp', len(batch),
                        self.index_name)
        if result:
            self.__client.move_index(self.index_name + '_tmp', self.index_name)
            logger.info('MOVE INDEX %s_tmp TO %s', self.index_name,
                        self.index_name)
        return counts
<|endoftext|>