Skip to content

Commit

Permalink
Merge pull request #35 from MiguelGuthridge/stage
Browse files Browse the repository at this point in the history
Refactor to add support for PyPi distribution
  • Loading branch information
MaddyGuthridge authored Aug 31, 2021
2 parents 156e923 + 6ea5b10 commit 84039cc
Show file tree
Hide file tree
Showing 36 changed files with 277 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .coveragerc to control coverage.py
[run]
branch = True
source = lib
source = equator/lib

[report]
# Regexes for lines to exclude from consideration
Expand Down
146 changes: 140 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,145 @@

# Byte-compiled / optimized / DLL files
__pycache__/
.venv/
.venv_win/
.venv_linux/
.pytest_cache/
*.py[cod]
*$py.class

.coverage
# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.coverage_html/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
.venv_linux/
.venv_win/
.venv_windows/
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# Temporary files
temp.*
12 changes: 2 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@
"module": "pytest"
},
{
"name": "Equator: Run Interpreter (Windows)",
"name": "Equator: Run Interpreter",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\equator.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal"
},
{
"name": "Equator: Run Interpreter (Linux)",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/equator.py",
"module": "equator",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal"
}
Expand Down
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@ A maths interpreter built in Python using SymPy
* Simplify expressions
* It can do maths faster than you

# Installation

Equator can be installed from PyPi. Run the command
```
pip3 install equatorpy
```

# Usage:

## Start-up:
Run the file `equator.py` in the top-level directory. For example, `python3 equator.py`. The program has been tested on Windows and Linux (Ubuntu), but not MacOS. It might work, but it might not.
Equator can be run directly through the Python module. Run the command
```
python3 -m equator
```
Alternatively, Equator can be invoked directly using the command
```
equator
```
The program has been tested on Windows and Linux (Ubuntu), but not MacOS. It might work, but it might not.
* If no arguments are provided, the program launches into a full interpreter, built using the Curses library.
* If it is started with the argument `json`, then its output will be in a JSON format, where each line of input is treated as one set of equations and expressions. Each input will have one line of respective output, in [JSON format](https://github.com/MiguelGuthridge/Equator/wiki/JSON-Format-Specification).
* If it is started with the argument `ev`, then it will run a quick evaluation on the following argument. For example `equator ev "1 + 1"` would print `2`.
Expand All @@ -21,4 +36,21 @@ Run the file `equator.py` in the top-level directory. For example, `python3 equa
* Use standard mathematical syntax (+, -, *, /, ^, =, etc)
* Functional notation is used for unary operators:
* `|A|` should be written as `abs(A)`
* Equations or expressions are seperated by semicolons
* Equations or expressions are separated by semicolons

# Development

When working with Equator, it is recommended to work with a virtual environment.

After `git clone`ing the repository, set up a virtual environment using [these
instructions](https://docs.python.org/3/library/venv.html), then install the
required dependencies using the command
```
pip3 install -r requirements.txt
```
or if you're on Windows
```
pip install -r requirements_windows.txt
```

You should then be able to debug or develop the interpreter normally.
5 changes: 0 additions & 5 deletions __init__.py

This file was deleted.

14 changes: 14 additions & 0 deletions equator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Equator
An advanced symbolic calculator built using SymPy
This project is licensed under the GNU General Public License v3.0
Author: Miguel Guthridge
"""

from .lib import equate, Expression
from .lib.tokens import Token, Operator, Number, Constant, Symbol, BadToken
from .lib.eq_except import *

from .equator import main
5 changes: 5 additions & 0 deletions equator/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

from .equator import main

if __name__ == "__main__":
exit(main())
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions eq_curses/curses_main.py → equator/eq_curses/curses_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

import curses

from lib import consts
from lib import Expression
from equator.lib import consts
from equator import Expression
from .output_container import OutputContainer
from . import display_exp, colours

Expand Down
14 changes: 6 additions & 8 deletions eq_curses/display_exp.py → equator/eq_curses/display_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

import curses

from lib import tokens

from lib.tokens import Token
from lib.expression import Expression
from equator.lib import tokens
from equator import Expression

from . import colours

Expand Down Expand Up @@ -34,7 +32,7 @@ def getColourPair(token: 'tokens.Token') -> int:
return curses.color_pair(colours.PROMPT)

def displayExpression(row: int, col: int, stdscr: 'curses._CursesWindow',
exp: 'list[Token]', clear:bool=True):
exp: 'list[tokens.Token]', clear:bool=True):
# Set to starting row/col
stdscr.addstr(row, col, "")

Expand All @@ -46,12 +44,12 @@ def displayExpression(row: int, col: int, stdscr: 'curses._CursesWindow',
if clear:
stdscr.clrtoeol()

def unravelInputTokens(tokens: 'list[list[Token]]') -> 'list[Token]':
def unravelInputTokens(tokens: 'list[list[tokens.Token]]') -> 'list[tokens.Token]':
ret = []
add_semi = False
for t in tokens[0]:
if add_semi:
ret.append(Token(";"))
ret.append(tokens.Token(";"))
else:
add_semi = True
ret.extend(t)
Expand Down Expand Up @@ -80,7 +78,7 @@ def displayInputExpression(row: int, col: int, stdscr: 'curses._CursesWindow',
# Clear to end of line
stdscr.clrtoeol()

def splitExpression(max_line_len: int, exp: 'list[Token]') -> 'list[list[Token]]':
def splitExpression(max_line_len: int, exp: 'list[tokens.Token]') -> 'list[list[tokens.Token]]':
"""Split expression so that lines don't go past the end of input
"""
max_line_len -= 1
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

import curses
from lib.expression import Expression
from lib.eq_except import EqExternalException
from lib.tokens import Token, BadToken

from equator import Expression
from equator import EqExternalException
from equator import Token, BadToken

from .display_exp import displayExpression, displayInputExpression, splitExpression, unravelInputTokens
from . import colours
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion eq_json/json_main.py → equator/eq_json/json_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import json

from lib import equate, EqExternalException
from equator import equate, EqExternalException

def json_main():
try:
Expand Down
15 changes: 7 additions & 8 deletions equator.py → equator/equator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"""
import sys

from eq_curses import curses_main
from eq_json import json_main
from lib import consts
from lib import Expression
from lib import EqExternalException, EqInternalException
from .eq_curses import curses_main
from .eq_json import json_main
from .lib import consts
from .lib import Expression
from .lib import EqExternalException, EqInternalException

def usage():
print("\n".join([
Expand All @@ -37,7 +37,8 @@ def quick_equate(eq: list):
except EqExternalException as e:
print(str(e))

def main(argv) -> int:
def main() -> int:
argv = sys.argv[1:]
try:
if len(argv) == 0:
curses_main()
Expand All @@ -63,5 +64,3 @@ def main(argv) -> int:
"possible):")
if e.input is not None: print(e.input)

if __name__ == "__main__":
exit(main(sys.argv[1:]))
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/consts.py → equator/lib/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from enum import Enum

NAME = "Equator"
VERSION = "1.0.3"
VERSION = "1.2.0"
AUTHOR = "Miguel Guthridge"

# Get 15 decimal places of precision - the max given by sympy
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
Binary file modified requirements.txt
Binary file not shown.
3 changes: 3 additions & 0 deletions requirements_windows.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r requirements.txt

windows-curses==2.2.0
Loading

0 comments on commit 84039cc

Please sign in to comment.