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

Add experimental support for pipenv #342

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
History
-------

1.1.1 (unreleased)
++++++++++++++++++

* Added support for pipenv

1.1.0 (2019-03-05)
++++++++++++++++++

Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ as python executable, which is the standard virtualenv layout. Other installatio
might work, but are not officially supported.


pipenv support
--------------

A limited / experimental support to ``pipenv`` is provided.

Check documentation https://djangocms-installer.readthedocs.io/en/latest/usage.html#pipenv-support

Windows support
---------------

Expand Down
6 changes: 6 additions & 0 deletions djangocms_installer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def parse(args):
parser.add_argument('--utc', dest='utc',
action='store_true',
default=False, help='Use UTC timezone.')
parser.add_argument('--pipenv', dest='pipenv',
action='store',
default='', help='Use pipenv at given path to install dependencies.')
parser.add_argument('--pipenv-options', dest='pipenv_options',
action='store',
default='', help='Options passed to pipenv as is.')

if '--utc' in args:
for action in parser._positionals._actions:
Expand Down
43 changes: 38 additions & 5 deletions djangocms_installer/install/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,50 @@ def check_install(config_data):
raise EnvironmentError('\n'.join(errors))


def requirements(req_file, pip_options='', is_file=False, verbose=False):
def install_packages(config_data):
if not config_data.no_deps:
if config_data.requirements_file:
requirements(
config_data.requirements_file, config_data, True,
verbose=config_data.verbose
)
else:
requirements(
config_data.requirements, config_data,
verbose=config_data.verbose
)


def install_arguments(req_file, options=None, is_file=False, verbose=False):
pip_replacement = None
cmd_options = ''
if options and options.pipenv:
pip_replacement = options.pipenv
cmd_options = '--dev %s' % options.pipenv_options
elif options and options.pip_options:
cmd_options = options.pip_options
args = ['install']
if not verbose:
if not verbose and not pip_replacement:
args.append('-q')
if pip_options:
args.extend([opt for opt in pip_options.split(' ') if opt])
elif verbose and pip_replacement:
args.append('-v')
if cmd_options:
args.extend([opt for opt in cmd_options.split(' ') if opt])
if is_file: # pragma: no cover
args += ['-r', req_file]
else:
args.extend(['{0}'.format(package) for package in req_file.split()])
cmd = [sys.executable, '-mpip'] + args
if pip_replacement:
cmd = [pip_replacement] + args
else:
cmd = [sys.executable, '-mpip'] + args
return cmd


def requirements(
req_file, options=None, is_file=False, verbose=False
):
cmd = install_arguments(req_file, options, is_file, verbose)
if verbose:
sys.stdout.write('python path: {0}\n'.format(sys.executable))
sys.stdout.write('packages install command: {0}\n'.format(' '.join(cmd)))
Expand Down
17 changes: 5 additions & 12 deletions djangocms_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@ def execute():
'Please wait while I install dependencies\n'
'If I am stuck for a long time, please check for connectivity / PyPi issues\n'
)
if not config_data.no_deps:
if config_data.requirements_file:
install.requirements(
config_data.requirements_file, config_data.pip_options, True,
verbose=config_data.verbose
)
else:
install.requirements(
config_data.requirements, config_data.pip_options,
verbose=config_data.verbose
)
install.install_packages(config_data)
sys.stdout.write('Dependencies installed\nCreating the project\n')
install.check_install(config_data)
django.create_project(config_data)
Expand All @@ -44,7 +34,10 @@ def execute():
django.setup_database(config_data)
if config_data.starting_page:
django.load_starting_page(config_data)
if not config_data.requirements_file:
if (
not config_data.requirements_file and
not config_data.pipenv
):
install.write_requirements(config_data)
if config_data.aldryn: # pragma: no cover
sys.stdout.write('Project created!\n')
Expand Down
2 changes: 2 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ advanced usage:
* ``--skip-empty-check``, ``-s``: Skip the check if the project dir contains files or directory;
in case of error when setting up the project the existing directory will be preserved.
* ``--delete-project-dir``', ``-c``: Delete project directory on creation failure in :ref:`batch_mode`.
* ``--pipenv``': Full path to pipenv executable to use ``pipenv`` instead of pip for requirements installation, see :ref:`pipenv_support`.
* ``--pipenv-opts``': additional options (as a single string passed as is) passed to ``pipenv`` executable in the command line, see :ref:`pipenv_support`.



