Skip to content

Commit 360d556

Browse files
author
Katie Horne
authored
chore: add guide on getting started with PyCharm (coder#872)
1 parent 71bb16c commit 360d556

File tree

4 files changed

+210
-2
lines changed

4 files changed

+210
-2
lines changed
Loading

getting-started/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ deployment available to them, these end-to-end guides will walk them through
2424
logging in and getting set up with a sample project they can use to experience
2525
Coder.
2626

27-
Additionally, we have a guide for those interested in leveraging Coder for data
28-
science, specifically using Python with Jupyter notebooks.
27+
Additionally, we have a guide for those interested in leveraging Coder for
28+
[data science](data-scientists.md), specifically using Python with Jupyter
29+
notebooks. We also have a tutorial on getting started with [PyCharm](pycharm.md)

getting-started/pycharm.md

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
---
2+
title: PyCharm
3+
description: Get started with Coder as a PyCharm user.
4+
---
5+
6+
This article will walk you through the process of getting started with a Coder
7+
workspace and a project that leverages PyCharm. You'll learn how to:
8+
9+
- Connect Coder to your Git provider;
10+
- Create a workspace;
11+
- Create your first Python project;
12+
- Push your changes to GitHub.
13+
14+
## Prerequisites
15+
16+
This guide assumes that you have a Coder deployment available to you and that
17+
you have the credentials needed to access the deployment.
18+
19+
## Step 1: Log in and connect Coder to your Git provider
20+
21+
In this step, you'll log into Coder and connect and authenticate with your Git
22+
provider. This will allow you to do things like pull repositories and push
23+
changes.
24+
25+
1. Navigate to the Coder deployment using the URL provided to you by your site
26+
manager, and log in.
27+
28+
1. Click on your avatar in the top-right, and select **Account**.
29+
30+
![Set account preferences](../assets/getting-started/account-preferences.png)
31+
32+
1. Provide Coder with your SSH key to connect and authenticate to GitHub.
33+
34+
If your site manager has configured OAuth, go to **Linked Accounts** and
35+
follow the on-screen instructions to link your GitHub account.
36+
37+
![Link GitHub account](../assets/getting-started/linked-accounts.png)
38+
39+
If your site manager has _not_ configured OAuth, go to **SSH keys**. Copy
40+
your public SSH key and
41+
[provide it to GitHub](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).
42+
43+
![Add SSH key](../assets/getting-started/ssh-keys.png)
44+
45+
## Step 2: Create your workspace
46+
47+
You will now create the workspace to work on your development project.
48+
49+
1. Return to **Workspaces** using the top navigation bar.
50+
51+
1. Click **New workspace** to launch the workspace-creation dialog.
52+
53+
1. Provide a **Workspace Name**.
54+
55+
1. In the **Image** section, click **Packaged** (this tab contains
56+
Coder-provided images hosted in a Docker registry). Select **PyCharm**. This
57+
will populate the form in the **Import** tab.
58+
59+
1. Under **Workspace providers**, leave the default option (which is
60+
**built-in**) selected.
61+
62+
1. Expand the **Advanced** section. If the **Run as a container-based virtual
63+
machine** option is selected, _unselect_ the box. Leave the **CPU**,
64+
**Memory**, **Disk**, and **GPU** allocations as-is.
65+
66+
1. Scroll to the bottom and click **Create workspace**. The dialog will close,
67+
allowing you to see the main workspace page. On the right-hand side, you can
68+
track the workspace build process using the **Build log**.
69+
70+
![Create a workspace](../assets/getting-started/create-workspace-pycharm.png)
71+
72+
Once your workspace is ready for use, you'll see a chip that says **Running**
73+
next to the name of your workspace.
74+
75+
## Step 3: Create a sample project file in your workspace
76+
77+
Once you've created your workspace, you can start working in Coder. For the
78+
purposes of this article, we'll leverage JetBrains' tutorial on how to
79+
[Create and run your first Python project](https://www.jetbrains.com/help/pycharm/creating-and-running-your-first-python-project.html).
80+
81+
1. Under **Browser applications**, click **PyCharm Community** to open the IDE
82+
in your browser. Follow the prompts to accept the license agreement and
83+
determine data sharing permissions.
84+
85+
1. On the **Welcome to PyCharm** screen, click **New Project**.
86+
87+
1. In the window that pops up:
88+
89+
1. Provide the **Location** where PyCharm should save your files (for this
90+
example, we changed the highlighted portion to `task`, but you can name
91+
the folder whatever you'd like))
92+
1. Ensure that **New environment using Virtualenv** is selected.
93+
1. Make sure to **uncheck** the option to **Create a main.py welcome
94+
script**.
95+
1. Click **Create** to proceed.
96+
97+
1. In the left-hand navigation bar, right-click on the **root** of your folder
98+
(for example, if you named the folder `task`, you would click where it says
99+
**task** in the navbar) and select **New** > **File**. When prompted, provide
100+
a name for your file (e.g., `car.py`).
101+
102+
1. The IDE automatically opens your new, empty file, allowing you to edit. Copy
103+
and paste the following
104+
[sample app from JetBrains](https://www.jetbrains.com/help/pycharm/creating-and-running-your-first-python-project.html#edit-file):
105+
106+
```python
107+
class Car:
108+
109+
def __init__(self, speed=0):
110+
self.speed = speed
111+
self.odometer = 0
112+
self.time = 0
113+
114+
def say_state(self):
115+
print("I'm going {} kph!".format(self.speed))
116+
117+
def accelerate(self):
118+
self.speed += 5
119+
120+
def brake(self):
121+
if self.speed < 5:
122+
self.speed = 0
123+
else:
124+
self.speed -= 5
125+
126+
def step(self):
127+
self.odometer += self.speed
128+
self.time += 1
129+
130+
def average_speed(self):
131+
if self.time != 0:
132+
return self.odometer / self.time
133+
else:
134+
pass
135+
136+
if __name__ == '__main__':
137+
138+
my_car = Car()
139+
print("I'm a car!")
140+
while True:
141+
action = input("What should I do? [A]ccelerate, [B]rake, "
142+
"show [O]dometer, or show average [S]peed? ").upper()
143+
if action not in "ABOS" or len(action) != 1:
144+
print("I don't know how to do that")
145+
continue
146+
if action == 'A':
147+
my_car.accelerate()
148+
elif action == 'B':
149+
my_car.brake()
150+
elif action == 'O':
151+
print("The car has driven {} kilometers".format(my_car.odometer))
152+
elif action == 'S':
153+
print("The car's average speed was {} kph".format(my_car.average_speed()))
154+
my_car.step()
155+
my_car.say_state()
156+
```
157+
158+
1. At this point, you can run your application by right-clicking on the IDE
159+
editor window and selecting **Run <fileName>**. Once the app starts, you can
160+
interact with it using the terminal at the bottom.
161+
162+
## Step 5: Push your repo to GitHub
163+
164+
The following steps show you how to push your app to a newly created GitHub
165+
repo.
166+
167+
1. Log in to GitHub and navigate to
168+
[Create a new repository](https://github.com/new).
169+
170+
1. Provide a **repository name** and click **Create repository**.
171+
172+
1. Return to your workspace, and click **Terminal** at the bottom.
173+
174+
1. Run the following to turn your directory into a Git repository and commit
175+
your initial changes:
176+
177+
```console
178+
cd ..
179+
git init <nameOfDirectory>
180+
cd <nameOfDirectory>
181+
git add -A
182+
git commit -am "Initial commit"
183+
```
184+
185+
1. Run the following in your terminal to add a remote to your GitHub repo,
186+
change the primary branch name to `main`, and push the contents to your newly
187+
created repo:
188+
189+
```console
190+
git remote add origin git@github.com:<username>/<repoName>.git
191+
git branch -M main
192+
git push origin main
193+
```
194+
195+
1. Within the IDE window (near the top), you'll be prompted to log in to GitHub
196+
by providing your username and password/personal access token.
197+
198+
1. Next, Code Web will display an alert that says the GitHub extension wants to
199+
sign in; click **Allow** to proceed.
200+
201+
1. In the subsequent window, click **Continue** to authorize Visual Studio Code
202+
to access GitHub.
203+
204+
At this point, the contents of your repo should be pushed to GitHub.

manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
},
3939
{
4040
"path": "getting-started/developers.md"
41+
},
42+
{
43+
"path": "getting-started/pycharm.md"
4144
}
4245
]
4346
},

0 commit comments

Comments
 (0)