
# The Mito Spreadsheet

This folder contains the `mitosheet` python package, as well as some other utilities for deploying Mito. 

Note that you can develop in with JLab 2 or JLab 3, as we currently support both!


## Mitosheet with JLab 2

First, delete any existing virtual enviornment that you have in this folder, and create a new virtual enviornment.

On Mac:
```
rm -rf venv;
python3 -m venv venv;
source venv/bin/activate;
```

On Windows:
```
del /s venv
python3 -m venv venv
venv\Scripts\activate.bat
```

Then, make sure that you have switched to `mitosheet` as the correct package (as this is the name of the package that we use with JLab 2). You can perform this with the command:
```
python switch.py mitosheet
```

Then, run the following commands to create a virtual enviorment, install a development version of `mitosheet` in it, and then launch Jupyter Lab 2.0.
```bash
pip install -e ".[test, deploy]"
jupyter labextension install @jupyter-widgets/jupyterlab-manager@2 --no-build
jupyter labextension install .
yarn cache clean
jupyter lab --watch
```

In a seperate terminal, to recompile the front-end, run the command:
```
npm run watch:lib
```

### One Liner Command for Mac
```bash
deactivate; rm -rf venv; python3 -m venv venv && source venv/bin/activate && python switch.py mitosheet && pip install -e ".[test, deploy]" && jupyter labextension install @jupyter-widgets/jupyterlab-manager@2 --no-build && jupyter labextension install . && yarn cache clean && jupyter lab --watch
```

## Mitosheet with JLab 3
First, delete any existing virtual enviornment that you have in this folder, and create a new virtual enviornment. 

On Mac:
```
rm -rf venv;
python3 -m venv venv;
source venv/bin/activate;
```

On Windows:
```
del /s venv
python3 -m venv venv
venv\Scripts\activate.bat
```

Then, make sure that you have switched to `mitosheet3` as the correct package (as this is the name of the package that we use with JLab 3). You can perform this with the command:
```
python switch.py mitosheet3
```

Then, run the following commands to create a virtual enviorment, install a development version of `mitosheet` in it, and then launch Jupyter Lab 3.0.
```bash
pip install -e ".[test, deploy]"
jupyter labextension develop . --overwrite
jupyter lab
```

In a seperate terminal, to recompile the front-end, run the command:
```
jlpm run watch
```

If the folder `pip-wheel-metadata` exists in your Mito folder, delete it. 

### One Liner Command for Mac
```bash
deactivate; rm -rf venv; python3 -m venv venv && source venv/bin/activate && python switch.py mitosheet3 && pip install -e ".[test, deploy]" && jupyter labextension develop . --overwrite && jupyter lab
```

# Testing

## Backend Tests

Run automated backend tests with
```
pytest
```
Automated tests can be found in  `mitosheet/test`. These are tests written using standard `pytest` tools, and include tests like testing the evaluate function, the MitoWidget, and all other pure Python code. 

## Frontend Tests

See `tests/README.md` for more instructions on writing tests.

### On Mac

First, start a server with:
```
jupyter lab
```

Then, run the tests with:
```
npm run test:local
```


### On Windows

First, start the server with:
```
jupyter lab --NotebookApp.token="" --NotebookApp.password="" &
```

Then, run the tests with
```
npm run test:local:noauth
```

Note: Windows has file descriptor limits, which practically means that you can only open so many notebooks before tests start failing. Thus, you _cannot run all the tests locally with the above command_. 

If you want to run all the tests on windows, run the commands
```
npm run test:ga:1
```
etc. See the `tests/README.md` for more information.

###### Testing on Windows


### Linting

This project has linting set up for both (Python)[https://flake8.pycqa.org/en/latest/index.html] and (typescript)[https://github.com/typescript-eslint/typescript-eslint]. 

Run typescript linting with the command 
```
npx eslint . --ext .tsx --fix
```

## How the Build Works

### For JLab 2

1. First, the TypeScript is compiled to JS, and placed in the `./lib` folder
2. Then, the `./lib` and `./css` folder (specified in files) are "packed" into the `./mitosheet` folder in `./mitosheet/labextension`.
3. The `mitosheet` package (including this JS and CSS) is then placed in the jupyter/share folder, whereever Jupyter is installed.
4. Then, JupyterLab is rebuilt, and the rebuild includes this new `mitosheet` package, including the JS + CSS it contains.

### For JLab 3

I am not totally sure.