Installing Thonny, flake8¶
The purpose of this document is to walk you through setting up your own computer for writing and submitting Python code in CS 149.
Downloading and Installing Thonny¶
Thonny, pronounced THON-ee, is the officially supported Integrated Development Environment (IDE) for CS 149. Thonny is free and open source, originally developed by Aivar Annamaa at the University of Tartu in Estonia. Many other individuals and organizations have contributed to the ongoing development of Thonny.
Instructions
Visit https://thonny.org/ and download the installer based on your operating system. Run the installer, and accept the default options during installation.
Revealing File Extensions¶
When naming a file, a longstanding convention is to use a file extension
to indicate the file's type.
For example, a Windows executable might be named installer.exe
,
while a Word document might be named FinalReport.docx
.
In this case, .exe
and .docx
are the extensions indicating the file types.
Python programs end with the extension .py
.
In the good old days, these file exertions were visible by default,
and they were often helpful in figuring out file types. Unfortunately,
file extensions could also be confusing and intimidating for
non-technical users. For example, .avi
, .mp4
, .mpg
, .divx
,
.mov
(among many others) are all file extensions that represent
different kinds of video files. Understanding the differences among
these extensions is crucial to someone involved in video production, but
irrelevant to someone who just wants to watch the video. In the
interest of not confusing people, modern operating systems generally
hide file extensions by default.
Now that you are studying computer science, you have become the kind of person who needs to pay attention to file extensions. Congratulations! This means that you should modify the settings on your computer to show file extensions by default. Follow the instructions in the following links to change the appropriate settings on your computer.
Instructions
Saving Files in Thonny and Submitting Through Gradescope¶
You will save yourself some trouble this semester if you get into the
habit of organizing your Python files into folders organized by
assignment. I suggest creating a top-level folder named CS149
that
you can use to store each individual assignment folder. The video at
the end of this page shows an example of how to organize your files.
PEP 8 – Python Style¶
When writing in English, readability can be impacted by the way the text is laid out on the page. We use conventions, like indenting the first sentence of a paragraph, to make understanding written text easier. Programming languages similar to English in this regard.
Programs are easier to read if we agree on a set of conventions for how the code should be formatted. PEP 8 is the official document that describes the standard formatting conventions for Python code. (Here is a prettier version: https://pep8.org.) You don't need to read and understand the entire document now, but you may want to look it over to get a feel for the kinds of issues that PEP 8 addresses.
When you submit homework assignments for CS 149 they will
automatically be checked against the PEP 8 formatting requirements
using a tool named flake8
. You will receive full credit only if you
pass all of these automated style checks. You can install flake8
in
Thonny by following these steps:
Instructions
In Thonny, go to Tools > Manage Packages… Search for and install the following packages:
- flake8
- flake8-docstrings
- darglint
- pep8-naming
After installation, you can check your file by typing the following line into the Thonny shell:
>>> !flake8
The exclamation point tells Thonny that the line should be interpreted
as a system command, not as Python code.
By default, flake8
runs on every Python file in the current folder.
If you want to test only one file, you can specify the name like this:
>>> !flake8 hello_world.py
Optional Config File¶
The Gradescope autograder is configured to be slightly more
lenient than the default settings for flake8
. Gradescope allows
line lengths up to 100 and disables checks for some errors and warnings.
If you want to run flake8
with exactly the same settings as Gradescope,
you can copy the following file into the same folder as your python code:
Instructions
Download setup.cfg into your HW1 folder. As the course progresses, you may have a copy of this file in every assignment folder.
Video Demonstration¶
Watch this short video for a demonstration of the steps required to create a new Python file, store it in a reasonable location, and submit it through Gradescope.