Skip to content

02 Getting Started

xovertheyearsx edited this page Mar 2, 2018 · 3 revisions

Getting Started

Setting up for development

  • Install atom (if you haven't already)
  • Install python 2 (and/or 3)
  • Install nodejs 6 LTS
  • Install git

For Windows: You can always use explorer and then right click to open the context menu and click on open git shell here. The basic navigation commands are cd to change directory and ls to list directory contents. For more information you can use help -m cd and man ls. help lists all of the available shell commands. You can call other commands like python and node as well as long as they're included in your PATH environment variable. Just make a note of using the / instead of the \; \ is an escape character in bash.

Navigate to your development path and clone atom-python-run using git.

$ pwd
/home/th3ros/Documents/Github
$ git clone https://github.com/foreshadow/atom-python-run.git
...git stuff here that i forgot to copy and paste...
$ cd atom-python-run
$ pwd
/home/th3ros/Documents/Github/atom-python-run
$ ls -l
total 28
-rw-rw-r-- 1 th3ros th3ros 1257 Sep 30 02:32 CHANGELOG.md
drwxrwxr-x 3 th3ros th3ros 4096 Sep 30 02:32 cp
drwxrwxr-x 2 th3ros th3ros 4096 Sep 30 02:32 keymaps
drwxrwxr-x 2 th3ros th3ros 4096 Sep 30 02:32 lib
-rw-rw-r-- 1 th3ros th3ros 1072 Sep 30 02:32 LICENSE.md
-rw-rw-r-- 1 th3ros th3ros  328 Sep 30 02:32 package.json
-rw-rw-r-- 1 th3ros th3ros 3723 Sep 30 02:32 README.md

Note: Make sure you do NOT have atom-python-run installed in atom.

If you do, remove it first.

$ apm uninstall atom-python-run
Uninstalling atom-python-run ✓

If you do NOT have it installed, the next step is to link it to atom.

$ pwd
/home/th3ros/Documents/Github/atom-python-run
$ apm link
/home/th3ros/.atom/packages/atom-python-run -> /home/th3ros/Documents/Github/atom-python-run
$ atom .

The last line, atom ., just tells the OS to run atom with the . (current working directory).

Note: As you make changes to the source files, you may need to refresh (or restart) atom before those changes take effect. To do so, make sure atom is the active selected window and press Ctrl + Shift + F5. This will refresh the atom text editor and allow those changes to take effect.

cp, terminal, and atom-python-run

It's best to learn about this package from the ground up. It makes it easier to understand when you know how the engine works underneath the hood.

  • cp is a command line utility that simply analyzes, parses, and executes the given set of arguments.
  • terminal detects the operating system and utilizes system meta data to automatically generate a shell object as a process.
  • atom-python-run the module that runs your source code when you hit your designated command as F5 or F6

The following is a mapped tree structure of the package.

$ ll
total 56K
-rw-rw-r-- 1 th3ros th3ros 1.3K Sep 30 02:32 CHANGELOG.md
drwxrwxr-x 3 th3ros th3ros 4.0K Sep 30 02:32 cp/
drwxrwxr-x 2 th3ros th3ros 4.0K Sep 30 02:32 keymaps/
drwxrwxr-x 2 th3ros th3ros 4.0K Sep 30 02:32 lib/
-rw-rw-r-- 1 th3ros th3ros 1.1K Sep 30 02:32 LICENSE.md
-rw-rw-r-- 1 th3ros th3ros  328 Sep 30 02:32 package.json
-rw-rw-r-- 1 th3ros th3ros 3.7K Sep 30 02:32 README.md
$ tree .
.
├── CHANGELOG.md
├── cp
│   ├── cp
│   │   ├── __init__.py
│   │   ├── parse.py
│   │   └── utils.py
│   └── main.py
├── keymaps
│   └── atom-python-run.json
├── lib
│   ├── atom-python-run.js
│   ├── terminal.js
│   └── test.js
├── LICENSE.md
├── package.json
└── README.md

4 directories, 12 files

Creating a development flow

The next step is to create a branch for testing purposes. That way we can play with the core files without worrying about affecting the original source code. We can always switch back and delete the branch if nothing comes out of it.

For development, we only really care about the lib and cp directories. That's where the core source files reside.

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
$ git branch
* master
$ git checkout -b alt
Switched to a new branch 'alt'
$ git branch
* alt
  master

Now the real fun begins. Don't be afraid to break the code. Tweak it, play with it, bend it to your will. That's part of the fun in coding; Discovery! That's also how you'll learn how it works.

Start with cp

I like the directory that I'm working in to be the actual current working directory. So I always work as closely to that directory as possible to minimize issues and typing.

$ pwd
/home/th3ros/Documents/Github/atom-python-run
$ ls -l
total 56
-rw-rw-r-- 1 th3ros th3ros 1257 Sep 30 02:32 CHANGELOG.md
drwxrwxr-x 3 th3ros th3ros 4096 Sep 30 02:32 cp
drwxrwxr-x 2 th3ros th3ros 4096 Sep 30 02:32 keymaps
drwxrwxr-x 2 th3ros th3ros 4096 Sep 30 02:32 lib
-rw-rw-r-- 1 th3ros th3ros 1072 Sep 30 02:32 LICENSE.md
-rw-rw-r-- 1 th3ros th3ros  328 Sep 30 02:32 package.json
-rw-rw-r-- 1 th3ros th3ros 3723 Sep 30 02:32 README.md
$ cd cp
$ pwd
/home/th3ros/Documents/Github/atom-python-run/cp
$ ls -l
total 16
drwxrwxr-x 2 th3ros th3ros 4096 Sep 30 02:32 cp
-rw-rw-r-- 1 th3ros th3ros 1997 Sep 30 02:32 main.py

First, before we do anything, we can play around with cp to see how it works.

$ ll
total 16K
drwxrwxr-x 2 th3ros th3ros 4.0K Sep 30 02:32 cp/
-rw-rw-r-- 1 th3ros th3ros 2.0K Sep 30 02:32 main.py
$ python main.py 
usage: main.py [-h] [-f FILE] [-p] repl args [args ...]
main.py: error: the following arguments are required: repl, args

I have a source file called hello.py that's source code looks like this. we can use that for testing out how cp works. It works with both python 2 and 3.

hello.py

from __future__ import print_function
print("hello, world!")

Then we execute it using cp

$ python main.py python ~/Documents/Python/hello.py 
hello, world!

You're not going crazy. It did exactly what it was supposed to do.

For more information, see What is cp?