|
| 1 | +.. _deploying-scripts: |
| 2 | + |
| 3 | +================== |
| 4 | +Deploying a Script |
| 5 | +================== |
| 6 | + |
| 7 | +Because DroneKit-Python is still under heavy development, you may find it beneficial to control which version you are using and have a plan for deployment. |
| 8 | + |
| 9 | +This section includes some tips for using `virtualenvwrapper <https://virtualenvwrapper.readthedocs.org/en/latest/>`_ (an extension of `virtualenv <https://virtualenv.readthedocs.org/en/latest/>`_) to manage versioning and deployment. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +Installing virtualenvwrapper |
| 14 | +============================ |
| 15 | + |
| 16 | +First, please follow the instructions for installing DroneKit-Python on your platform of choice under the section :ref:`getting_started_installing_dronekit` in :ref:`get-started`: |
| 17 | + |
| 18 | +* :ref:`getting_started_installing_dronekit_linux` |
| 19 | +* :ref:`getting_started_installing_dronekit_mac` |
| 20 | + |
| 21 | +.. note:: |
| 22 | + |
| 23 | + virtualenvwrapper uses functionality specific to bash, a shell commonly used in Linux and Mac. To follow this guide on Windows you can use `cygwin <https://www.cygwin.com/>`_ or `look here for more information <http://stackoverflow.com/questions/2615968/installing-virtualenvwrapper-on-windows>`_. |
| 24 | + |
| 25 | +After you have installed **pip** you can install virtualenvwrapper and its dependencies. |
| 26 | + |
| 27 | +.. code-block:: bash |
| 28 | +
|
| 29 | + sudo pip install virtualenvwrapper |
| 30 | +
|
| 31 | +Then, place |
| 32 | + |
| 33 | +.. code-block:: bash |
| 34 | +
|
| 35 | + source $(which virtualenvwrapper.sh) |
| 36 | +
|
| 37 | +into your shell startup file (most commonly **.bashrc**). |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +Working with virtualenvwrapper |
| 42 | +============================== |
| 43 | + |
| 44 | +Next, you will want to create a new virtual environment: |
| 45 | + |
| 46 | +.. code:: bash |
| 47 | +
|
| 48 | + mkvirtualenv my-dronekit-project |
| 49 | +
|
| 50 | +This will create a new virtual environment and activate it. |
| 51 | + |
| 52 | +Next, you will want to install **dronekit** into your new virtual environment. |
| 53 | + |
| 54 | +.. code:: bash |
| 55 | +
|
| 56 | + pip install dronekit |
| 57 | +
|
| 58 | +If you need to install anything else, you can use ``pip install`` as usual. |
| 59 | + |
| 60 | +.. tip:: |
| 61 | + |
| 62 | + No ``sudo`` is required because the virtual environment is installed in your home directory and only effects instances of bash under your control. |
| 63 | + |
| 64 | +When you are done working with your virtual environment, you can deactivate it to switch back to the global python environment with |
| 65 | + |
| 66 | +.. code:: bash |
| 67 | +
|
| 68 | + deactive |
| 69 | +
|
| 70 | +To work on it again use |
| 71 | + |
| 72 | +.. code:: bash |
| 73 | +
|
| 74 | + workon my-dronekit-project |
| 75 | +
|
| 76 | +.. note:: |
| 77 | + |
| 78 | + You will need to use ``workon my-dronekit-project`` on each instance of bash you wish to run your code in. |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +Deployment and Version Control |
| 83 | +============================== |
| 84 | + |
| 85 | +At any point you can write a list of every library you have installed along with its version to file by using |
| 86 | + |
| 87 | +.. code:: bash |
| 88 | +
|
| 89 | + pip freeze > requirements.txt |
| 90 | +
|
| 91 | +Later, you can tell **pip** to install those libraries at the versions listed with |
| 92 | + |
| 93 | +.. code:: bash |
| 94 | +
|
| 95 | + pip install -r requirements.txt |
| 96 | +
|
| 97 | +By using multiple virtual environments you can easily test new versions of DroneKit without the risk of breaking your project. You can also tie a **requirements.txt** to each release of your project to guarantee the appropriate version of DroneKit and any other libraries are installed, and to speed up deployment. If you use version control, you can keep requirements.txt under your version control to make it easy to install the software appropriate to any given commit. |
0 commit comments