- What this tutorial is about
- Before you start
- Preparing an example
- Configuring a deployment server
- Browsing remote hosts
- Deployment tool
- Automatic upload to the default server
- Uploading external changes
What this tutorial is about
This tutorial aims to take you step-by-step through configuring an managing deployment of your code to remote hosts, using PyCharm.
Before you start
Make sure that:
- You are working with PyCharm version 3.0 or higher
- You have access right to a remote host you want your code to be deployed.
Also note that this tutorial is created on Windows 7 and makes use of the default keyboard shortcuts scheme. If you are working on a different platform, the keyboard shortcuts will be different.
Preparing an example
You can use the everlasting sample project from Getting Started. Thus the preliminary steps are done, and we are ready to take off.
Configuring a deployment server
On the main toolbar, click to open the Settings/Preferences dialog, and choose the page Deployment (actually, you can access the same page by choosing Tools→Deployment→Configuration on the main menu).
Click , then in the Add Server dialog box, type your server name (MyRemoteServer) and select its type (in our case, this is Local or mounted folder):
OK, the new server is added, but it is still void... It only shows the Web server root URL (http://localhost), where you will actually browse your uploaded files.
What is specified in the Connection tab?
Select the directory where the project files will be uploaded. In our case, this is the local folder C:\xampp\htdocs (You can either type this path manually, or press Shift+Enter to open the Select Path dialog.) Refer to the product documentation for details.
What is specified in the Mappings tab?
Next, choose the Mappings tab. By default, the Local path field contains the project root. However, you can select any other directory within your project tree. Let's assume the default value.
In the Deployment path field (which is by default empty), you have to specify the folder on your server, where PyCharm will upload data from the folder, specified in the Local path. This path is specified relative to the folder C:\xampp\htdocs!
And, finally, let's accept the default value for Web path on the server MyRemoteServer:
OK, apply changes, and the server is ready to use.
Browsing remote hosts
You can easily make sure your server is up and running. Just open the Remote Hosts tool window (the tool window button is along the right edge of the PyCharm frame):
Alternatively, choose Tools→Deployment→Browse Remote Hosts on the main menu to show the same tool window.
Next, let's perform some actions, and see what happens.
First, let's upload one of the files to the remote server. This how it's done...
In the Project tool window, right-click a file you want to upload. In our case, let it be the file Solver.py. On the context menu, choose Deployment→Upload to MyRemoteServer - and see the upload results!
You can also upload contents of each directory within your project. For example, right-click the parent directory of the Solver.py file, namely, src, and choose Upload to MyRemoteServer on the context menu. Wow! We have the entire directory uploaded to the server:
Comparing remote and local versions
There is a local and a remote copy of the file Solver.py, and they are identical. Let's change the local version.
To do that, place the caret at the method declaration, and press Ctrl+Alt+Shift+T (or choose Refactor→Refactor This on the main menu):
As you see, the pop-up menu shows all refactorings, available in the current context. Let's choose Rename refactoring, and rename a method:
Click Do Refactor, and see the method name and its usage changed.
OK, now we've changed a local version. Let's make sure PyCharm knows about these changes. To do that, again go to the Project tool window, and right-click the Solver.py file. On the context menu, choose Deployment→Compare with Deployed Version on MyRemoteServer. PyCharm opens the differences viewer for files, where you can accept changes or reject them, using the shevron buttons:
Refer also to the product documentation for details.
Right-click Solver.py, and choose Deployment→Download from MyRemoteServer on the context menu. PyCharm immediately shows a warning:
Do not be afraid, and click Continue:
You can also download an entire directory, if it has been previously uploaded to the server. For example, if you right-click the parent directory src and choose same command, all nested files will be downloaded from the server.
However, if you try downloading a directory that has never been uploaded before, the result will be quite disappointing:
Make a preliminary step - roll the changes to the Solver.py file back (Ctrl+Z). You again see the class Solver.py with the renamed method.
Next, right-click Solver.py, and choose Deployment→Sync with Deployed to MyRemoteServer on the context menu. PyCharm shows differences viewer for folders, where you can accept individual changes or reject them, using the shevron buttons:
It is also possible to synchronize the entire folders. For example, right-click node_modules and choose Deployment→Sync with Deployed to MyRemoteServer on the context menu. The differences viewer this time shows contents of the node_modules folder in the left pane, but nothing in the right pane - because the contents of this directory has not been uploaded to the server. However, you can do it now. Select the files to be synchronized, and click on the toolbar:
Automatic upload to the default server
When a user needs to have the exact same files on the server as in a PyCharm project, automatic upload can be of help. Automatic upload means that whenever a change is saved in the IDE, it will be deployed to the default deployment server.
Defining a server as default
A deployment server is considered default, if its settings apply by default during automatic upload of changed files. To define a deployment server as the default one:
- Choose a server in the Deployment page. You can open this page it two possible ways: either Settings/Preferences→Deployment, or Tools→Deployment→Configuration on the main menu.
- On the toolbar of the server configurations list, click :
Enabling automatic upload
As soon as the default server is set, you can make upload to this server automatic. This can be done in the following ways:
- First, open the deployment Options (Settings/Preferences→Deployment→Options or Tools→Deployment→Options on the main menu), and in the field Upload files automatically to the defaylt server choose Always, or On explicit save action:
The difference between these two choices is explained in the field description.
- Second, select the check command Tools→Deployment→Automatic upload on the main menu. Note that automatic apload in this case is performed in the Always mode:
It is worth mentioning that the option Always is not recommended for deployment to production: incomplete code can be uploaded while developing, potentilly breaking the production application.
Uploading external changes
By default, PyCharm uploads only the files changed by itself. If the files are changed by some other process, such as a VCS branch change, transpilation of SASS or LESS or a File Watcher, they are not automatically uploaded. To change this behavior and autoupload these changes as well, enable the Upload external changes option: