#!/usr/bin/env python
"""
Installation script:

To release a new version to PyPi:
- Ensure the version is correctly set in oscar.__init__.py
- Run: make release
"""
import os
import re
import sys

from setuptools import find_packages, setup

PROJECT_DIR = os.path.dirname(__file__)
PY3 = sys.version_info >= (3, 0)

sys.path.append(os.path.join(PROJECT_DIR, 'src'))
from oscar import get_version  # noqa isort:skip

install_requires = [
    'django>=1.11,<2.1',
    # PIL is required for image fields, Pillow is the "friendly" PIL fork
    'pillow>=4.0',
    # We use the ModelFormSetView from django-extra-views for the basket page
    'django-extra-views>=0.2,<0.11',
    # Search support
    'django-haystack>=2.5.0,<3.0.0',
    # Treebeard is used for categories
    'django-treebeard>=4.3.0',
    # Sorl is used as the default thumbnailer
    'sorl-thumbnail>=12.4.1,<12.5',
    # Babel is used for currency formatting
    'Babel>=1.0,<3.0',
    # For converting non-ASCII to ASCII when creating slugs
    'Unidecode>=1.0,<1.1',
    # For manipulating search URLs
    'purl>=0.7',
    # For phone number field
    'django-phonenumber-field>=2.0,<2.1',
    # Used for oscar.test.contextmanagers.mock_signal_receiver
    'mock>=1.0.1,<3.0',
    # Used for oscar.test.newfactories
    'factory-boy>=2.4.1,<3.0',
    # Used for automatically building larger HTML tables
    'django-tables2>=1.19,<2.0',
    # Used for manipulating form field attributes in templates (eg: add
    # a css class)
    'django-widget-tweaks>=1.4.1',
]

docs_requires = [
    'Sphinx==1.7.2',
    'sphinxcontrib-napoleon==0.6.1',
    'sphinx_rtd_theme==0.3.0',
    'sphinx-issues==0.4.0',
]

test_requires = [
    'WebTest>=2.0,<2.1',
    'coverage>=4.5,<4.6',
    'django-webtest==1.9.2',
    'py>=1.4.31',
    'psycopg2>=2.7,<2.8',
    'pytest>=3.5,<3.6',
    'pytest-cov==2.5.1',
    'pytest-django==3.1.2',
    'pytest-xdist>=1.22<1.23',
    'tox>=3.0,<3.1',
]

with open(os.path.join(PROJECT_DIR, 'README.rst')) as fh:
    long_description = re.sub(
        '^.. start-no-pypi.*^.. end-no-pypi', '', fh.read(), flags=re.M | re.S)

setup(
    name='django-oscar',
    version=get_version().replace(' ', '-'),
    url='https://github.com/django-oscar/django-oscar',
    author="David Winterbottom",
    author_email="david.winterbottom@gmail.com",
    description="A domain-driven e-commerce framework for Django",
    long_description=long_description,
    keywords="E-commerce, Django, domain-driven",
    license='BSD',
    platforms=['linux'],
    package_dir={'': 'src'},
    packages=find_packages('src'),
    include_package_data=True,
    install_requires=install_requires,
    extras_require={
        'docs': docs_requires,
        'test': test_requires,
    },
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'Framework :: Django',
        'Framework :: Django :: 1.11',
        'Framework :: Django :: 2.0',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: Unix',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Topic :: Software Development :: Libraries :: Application Frameworks']
)

# Show contributing instructions if being installed in 'develop' mode
if len(sys.argv) > 1 and sys.argv[1] == 'develop':
    docs_url = 'https://django-oscar.readthedocs.io/en/latest/internals/contributing/index.html'
    mailing_list = 'django-oscar@googlegroups.com'
    mailing_list_url = 'https://groups.google.com/forum/?fromgroups#!forum/django-oscar'
    twitter_url = 'https://twitter.com/django_oscar'
    msg = (
        "You're installing Oscar in 'develop' mode so I presume you're thinking\n"
        "of contributing:\n\n"
        "(a) That's brilliant - thank you for your time\n"
        "(b) If you have any questions, please use the mailing list:\n    %s\n"
        "    %s\n"
        "(c) There are more detailed contributing guidelines that you should "
        "have a look at:\n    %s\n"
        "(d) Consider following @django_oscar on Twitter to stay up-to-date\n"
        "    %s\n\nHappy hacking!") % (mailing_list, mailing_list_url,
                                       docs_url, twitter_url)
    line = '=' * 82
    print(("\n%s\n%s\n%s" % (line, msg, line)))

setup.py
#!/usr/bin/env python
"""
Installation script:

To release a new version to PyPi:
- Ensure the version is correctly set in oscar.__init__.py
- Run: make release
"""
import os
import re
import sys

from setuptools import find_packages, setup

PROJECT_DIR = os.path.dirname(__file__)
PY3 = sys.version_info >= (3, 0)

sys.path.append(os.path.join(PROJECT_DIR, 'src'))
from oscar import get_version  # noqa isort:skip

install_requires = [
    'django>=1.11,<2.1',
    # PIL is required for image fields, Pillow is the "friendly" PIL fork
    'pillow>=4.0',
    # We use the ModelFormSetView from django-extra-views for the basket page
    'django-extra-views>=0.2,<0.11',
    # Search support
    'django-haystack>=2.5.0,<3.0.0',
    # Treebeard is used for categories
    'django-treebeard>=4.3.0',
    # Sorl is used as the default thumbnailer
    'sorl-thumbnail>=12.4.1,<12.5',
    # Babel is used for currency formatting
    'Babel>=1.0,<3.0',
    # For converting non-ASCII to ASCII when creating slugs
    'Unidecode>=1.0,<1.1',
    # For manipulating search URLs
    'purl>=0.7',
    # For phone number field
    'phonenumbers',
    'django-phonenumber-field>=2.0,<2.1',
    # Used for oscar.test.contextmanagers.mock_signal_receiver
    'mock>=1.0.1,<3.0',
    # Used for oscar.test.newfactories
    'factory-boy>=2.4.1,<3.0',
    # Used for automatically building larger HTML tables
    'django-tables2>=1.19,<2.0',
    # Used for manipulating form field attributes in templates (eg: add
    # a css class)
    'django-widget-tweaks>=1.4.1',
]

