Skip to content

Commit

Permalink
docs: improve the contributing instructions (#24)
Browse files Browse the repository at this point in the history
- changed local pip install to editable (this removes an extra step when working).
- added the missing `black` requirement
- reworked the contributing instructions (the main path helps setup a full environment, while the frontend-only/server-only instructions have been moved to a dedicated section at the end).
  • Loading branch information
tpatel committed Jun 2, 2023
1 parent bd7cbd9 commit f641e76
Showing 1 changed file with 45 additions and 22 deletions.
67 changes: 45 additions & 22 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ cd src
poetry install
```

## Contribute to the UI
Make sure you have the Python code formatter `black` installed as it is used in a pre-commit hook. Run `pip install black` if needed.

## Setup the UI

The source code of the UI is in [src/chainlit/frontend](/src/chainlit/frontend).

Before anything, go to [src/chainlit/frontend/api/index.ts](/src/chainlit/frontend/src/api/index.ts). Find the definition of `const server` and inverse the comment:
Before anything, go to [src/chainlit/frontend/src/api/index.ts](/src/chainlit/frontend/src/api/index.ts). Find the definition of `const server` and inverse the comment:

```ts
export const server = 'http://127.0.0.1:8000';
Expand All @@ -48,48 +50,69 @@ Don't forget to revert that change before pushing.

```sh
cd src/chainlit/frontend
npm run buildUi
npm run dev -- --port 5174
```

The `buildUi` step is currently needed by the server.

If you visit `http://127.0.0.1:5174/`, it should say that it can't connect to the server.
## Setup the server

### Start the server
- If you only wish to contribute to the UI, you can use any Chainlit installation
- If your contribution impacts both the UI and the Python package, you need to start the server from your [local installation](#contribute-to-the-python-package)
### Install from local sources

Starting the chainlit server in headless mode (since we manually started the UI)
```sh
chainlit run target.py -h
pip install -e PATH_TO_CHAINLIT_REPO/src
```

## Contribute to the Python package
This installs your project in editable mode, which means you only need to do this once.

### Start the server

- If you only wish to contribute to the Python package, run:
```sh
npm run buildUi
chainlit run target.py -h
```

- If your contribution impacts both the Python package and the UI, check the section above
The `-h` parameter (headless) means the UI will not automatically open.

### Install from local sources
## Run the tests

```sh
pip install PATH_TO_CHAINLIT_REPO/src
1. Create an `.env` file at the root of the repo following the model of `.env.example`
2. Run `npm test`

Once you create a pull request, the tests will automatically run. It is a good practice to run the tests locally before pushing.

## Only contribute to one side of the project

This is the easiest solution if you want to only make a change in the UI or the server.

Start with following the steps from the [Local setup](#local-setup).

### Only contribute to frontend

1. Follow the steps from [Setup the UI](#setup-the-ui).
2. Change the server configuration in [src/chainlit/frontend/src/api/index.ts](/src/chainlit/frontend/src/api/index.ts) to match your target chainlit server.

```js
export const server = 'https://img-gen.chainlit.app/';
```
3. Follow the steps from [Start the UI](#start-the-ui).

You need to repeat that step everytime you make a change in the Python codebase
### Only contribute to the server

### Start the server
1. Build the UI.

```sh
chainlit run target.py [-h]
cd src/chainlit/frontend
npm run buildUi
```

The `-h` parameter (headless) means the UI will not automatically open. Only use this if you are already running the UI yourself.
2. Follow the instruction from [Install from local sources](#install-from-local-sources).

## Run the tests
3. Run the server without the `-h` flag.

1. Create an `.env` file at the root of the repo following the model of `.env.example`
2. Run `npm test`
```sh
chainlit run target.py
```

Once you create a pull request, the tests will automatically run. It is a good practice to run the tests locally before pushing.
4. Any time you've made a change, restart the server from the previous step.

0 comments on commit f641e76

Please sign in to comment.