From 26cb8a5ed7236e035e97877af0b9d0e1685442f2 Mon Sep 17 00:00:00 2001 From: Ian Adam Naval Date: Thu, 26 Feb 2015 16:47:39 -0500 Subject: [PATCH] Restructure to Python package --- .gitignore | 1 + README.md | 44 ++++++++++++++++++++++++++ psh/__init__.py | 0 commands.py => psh/commands.py | 0 console.py => psh/console.py | 4 +-- example_cmd.py => psh/example_cmd.py | 2 +- formatters.py => psh/formatters.py | 2 +- raw_commands.py => psh/raw_commands.py | 4 +-- main.py => psh/run.py | 6 ++-- tree.py => psh/tree.py | 0 requirements.txt | 1 + setup.py | 20 ++++++++++++ 12 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 README.md create mode 100644 psh/__init__.py rename commands.py => psh/commands.py (100%) rename console.py => psh/console.py (97%) rename example_cmd.py => psh/example_cmd.py (94%) rename formatters.py => psh/formatters.py (89%) rename raw_commands.py => psh/raw_commands.py (93%) rename main.py => psh/run.py (81%) rename tree.py => psh/tree.py (100%) create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 8d35cb3..e581009 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ *.pyc +*.egg-info diff --git a/README.md b/README.md new file mode 100644 index 0000000..abadc96 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +psh +=== + +Augmented Unix Userland shell inspired by Windows PowerShell, written in Python. + +Requirements +------------ + +* Python 3+ +* pip + +Installing +---------- + +Preferably, you would use a separate virtual env + +``` +pip install -r requirements.txt +pip install -e . # installs the 'psh' package in editable mode +``` + +Running +------- + +From Python shell: + +``` +from psh.run import main +main() +``` + +From Unix shell: +``` +python -m psh.run +``` + +Testing +------- + +From Unix shell: + +``` +py.test +``` diff --git a/psh/__init__.py b/psh/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/commands.py b/psh/commands.py similarity index 100% rename from commands.py rename to psh/commands.py diff --git a/console.py b/psh/console.py similarity index 97% rename from console.py rename to psh/console.py index b08f42d..06ffee7 100644 --- a/console.py +++ b/psh/console.py @@ -4,8 +4,8 @@ import os import readline import shlex -from commands import registered_cmds -import example_cmd +from psh.commands import registered_cmds +import psh.example_cmd DEFAULT_HISTORY_FILE = "~/.psh_history" diff --git a/example_cmd.py b/psh/example_cmd.py similarity index 94% rename from example_cmd.py rename to psh/example_cmd.py index 1b23ad3..8abf205 100644 --- a/example_cmd.py +++ b/psh/example_cmd.py @@ -1,4 +1,4 @@ -from commands import BaseCommand, register_cmd +from psh.commands import BaseCommand, register_cmd @register_cmd diff --git a/formatters.py b/psh/formatters.py similarity index 89% rename from formatters.py rename to psh/formatters.py index 8a516fb..3e50c47 100644 --- a/formatters.py +++ b/psh/formatters.py @@ -1,4 +1,4 @@ -from commands import BaseCommand +from psh.commands import BaseCommand class Printer(BaseCommand): diff --git a/raw_commands.py b/psh/raw_commands.py similarity index 93% rename from raw_commands.py rename to psh/raw_commands.py index 82f4c54..6777bc1 100644 --- a/raw_commands.py +++ b/psh/raw_commands.py @@ -1,5 +1,5 @@ -from formatters import Printer -from commands import BaseCommand +from psh.formatters import Printer +from psh.commands import BaseCommand class RawCommand(BaseCommand): diff --git a/main.py b/psh/run.py similarity index 81% rename from main.py rename to psh/run.py index a7bf3cc..2118e04 100644 --- a/main.py +++ b/psh/run.py @@ -1,8 +1,8 @@ import os import os.path -from formatters import * -from raw_commands import RawCommand +from psh.formatters import * +from psh.raw_commands import RawCommand # Load all of the commands in the path into the global namespace as raw # commands. @@ -15,7 +15,7 @@ for path in os.environ['PATH'].split(':'): def main(): - from console import HistoryConsole + from psh.console import HistoryConsole console = HistoryConsole(globals()) console.interact("Augmented Unix Userland") diff --git a/tree.py b/psh/tree.py similarity index 100% rename from tree.py rename to psh/tree.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e079f8a --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pytest diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a6fa282 --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +import os +from setuptools import setup + +# Utility function to read the README file. +# Used for the long_description. It's nice, because now 1) we have a top level +# README file and 2) it's easier to type in the README file than to put a raw +# string in below ... +def read(fname): + return open(os.path.join(os.path.dirname(__file__), fname)).read() + +setup( + name = "psh", + version = "0.0.1", + author = "WPI Augmented Unix Userland MQP", + author_email = "jsh@wpi.edu", + description = ("Simple Unix shell inspired by PowerShell"), + license = "MIT", + packages=['psh'], + long_description=read('README.md'), +)