docs_requires = [
    'Sphinx==1.7.2',
    'sphinxcontrib-napoleon==0.6.1',
    'sphinx_rtd_theme==0.3.0',
    'sphinx-issues==0.4.0',
]

test_requires = [
    'WebTest>=2.0,<2.1',
    'coverage>=4.5,<4.6',
    'django-webtest==1.9.2',
    'py>=1.4.31',
    'psycopg2>=2.7,<2.8',
    'pytest>=3.5,<3.6',
    'pytest-cov==2.5.1',
    'pytest-django==3.1.2',
    'pytest-xdist>=1.22<1.23',
    'tox>=3.0,<3.1',
]

with open(os.path.join(PROJECT_DIR, 'README.rst')) as fh:
    long_description = re.sub(
        '^.. start-no-pypi.*^.. end-no-pypi', '', fh.read(), flags=re.M | re.S)

setup(
    name='django-oscar',
    version=get_version().replace(' ', '-'),
    url='https://github.com/django-oscar/django-oscar',
    author="David Winterbottom",
    author_email="david.winterbottom@gmail.com",
    description="A domain-driven e-commerce framework for Django",
    long_description=long_description,
    keywords="E-commerce, Django, domain-driven",
    license='BSD',
    platforms=['linux'],
    package_dir={'': 'src'},
    packages=find_packages('src'),
    include_package_data=True,
    install_requires=install_requires,
    extras_require={
        'docs': docs_requires,
        'test': test_requires,
    },
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'Framework :: Django',
        'Framework :: Django :: 1.11',
        'Framework :: Django :: 2.0',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: Unix',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Topic :: Software Development :: Libraries :: Application Frameworks']
)

# Show contributing instructions if being installed in 'develop' mode
if len(sys.argv) > 1 and sys.argv[1] == 'develop':
    docs_url = 'https://django-oscar.readthedocs.io/en/latest/internals/contributing/index.html'
    mailing_list = 'django-oscar@googlegroups.com'
    mailing_list_url = 'https://groups.google.com/forum/?fromgroups#!forum/django-oscar'
    twitter_url = 'https://twitter.com/django_oscar'
    msg = (
        "You're installing Oscar in 'develop' mode so I presume you're thinking\n"
        "of contributing:\n\n"
        "(a) That's brilliant - thank you for your time\n"
        "(b) If you have any questions, please use the mailing list:\n    %s\n"
        "    %s\n"
        "(c) There are more detailed contributing guidelines that you should "
        "have a look at:\n    %s\n"
        "(d) Consider following @django_oscar on Twitter to stay up-to-date\n"
        "    %s\n\nHappy hacking!") % (mailing_list, mailing_list_url,
                                       docs_url, twitter_url)
    line = '=' * 82
    print(("\n%s\n%s\n%s" % (line, msg, line)))

setup.py
diff --git a/setup.py b/setup.py
index 1d06d4c1350..8606d593c46 100755
--- a/setup.py
+++ b/setup.py
@@ -37,6 +37,7 @@
     # For manipulating search URLs
     'purl>=0.7',
     # For phone number field
+    'phonenumbers',
     'django-phonenumber-field>=2.0,<2.1',
     # Used for oscar.test.contextmanagers.mock_signal_receiver
     'mock>=1.0.1,<3.0',

ImportError: No module named 'phonenumbers'
Hi!

I'm trying to start a project from the beginning with `1.6rc1` version with python 3.5.0
```
virtualenv venv 
source venv/bin/activate
pip install django-oscar==1.6rc1
django-admin.py startproject mycommerce .
```
...
Edit settings with https://django-oscar.readthedocs.io/en/latest/internals/getting_started.html

Everything is the same for django 2.0 except for the urls:
```
from django.contrib import admin
from django.urls import path, include
from oscar.app import application

urlpatterns = [
    path('i18n/', include('django.conf.urls.i18n')),

    # The Django admin is not officially supported; expect breakage.
    # Nonetheless, it's often useful for debugging.
    path('admin/', include(admin.site.urls)),

    path('', include(application.urls)),
]
```
But when i execute `python manage.py showmigrations` i get the error `ImportError: No module named 'phonenumbers'`.

This is the complete traceback:
```
Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 347, in execute
    django.setup()
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/django/apps/registry.py", line 112, in populate
    app_config.import_models()
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/andres/mycommerce/venv/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/oscar/apps/address/models.py", line 1, in <module>
    from oscar.apps.address.abstract_models import (
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/oscar/apps/address/abstract_models.py", line 11, in <module>
    from phonenumber_field.modelfields import PhoneNumberField
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/phonenumber_field/modelfields.py", line 8, in <module>
    from phonenumber_field import formfields
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/phonenumber_field/formfields.py", line 9, in <module>
    from phonenumber_field.phonenumber import to_python
  File "/Users/andres/mycommerce/venv/lib/python3.5/site-packages/phonenumber_field/phonenumber.py", line 5, in <module>
    import phonenumbers
ImportError: No module named 'phonenumbers'
```

Thanks in advance :).

Andrés.

