Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix dependencies overhead #2346

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Now see how you could test it with Moto:

```python
import boto3
from moto import mock_s3
from moto.s3 import mock_s3
from mymodule import MyModel


Expand Down Expand Up @@ -168,7 +168,7 @@ To test it:

```python
from . import add_servers
from moto import mock_ec2
from moto.ec2 import mock_ec2

@mock_ec2
def test_add_servers():
Expand All @@ -186,7 +186,7 @@ moto 1.0.X mock decorators are defined for boto3 and do not work with boto2. Use

Using moto with boto2
```python
from moto import mock_ec2_deprecated
from moto.ec2 import mock_ec2_deprecated
import boto

@mock_ec2_deprecated
Expand All @@ -198,8 +198,8 @@ def test_something_with_ec2():

When using both boto2 and boto3, one can do this to avoid confusion:
```python
from moto import mock_ec2_deprecated as mock_ec2_b2
from moto import mock_ec2
from moto.ec2 import mock_ec2_deprecated as mock_ec2_b2
from moto.ec2 import mock_ec2

```

Expand Down
2 changes: 1 addition & 1 deletion docs/_build/html/_sources/docs/getting_started.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ With a decorator wrapping all the calls to S3 are automatically mocked out.
.. sourcecode:: python

import boto
from moto import mock_s3
from moto.s3 import mock_s3
from mymodule import MyModel

@mock_s3
Expand Down
2 changes: 1 addition & 1 deletion docs/_build/html/_sources/getting_started.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ With a decorator wrapping all the calls to S3 are automatically mocked out.
.. sourcecode:: python

import boto
from moto import mock_s3
from moto.s3 import mock_s3
from mymodule import MyModel

@mock_s3
Expand Down
2 changes: 1 addition & 1 deletion docs/_build/html/_sources/getting_started.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ With a decorator wrapping all the calls to S3 are automatically mocked out.
.. sourcecode:: python

import boto
from moto import mock_s3
from moto.s3 import mock_s3
from mymodule import MyModel

@mock_s3
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ With a decorator wrapping, all the calls to S3 are automatically mocked out.
.. sourcecode:: python

import boto
from moto import mock_s3
from moto.s3 import mock_s3
from mymodule import MyModel

@mock_s3
Expand Down
50 changes: 1 addition & 49 deletions moto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,10 @@
from __future__ import unicode_literals
import logging
# import logging
# logging.getLogger('boto').setLevel(logging.CRITICAL)

__title__ = 'moto'
__version__ = '1.3.14.dev'

from .acm import mock_acm # flake8: noqa
from .apigateway import mock_apigateway, mock_apigateway_deprecated # flake8: noqa
from .autoscaling import mock_autoscaling, mock_autoscaling_deprecated # flake8: noqa
from .awslambda import mock_lambda, mock_lambda_deprecated # flake8: noqa
from .cloudformation import mock_cloudformation, mock_cloudformation_deprecated # flake8: noqa
from .cloudwatch import mock_cloudwatch, mock_cloudwatch_deprecated # flake8: noqa
from .cognitoidentity import mock_cognitoidentity, mock_cognitoidentity_deprecated # flake8: noqa
from .cognitoidp import mock_cognitoidp, mock_cognitoidp_deprecated # flake8: noqa
from .config import mock_config # flake8: noqa
from .datapipeline import mock_datapipeline, mock_datapipeline_deprecated # flake8: noqa
from .dynamodb import mock_dynamodb, mock_dynamodb_deprecated # flake8: noqa
from .dynamodb2 import mock_dynamodb2, mock_dynamodb2_deprecated # flake8: noqa
from .dynamodbstreams import mock_dynamodbstreams # flake8: noqa
from .ec2 import mock_ec2, mock_ec2_deprecated # flake8: noqa
from .ecr import mock_ecr, mock_ecr_deprecated # flake8: noqa
from .ecs import mock_ecs, mock_ecs_deprecated # flake8: noqa
from .elb import mock_elb, mock_elb_deprecated # flake8: noqa
from .elbv2 import mock_elbv2 # flake8: noqa
from .emr import mock_emr, mock_emr_deprecated # flake8: noqa
from .events import mock_events # flake8: noqa
from .glacier import mock_glacier, mock_glacier_deprecated # flake8: noqa
from .glue import mock_glue # flake8: noqa
from .iam import mock_iam, mock_iam_deprecated # flake8: noqa
from .kinesis import mock_kinesis, mock_kinesis_deprecated # flake8: noqa
from .kms import mock_kms, mock_kms_deprecated # flake8: noqa
from .organizations import mock_organizations # flake8: noqa
from .opsworks import mock_opsworks, mock_opsworks_deprecated # flake8: noqa
from .polly import mock_polly # flake8: noqa
from .rds import mock_rds, mock_rds_deprecated # flake8: noqa
from .rds2 import mock_rds2, mock_rds2_deprecated # flake8: noqa
from .redshift import mock_redshift, mock_redshift_deprecated # flake8: noqa
from .resourcegroups import mock_resourcegroups # flake8: noqa
from .s3 import mock_s3, mock_s3_deprecated # flake8: noqa
from .ses import mock_ses, mock_ses_deprecated # flake8: noqa
from .secretsmanager import mock_secretsmanager # flake8: noqa
from .sns import mock_sns, mock_sns_deprecated # flake8: noqa
from .sqs import mock_sqs, mock_sqs_deprecated # flake8: noqa
from .sts import mock_sts, mock_sts_deprecated # flake8: noqa
from .ssm import mock_ssm # flake8: noqa
from .route53 import mock_route53, mock_route53_deprecated # flake8: noqa
from .swf import mock_swf, mock_swf_deprecated # flake8: noqa
from .xray import mock_xray, mock_xray_client, XRaySegment # flake8: noqa
from .logs import mock_logs, mock_logs_deprecated # flake8: noqa
from .batch import mock_batch # flake8: noqa
from .resourcegroupstaggingapi import mock_resourcegroupstaggingapi # flake8: noqa
from .iot import mock_iot # flake8: noqa
from .iotdata import mock_iotdata # flake8: noqa


try:
# Need to monkey-patch botocore requests back to underlying urllib3 classes
Expand Down
163 changes: 64 additions & 99 deletions moto/backends.py
Original file line number Diff line number Diff line change
@@ -1,109 +1,74 @@
from __future__ import unicode_literals
import importlib

from moto.acm import acm_backends
from moto.apigateway import apigateway_backends
from moto.autoscaling import autoscaling_backends
from moto.awslambda import lambda_backends
from moto.cloudformation import cloudformation_backends
from moto.cloudwatch import cloudwatch_backends
from moto.cognitoidentity import cognitoidentity_backends
from moto.cognitoidp import cognitoidp_backends
from moto.core import moto_api_backends
from moto.datapipeline import datapipeline_backends
from moto.dynamodb import dynamodb_backends
from moto.dynamodb2 import dynamodb_backends2
from moto.dynamodbstreams import dynamodbstreams_backends
from moto.ec2 import ec2_backends
from moto.ecr import ecr_backends
from moto.ecs import ecs_backends
from moto.elb import elb_backends
from moto.elbv2 import elbv2_backends
from moto.emr import emr_backends
from moto.events import events_backends
from moto.glacier import glacier_backends
from moto.glue import glue_backends
from moto.iam import iam_backends
from moto.instance_metadata import instance_metadata_backends
from moto.kinesis import kinesis_backends
from moto.kms import kms_backends
from moto.logs import logs_backends
from moto.opsworks import opsworks_backends
from moto.organizations import organizations_backends
from moto.polly import polly_backends
from moto.rds2 import rds2_backends
from moto.redshift import redshift_backends
from moto.resourcegroups import resourcegroups_backends
from moto.route53 import route53_backends
from moto.s3 import s3_backends
from moto.ses import ses_backends
from moto.secretsmanager import secretsmanager_backends
from moto.sns import sns_backends
from moto.sqs import sqs_backends
from moto.ssm import ssm_backends
from moto.sts import sts_backends
from moto.swf import swf_backends
from moto.xray import xray_backends
from moto.iot import iot_backends
from moto.iotdata import iotdata_backends
from moto.batch import batch_backends
from moto.resourcegroupstaggingapi import resourcegroupstaggingapi_backends
from moto.config import config_backends

BACKENDS = {
'acm': acm_backends,
'apigateway': apigateway_backends,
'autoscaling': autoscaling_backends,
'batch': batch_backends,
'cloudformation': cloudformation_backends,
'cloudwatch': cloudwatch_backends,
'cognito-identity': cognitoidentity_backends,
'cognito-idp': cognitoidp_backends,
'config': config_backends,
'datapipeline': datapipeline_backends,
'dynamodb': dynamodb_backends,
'dynamodb2': dynamodb_backends2,
'dynamodbstreams': dynamodbstreams_backends,
'ec2': ec2_backends,
'ecr': ecr_backends,
'ecs': ecs_backends,
'elb': elb_backends,
'elbv2': elbv2_backends,
'events': events_backends,
'emr': emr_backends,
'glacier': glacier_backends,
'glue': glue_backends,
'iam': iam_backends,
'moto_api': moto_api_backends,
'instance_metadata': instance_metadata_backends,
'logs': logs_backends,
'kinesis': kinesis_backends,
'kms': kms_backends,
'opsworks': opsworks_backends,
'organizations': organizations_backends,
'polly': polly_backends,
'redshift': redshift_backends,
'resource-groups': resourcegroups_backends,
'rds': rds2_backends,
's3': s3_backends,
's3bucket_path': s3_backends,
'ses': ses_backends,
'secretsmanager': secretsmanager_backends,
'sns': sns_backends,
'sqs': sqs_backends,
'ssm': ssm_backends,
'sts': sts_backends,
'swf': swf_backends,
'route53': route53_backends,
'lambda': lambda_backends,
'xray': xray_backends,
'resourcegroupstaggingapi': resourcegroupstaggingapi_backends,
'iot': iot_backends,
'iot-data': iotdata_backends,
_backends = {
'acm': 'moto.acm.acm_backends',
'apigateway': 'moto.apigateway.apigateway_backends',
'autoscaling': 'moto.autoscaling.autoscaling_backends',
'batch': 'moto.batch.batch_backends',
'cloudformation': 'moto.cloudformation.cloudformation_backends',
'cloudwatch': 'moto.cloudwatch.cloudwatch_backends',
'cognito-identity': 'moto.cognitoidentity.cognitoidentity_backends',
'cognito-idp': 'moto.cognitoidp.cognitoidp_backends',
'config': 'moto.config.config_backends',
'datapipeline': 'moto.datapipeline.datapipeline_backends',
'dynamodb': 'moto.dynamodb.dynamodb_backends',
'dynamodb2': 'moto.dynamodb2.dynamodb_backends2',
'dynamodbstreams': 'moto.dynamodbstreams.dynamodbstreams_backends',
'ec2': 'moto.ec2.ec2_backends',
'ecr': 'moto.ecr.ecr_backends',
'ecs': 'moto.ecs.ecs_backends',
'elb': 'moto.elb.elb_backends',
'elbv2': 'moto.elbv2.elbv2_backends',
'events': 'moto.events.events_backends',
'emr': 'moto.emr.emr_backends',
'glacier': 'moto.glacier.glacier_backends',
'glue': 'moto.glue.glue_backends',
'iam': 'moto.iam.iam_backends',
'moto_api': 'moto.core.moto_api_backends',
'instance_metadata': 'moto.instance_metadata.instance_metadata_backends',
'logs': 'moto.logs.logs_backends',
'kinesis': 'moto.kinesis.kinesis_backends',
'kms': 'moto.kms.kms_backends',
'opsworks': 'moto.opsworks.opsworks_backends',
'organizations': 'moto.organizations.organizations_backends',
'polly': 'moto.polly.polly_backends',
'redshift': 'moto.redshift.redshift_backends',
'resource-groups': 'moto.resourcegroups.resourcegroups_backends',
'rds': 'moto.rds2.rds2_backends',
's3': 'moto.s3.s3_backends',
's3bucket_path': 'moto.s3.s3_backends',
'ses': 'moto.ses.ses_backends',
'secretsmanager': 'moto.secretsmanager.secretsmanager_backends',
'sns': 'moto.sns.sns_backends',
'sqs': 'moto.sqs.sqs_backends',
'ssm': 'moto.ssm.ssm_backends',
'sts': 'moto.sts.sts_backends',
'swf': 'moto.swf.swf_backends',
'route53': 'moto.route53.route53_backends',
'lambda': 'moto.awslambda.lambda_backends',
'xray': 'moto.xray.xray_backends',
'resourcegroupstaggingapi': 'moto.resourcegroupstaggingapi.resourcegroupstaggingapi_backends',
'iot': 'moto.iot.iot_backends',
'iot-data': 'moto.iotdata.iotdata_backends',
}


def get_backend(backend_name):
import_path = _backends.get(backend_name)
if import_path is None:
raise ValueError(
"No such backend '%s'. Available backends are: %s" % (backend_name, ', '.join(_backends.keys()))
)
module_path, member_name = import_path.rsplit('.', 1)
module = importlib.import_module(module_path)
return getattr(module, member_name)


def get_model(name, region_name):
for backends in BACKENDS.values():
for backend_name in _backends.keys():
backends = get_backend(backend_name)
for region, backend in backends.items():
if region == region_name:
models = getattr(backend.__class__, '__models__', {})
Expand Down
14 changes: 7 additions & 7 deletions moto/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import mock
from moto import settings
import responses
from moto.backends import get_backend
from moto.packages.httpretty import HTTPretty
from .utils import (
convert_httpretty_response,
Expand All @@ -30,10 +31,9 @@ def __init__(self, backends):
self.backends = backends

self.backends_for_urls = {}
from moto.backends import BACKENDS
default_backends = {
"instance_metadata": BACKENDS['instance_metadata']['global'],
"moto_api": BACKENDS['moto_api']['global'],
"instance_metadata": get_backend('instance_metadata')['global'],
"moto_api": get_backend('moto_api')['global'],
}
self.backends_for_urls.update(self.backends)
self.backends_for_urls.update(default_backends)
Expand Down Expand Up @@ -582,11 +582,11 @@ class deprecated_base_decorator(base_decorator):
class MotoAPIBackend(BaseBackend):

def reset(self):
from moto.backends import BACKENDS
for name, backends in BACKENDS.items():
if name == "moto_api":
from moto.backends import _backends
for backend_name in _backends:
if backend_name == "moto_api":
continue
for region_name, backend in backends.items():
for _region_name, backend in get_backend(backend_name).items():
backend.reset()
self.__init__()

Expand Down
2 changes: 1 addition & 1 deletion moto/rds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import boto.rds
from jinja2 import Template

from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
from moto.core import BaseBackend, BaseModel
from moto.core.utils import get_random_hex
from moto.ec2.models import ec2_backends
Expand Down Expand Up @@ -108,6 +107,7 @@ def get_cfn_attribute(self, attribute_name):
return self.address
elif attribute_name == 'Endpoint.Port':
return self.port
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
raise UnformattedGetAttTemplateException()

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion moto/rds2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import boto.rds2
from jinja2 import Template
from re import compile as re_compile
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
from moto.compat import OrderedDict
from moto.core import BaseBackend, BaseModel
from moto.core.utils import get_random_hex
Expand Down Expand Up @@ -274,6 +273,7 @@ def get_cfn_attribute(self, attribute_name):
return self.address
elif attribute_name == 'Endpoint.Port':
return self.port
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
raise UnformattedGetAttTemplateException()

@staticmethod
Expand Down
Loading