Link Search Menu Expand Document

Coding - Programs and Tweaks

  1. Sublime Text
  2. Spyder
  3. Jupyter Notebooks
  4. Python Best Practices

Sublime Text

A nice text editor with good theming and visual appeal

A good basic setup:

  • Theme: Preferences » Theme » Adaptive
  • Colors: Preferences » Color Scheme » Monokai

Extensions

  • Package Control - A nice way to add and remove packages to sublime. You need this for all other visual tweaks
  • Material Theme - Beautiful theming using material design. Be sure to set the colors back to Monokai afterward
    • Theme settings:
      "material_theme_accent_cyan": true,
      "material_theme_big_fileicons": true,
      "material_theme_bright_scrollbars": true,
      "material_theme_compact_sidebar": true,
      "material_theme_contrast_mode": true,
      "material_theme_small_tab": true,
      "material_theme_titlebar": true,
      "theme": "Material-Theme-Darker.sublime-theme"
      
  • Sync Settings - A nice tool to sync sublime settings using github gists.

Windows right-click menu items

subl.reg

This registy file adds several right-click options:

  1. Open any file with Sublime
  2. Open any folder with Sublime
    • by right-clicking on the folder
    • by right clicking on any white space inside the folder

Enjoy!

Spyder

Python IDE

Settings

  • Tools » Preferences » Syntax Coloring » Monokai
  • Tools » Preferences » iPython Console » Graphics » Backend » Automatic

QDarkStyle

Doesn’t Work

QDarkStyle dark mode for spyder. Here are the instructions from someone on StackOverflow

I tried it by placing the correct line here: C:\ProgramData\Anaconda2\Lib\site-packages\spyder\app, but it sort of looks like garbage. For now I’m sticking to the white window with dark Monokai syntax highlighting.

Dark Fusion

Doesn’t Work

Based on the instructions from this Github Issue

darkflat.py

  1. Put darkflat.py into C:\ProgramData\Anaconda2\Lib\site-packages\spyder\
    • This is a modified version of the original code.
    • Modifications: Refactored the class definition to not rely on super
    • Additions:
      from qtpy.QtGui import QPalette, QColor
      from qtpy import QtCore
      
    • Subtractions:
      #! /usr/bin/env python3
      
  2. Add the following three lines right before the return statement in the initialize function in app/mainwindow.py
    from spyder import darkflat
    palette = darkflat.QDarkPalette()
    palette.set_app(app)
    
  3. Follow Repligon’s instructions to make all uncolored icons white.

Note: I tried this as well, but this styling didn’t affect the title bar or the tabs in spyder’s editor. I ultimately abandoned my attempts to add a nice dark mode to Spyder 3.

Jupyter Notebooks

Install Monokai theme using jupyter-themes:

pip install jupyterthemes # install jupyterthemes
jt -t monokai -T   # Use monokai theme and enable the toobar (-T)

As seen on this post on StackOverflow

Python Best Practices

Packages

When making python packages, I follow Scott Torborg’s guide for how to package python code

Python Packaging Guidelines

Tweaks I make to his style guide:

  1. I place the tests folder in the main folder (not in the package directory)
  2. I don’t use the unittest.TestCase class

Upload open source packages to PyPI

Follow this guide to build and upload your package

  1. Build your package
    • increment the version number
    • Delete the build and dist folders)
    • python setup.py sdist bdist_wheel
  2. Check that the package will work correctly
    • twine check dist/*
  3. Test your package on the test server. You will need to make an account there too (it’s completely separate)
    • twine upload --repository-url https://test.pypi.org/legacy/ dist/*
  4. Upload for real
    • twine upload dist/*
  5. It seems that sometimes PyPi’s servers don’t update the available version number right away, but according to this GitHub issue, you can force that to happen
    • curl -X PURGE https://pypi.python.org/simple/[YOUR PACKAGE NAME]

Virtual Environments

  1. Install venv: sudo apt install python3-venv
  2. Create a folder to store virtual environments (mine is in ~Documents/virtual_envs)
  3. Create a new virtual environment: python3 -m venv ~/Documents/virtual_envs/[ENV NAME]
  4. Activate a virtual environment in a terminal: source ~/Documents/virtual_envs/[ENV NAME]/bin/activate