Python Notes - rharmonson/richtech GitHub Wiki

Python

Install Atom

Alternative to idle3 is to use Atom.

To install Atom from the official RPM package provide by the Atom team (which is only suitable for 64-bit systems!) for the latest stable (as opposed to beta releases which are also packaged at RPMs) Atom release, run:

sudo dnf install $(curl -sL "https://api.github.com/repos/atom/atom/releases/latest" | grep "https.*atom.x86_64.rpm" | cut -d '"' -f 4)

Alternatively, if the above does not work due to s3.amazon.com issues, i.e. July 23, 2018.

wget https://atom.io/download/rpm -O atom.x86_64.rpm

For 32 bit use atom.rpm.

While there is no official way to auto-update these binaries here is a ~/.bashrc (also compatible with the Zsh shell's ~/.zshrc file) snippet that will automatically check for available Atom updates and install them whenever one opens a terminal:

ATOM_INSTALLED_VERSION=$(rpm -qi atom | grep "Version" |  cut -d ':' -f 2 | cut -d ' ' -f 2)
ATOM_LATEST_VERSION=$(curl -sL "https://api.github.com/repos/atom/atom/releases/latest" | grep -E "https.*atom-amd64.tar.gz" | cut -d '"' -f 4 | cut -d '/' -f 8 | sed 's/v//g')

if [ $ATOM_INSTALLED_VERSION < $ATOM_LATEST_VERSION ](/rharmonson/richtech/wiki/-$ATOM_INSTALLED_VERSION-<-$ATOM_LATEST_VERSION-); then
  sudo dnf install -y https://github.com/atom/atom/releases/download/v${ATOM_LATEST_VERSION}/atom.x86_64.rpm
fi

Create Python3 Virtual Environment

Create a top-level directory to maintain your projects.

$ mkdir /home/username/pyvenvs

Create a project folder, e.g. project1, then a virtual environment.

$ pwd
/home/username/pyvenvs
$ python3 -m venv project1
$ ls project1
bin  include  lib  lib64  pyvenv.cfg

Clone your repository (optional)

I will be cloning my misc-python repository using git. Before cloning you need to complete initial setup.

Generate a key pair for use or use an existing key pair.

$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

Visit your account settings on github.com, SSH and GPG Keys, then New SSH Key. cat then copy and paste the results.

cat ~/.ssh/id_rsa.pub

Clone the github repository by visiting the repository and copying the link found in the upper-left corner titled "Clone or Download."

git clone [email protected]:rharmonson/misc-python3.git

Start Virtual Environment and Atom

Activate the project1 virtual environment then launch Atom--use of python3 versus the system wide or non-virtual environment default, python2.

$ pwd
/home/username/pyvenvs/project1
$ . bin/activate  <-- space after the "."
(project1) $
$ atom

When done execute deactivate to exit the virtual environment.

Configure Atom

Source Code Pro Font

Download and install before starting Atom. For Windows download and right-mouse click to install. For Linux, install the appropriate package, i.e. Fedora is adobe-source-code-pro-fonts.

Note as of July 2018, it appears the name of the fonts are "Source Code Variable."

For Microsoft Windows, download using the URI given below.

https://github.com/adobe-fonts/source-code-pro/releases/tag/variable-fonts

Atom Configuraiton

On Startup

On opening, Atom will display tabs:

  1. Welcome Guide: select "Open a Project" then browse, select, and click the OK button for the project1 folder.
  2. Welcome: remove the check to Show Welcome Guide on opening Atom
  3. Telemetrics: Disable or permit

Script

Open Atom Settings pane by selecting "Edit" from the menu then Preferences.

Using "Settings" select "Install" then install "script" by rgbkrk.

Predawn

Change selection from Packages to Themes then install "predawn-syntax" by jamiewilson. Next, select "Themes" and select Predawn under Syntax Theme.

Editor

Using "Settings" select "Editor"

  1. Font Family: Source Code Pro or Source Code Variable; the font displayed by Atom will change to Times Roman(?) then update if you type the correct Source Code Pro/Variable font name
  2. Font Size: 20
  3. Scroll Past End: enable
  4. Tab Length: 4

Auto-complete

Core packages "autocomplete-plus" and "autocomplete-snippets" found under "Settings" select "Packages" are enabled by default.

Using "Settings" select "Install" then install package "autocomplete-python."

python-autopep8

Install package python-autopep8 by markbaas then

  1. Format On Save: enable
  2. Install within venv pip install autopep8
  3. Also, use ctrl-alt-s to reformat code

linter

Install package linter by steelbrain. After installation, it will prompt you to install linter-ui-default which in turns prompts you to install intentions and busy-signal.

Install package linter-flake8 by AtomLinter, then install within venv pip install flake8.

Additional Packages

  • file-icons by file-icons
  • minimap by atom-minimap
  • git-plus by akonwi
  • atom-beautify by Glabin001

Delete Changes

If things go wrong or you just want a fresh start, execute rm -rf ~/.atom.

Miscellaneous

On Fedora, tkinter is not install by default. If using Python 3, install using sudo dnf python3-tkinter which also installs tk.

On Windows, I experienced the following flake8 error.

flake8 Error: c:\program files\python37\lib\site-packages\pycodestyle.py:113:

Fix is found here:

https://github.com/PyCQA/pycodestyle/issues/728