Skip to content

Commit

Permalink
Add experimental support for pipenv
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Mar 18, 2019
1 parent 9fec66d commit 03512ea
Show file tree
Hide file tree
Showing 39 changed files with 137 additions and 16 deletions.
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
17 changes: 12 additions & 5 deletions djangocms_installer/install/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,24 @@ def check_install(config_data):
raise EnvironmentError('\n'.join(errors))


def requirements(req_file, pip_options='', is_file=False, verbose=False):
def requirements(
req_file, options='', is_file=False, verbose=False, pip_replacement=None
):
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 options:
args.extend([opt for opt in 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
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
19 changes: 14 additions & 5 deletions djangocms_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ def execute():
'If I am stuck for a long time, please check for connectivity / PyPi issues\n'
)
if not config_data.no_deps:
if config_data.pipenv:
pip_replacement = config_data.pipenv
options = '--dev %s' % config_data.pipenv_options
else:
pip_replacement = None
options = config_data.pip_options
if config_data.requirements_file:
install.requirements(
config_data.requirements_file, config_data.pip_options, True,
verbose=config_data.verbose
config_data.requirements_file, options, True,
verbose=config_data.verbose, pip_replacement=pip_replacement
)
else:
install.requirements(
config_data.requirements, config_data.pip_options,
verbose=config_data.verbose
config_data.requirements, options,
verbose=config_data.verbose, pip_replacement=pip_replacement
)
sys.stdout.write('Dependencies installed\nCreating the project\n')
install.check_install(config_data)
Expand All @@ -44,7 +50,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/
2 changes: 2 additions & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,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 =
3 changes: 2 additions & 1 deletion tests/fixtures/configs/config-30.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ no-plugins = true
verbose = true
wizard = false
delete-project-dir = false

pipenv =
pipenv-options =
2 changes: 2 additions & 0 deletions tests/fixtures/configs/config-32.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ no-plugins = true
verbose = true
wizard = false
delete-project-dir = true
pipenv =
pipenv-options =

0 comments on commit 03512ea

Please sign in to comment.