Expand Down
32 changes: 28 additions & 4 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,35 @@ You can create the base project with a custom templateset by using the ``--templ
Be aware that while **djangocms installer** will copy the files for you, it won't update the ``CMS_TEMPLATES`` settings
parameter, so you'll need to modify that after installation.

.. _complete example: https://github.com/nephila/djangocms-installer/blob/develop/config.ini.sample


Bare install
------------

You can optionally install just Django and django CMS without any additiona plugin by using the
You can optionally install just Django and django CMS without any additional plugin by using the
``--no-plugins`` option; this will allow you to further customise your installation.

.. _pipenv_support:

pipenv support
--------------

Provided that you already have `pipenv`_ installed, you can use it to install the dependencies instead of plain pip
and generate a ``Pipfile`` and ``Pipfile.lock``.

To run provide full path to ``pipenv`` executable via ``--pipenv`` argument.

You can provide additional options via ``--pipenv-opts`` argument.

You **must** create the pipenv virtualenv *before* running ``djangocms-installer`` and ``djangocms-installer`` must be installed within the ``pipenv`` virtualenv.

The currently supported workflow is:

.. code-block:: bash

$ pipenv --three
$ pipenv install djangocms-installer
$ pipenv run djangocms mysite

.. warning:: pipenv support is still experimental and **may** not work for all workflows

.. _complete example: https://github.com/nephila/djangocms-installer/blob/develop/config.ini.sample
.. _pipenv: https://pipenv.readthedocs.io/en/latest/
27 changes: 26 additions & 1 deletion tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from six import StringIO, text_type
from tzlocal import get_localzone

from djangocms_installer import config
from djangocms_installer import config, install
from djangocms_installer.config.data import CMS_VERSION_MATRIX, DJANGO_VERSION_MATRIX
from djangocms_installer.install import check_install
from djangocms_installer.utils import less_than_version, supported_versions
Expand Down Expand Up @@ -673,6 +673,29 @@ def disabled_test_aldryn_compatibility(self):
except AttributeError:
self.assertEqual(error.exception, 5)

def test_pip_cmd(self):
conf_data = config.parse([
'-q', '--pip-options=--something --other-option',
'-p'+self.project_dir,
'example_prj']
)
cmd = install.install_arguments(conf_data.requirements, conf_data)
self.assertTrue('-mpip' in cmd)
self.assertTrue('--something' in cmd)
self.assertTrue('--other-option' in cmd)

def test_pipend_cmd(self):
conf_data = config.parse([
'-q', '--pipenv=/path/pipenv', '--pipenv-options=--something --other-option',
'-p'+self.project_dir,
'example_prj']
)
cmd = install.install_arguments(conf_data.requirements, conf_data)
self.assertTrue('/path/pipenv' in cmd)
self.assertTrue('--dev' in cmd)
self.assertTrue('--something' in cmd)
self.assertTrue('--other-option' in cmd)

def test_boostrap(self):
"""
Verify handling of bootstrap parameter
Expand Down Expand Up @@ -874,6 +897,8 @@ class TestBaseConfig(unittest.TestCase):
'no_plugins': False,
'verbose': False,
'wizard': False,
'pipenv': '',
'pipenv_options': '',
'delete_project_dir': False,
})

Expand Down
2 changes: 1 addition & 1 deletion tests/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def test_patch_django_20_develop(self):
params = [
'--db=sqlite://localhost/test.db', '--lang=en', '--extra-settings=%s' % extra_path,
'--django-version=2.0', '-f', '--cms-version=develop', '--timezone=Europe/Moscow',
'-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir,
'--verbose', '-u', '-zno', '--i18n=no', '-p' + self.project_dir,
'example_path_20_develop_settings'
]
config_data = config.parse(params)
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-01.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-02.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-03.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-04.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-05.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-06.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-07.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-08.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-09.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-10.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-11.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-12.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-13.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-14.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-15.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-16.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-17.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-18.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-19.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-20.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-21.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-22.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-23.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-24.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-25.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-26.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-27.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = false
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-28.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = true
verbose = false
wizard = false
delete-project-dir = false
pipenv =
pipenv-options =
Loading