Skip to content

Commit 922aa3d

Browse files
authored
docs: update python developer guide to use tox (#6637)
1 parent e63f563 commit 922aa3d

File tree

2 files changed

+32
-159
lines changed

2 files changed

+32
-159
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ Before submitting a pull request, please make sure the following is done. We exp
2525
- Fork the repository and create your branch from `main`.
2626
- Follow the [development guide](./DEVELOPMENT.md) to setup your local environment.
2727
- If you've fixed a bug or added code that should be tested, add tests!
28-
- Ensure test suite pass. (`hatch run tests` and `npm run test` for app changes)
29-
- Make sure your code is formatted with `hatch run style:fix` and `npm run prettier` for app changes.
28+
- Ensure test suite passes (`tox run -e unit_tests` and `npm run test` for app changes)
29+
- Make sure your code is formatted with `tox run -e ruff` and `npm run prettier` for app changes.
3030
- Make sure to your code lints with `npm run lint` for app changes.
31-
- Run type checking with `hatch run type:check` and `npm run typecheck` for app changes.
31+
- Run type checking with `tox run -e type_check` and `npm run typecheck` for app changes.
3232

3333
### Pull Request (PR) Descriptions
3434

DEVELOPMENT.md

Lines changed: 29 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
- [Building the Package](#building-the-package)
99
- [Installing a Phoenix Build](#installing-a-phoenix-build)
1010
- [Installing a `git` Branch on Colab](#installing-a-git-branch-on-colab)
11-
- [Setting Up Your Windows Test Environment](#setting-up-your-windows-test-environment)
12-
- [Selecting a Virtualization Option](#selecting-a-virtualization-option)
13-
- [Installing Python and Phoenix](#installing-python-and-phoenix)
14-
- [Configuring a Remote Interpreter](#configuring-a-remote-interpreter)
15-
- [Troubleshooting](#troubleshooting)
1611
- [Publishing a New Release](#publishing-a-new-release)
1712
- [Best Practices](#best-practices)
1813
- [REST API](#rest-api)
@@ -25,20 +20,32 @@
2520

2621
## Setting Up Your macOS Development Environment
2722

28-
We recommend using a virtual environment to isolate your Python dependencies. This guide will use `conda`, but you can use a different virtual environment management tool if you want.
23+
We recommend using a virtual environment to isolate your Python dependencies. This guide will use `uv`, but you can use a different virtual environment management tool such as `conda` if you want.
2924

30-
First, ensure that your virtual environment manager is installed. For macOS users, we recommend installing `conda` via `brew` with
25+
First, ensure that your virtual environment manager is installed. For macOS users, we recommend installing `uv` via `brew` with
3126

3227
```
33-
brew install --cask mambaforge
28+
brew install uv
3429
```
3530

36-
For non-mac users, you can follow the instruction [here](https://github.com/conda-forge/miniforge#miniforge) to install `conda` for your particular operating system.
31+
For non-mac users, you can follow the instruction [here](https://docs.astral.sh/uv/getting-started/installation/) to install `uv` for your particular operating system.
3732

38-
Create a new virtual environment with a Phoenix-compatible Python version. For example,
33+
Create a new virtual environment. In general, we recommend developing on the lowest Python version compatible with Phoenix (currently 3.9) to make it easier to write code that is compatible across all supported versions.
3934

4035
```bash
41-
conda create --name phoenix python=3.12
36+
uv venv --python 3.9
37+
```
38+
39+
Activate your virtual environment before continuing.
40+
41+
```bash
42+
source ./.venv/bin/activate
43+
```
44+
45+
From the root of the reposistory, install the `arize-phoenix` package in editable mode (using the `-e` flag) with development dependencies (using the `dev` extra) by running
46+
47+
```bash
48+
uv pip install -e ".[dev]"
4249
```
4350

4451
Second, install the web build dependencies.
@@ -65,30 +72,6 @@ pnpm install
6572
pnpm run build
6673
```
6774

68-
Finally, change directory back to repository root and install `phoenix` in
69-
development mode (using the `-e` flag), and with development dependencies
70-
(using the `[dev,test]` extra) by running
71-
72-
```bash
73-
pip install -e ".[dev,test]"
74-
```
75-
76-
If you are working on our LLM orchestration framework integrations, you may also wish to install LlamaIndex or LangChain from source. To install LlamaIndex from source,
77-
78-
- Uninstall any pre-existing version of LlamaIndex with `pip uninstall llama-index`.
79-
- Fork and clone LlamaIndex using one of the following two methods:
80-
- If you are an Arize employee, clone [Arize's fork of LlamaIndex](https://github.com/Arize-ai/llama_index).
81-
- If you are an external contributor, fork and clone [LlamaIndex's upstream repository](https://github.com/run-llama/llama_index).
82-
- Run `pip install -e .` from the repository root.
83-
84-
To install LangChain from source,
85-
86-
- Uninstall any pre-existing version of LangChain with `pip uninstall langchain`.
87-
- Fork and clone LangChain using one of the following two methods:
88-
- If you are an Arize employee, clone [Arize's fork of LangChain](https://github.com/Arize-ai/langchain).
89-
- If you are an external contributor, fork and clone [LangChain's upstream repository](https://github.com/langchain-ai/langchain).
90-
- Run `pip install -e .` from `libs/langchain`.
91-
9275
## Testing and Linting
9376

9477
Phoenix is backed with either a `sqlite` or `postgresql` database. By default, tests that involve
@@ -108,47 +91,34 @@ pg_config --bindir
10891
This command should point to the `homebrew` install of `postgresql`, if it doesn't, try creating
10992
a fresh Python environment or modifying your `PATH`.
11093

111-
Phoenix uses `hatch` as the project management tool to lint and test source code and to build the package. After creating and activating your `phoenix` virtual environment, view your `hatch` environments, dependencies and, scripts defined in `pyproject.toml` with
94+
Phoenix uses `tox` to run linters, formatters, type-checks, tests, and more. In particular, we recommend using `tox-uv`, which uses `uv` under the hood for package management and is significantly faster than vanilla `tox`.
11295

113-
```bash
114-
hatch env show
115-
```
116-
117-
Scripts belonging to the various environments can be run with
118-
119-
```bash
120-
hatch run <env-name>:<script-name>
121-
```
122-
123-
To type-check your code, run
96+
You can install `tox-uv` globally with
12497

12598
```bash
126-
hatch run type:check
99+
uv tool install tox --with tox-uv
127100
```
128101

129-
To format your code, run
102+
`tox` manages isolated virtual environments, each with a corresponding set of commands. These environments are defined inside of `tox.ini` and can be enumerated by running
130103

131104
```bash
132-
hatch run style:fix
105+
tox list
133106
```
134107

135-
To run tests
108+
Commands corresponding to an environment can be executed by running `tox run -e <env-name>`. For example, you can execute unit tests by running
136109

137110
```bash
138-
hatch run tests
111+
tox run -e unit_tests
139112
```
140113

141114
By default, database tests only run against `sqlite`, in order to run database tests against
142115
a `postgresql` database as well, use the `--run-postgres` flag
143116

144117
```bash
145-
hatch run tests --run-postgres
118+
tox run -e unit_tests -- --run-postgres
146119
```
147120

148-
The following resources are helpful to learn more about the capabilities of `hatch` and to familiarize yourself with the CLI.
149-
150-
- [Hatch Quickstart](https://hatch.pypa.io/latest/)
151-
- [Hatch CLI Reference](https://hatch.pypa.io/latest/cli/reference/)
121+
Check the output of `tox list` to find commands for type-checks, linters, formatters, etc.
152122

153123
## Installing Pre-Commit Hooks
154124

@@ -164,9 +134,8 @@ Once installed, the pre-commit hooks configured in `.pre-commit-config.yaml` wil
164134

165135
To add or modify a Jupyter notebook, the following commands are needed to pass CI.
166136

167-
- `hatch run type:check`: Run type checks
168-
- `hatch run style:fix`: Runs formatters
169-
- `hatch run notebooks:clean`: Removes cell output and notebook metadata to keep the diff as small as possible
137+
- `tox run -e ruff`: Runs formatters
138+
- `tox run -e clean_jupyter_notebooks`: Removes cell output and notebook metadata to keep the diff as small as possible
170139

171140
## Building the Package
172141

@@ -229,102 +198,6 @@ The code below installs the `main` branch in [Colab](https://colab.research.goog
229198
%pip install git+https://github.com/Arize-ai/phoenix.git@main
230199
```
231200

232-
## Setting Up Your Windows Test Environment
233-
234-
It is occasionally necessary to manually test a Phoenix build or to run Phoenix from source on Windows. The following instructions enable macOS developers who do not have a PC to quickly set up a Windows Python environment in a cloud or local virtual machine.
235-
236-
### Selecting a Virtualization Option
237-
238-
We recommend to use a virtual machine either with Microsoft Azure (a cloud virtual machine) or using the Parallels Desktop app (a local virtual machine). Which option you select will depend on your hardware and whether you wish to run a remote IDE. The following resources are helpful to make a decision:
239-
240-
- [Parallels Desktop for Mac System Requirements](https://kb.parallels.com/en/124223)
241-
- [Supported SSH Clients for Remote Development with VSCode](https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client)
242-
243-
At the time of this writing in December 2022,
244-
245-
- Windows 11 is the only Windows OS with a supported ARM version,
246-
- JetBrains does not support remote development on Windows servers,
247-
- VSCode supports remote development on certain Windows versions not including Windows 11.
248-
249-
Hence, if you are a macOS developer using an Apple Silicon machine and you wish to use a remote interpreter, running a Windows VM locally is not straightforward and we recommend you use a Windows VM on Azure.
250-
251-
If you elect to use an Azure VM, we recommend that you select a non-headless OS (we use Windows Server 2019), configure an inbound port rule for RDP on port 3389 while creating the VM and screenshare with your VM using Microsoft Remote Desktop, which can be downloaded from the Apple App Store. This will enable you to [configure an SSH server](#configuring-a-remote-interpreter) on the VM for remote development.
252-
253-
### Installing Python and Phoenix
254-
255-
The following instructions assume you have created a Windows virtual machine either locally or in the cloud. These instructions have been tested on Windows Server 2019 and assume you are using Powershell.
256-
257-
Install `chocolatey`, a package manager for Windows, by following the instructions [here](https://chocolatey.org/install#individual).
258-
259-
Open a new shell and run
260-
261-
```powershell
262-
choco install nvm pyenv-win git
263-
```
264-
265-
Open a new shell and install the latest long-term supported version of `node` using
266-
267-
```powershell
268-
nvm install lts
269-
```
270-
271-
Activate this version using
272-
273-
```powershell
274-
nvm use lts
275-
```
276-
277-
Open a new shell and confirm that `node` and `npm` are available with
278-
279-
```powershell
280-
node --version
281-
npm --version
282-
```
283-
284-
Install your desired Python version with
285-
286-
```powershell
287-
$env:PHOENIX_PYTHON_VERSION = "desired-python-version"
288-
pyenv install $env:PHOENIX_PYTHON_VERSION
289-
```
290-
291-
Set the global `pyenv` version with
292-
293-
```powershell
294-
pyenv global $env:PHOENIX_PYTHON_VERSION
295-
```
296-
297-
Install `virtualenvwrapper-win` with
298-
299-
```powershell
300-
pip install virtualenvwrapper-win
301-
```
302-
303-
Create a virtual environment called `phoenix` with
304-
305-
```powershell
306-
mkvirtualenv phoenix-env
307-
```
308-
309-
Activate your virtual environment. You can now [install a Phoenix build](#installing-a-phoenix-build). Alternatively, if you wish to run Phoenix from source, clone the repo and install Phoenix in development mode with
310-
311-
```powershell
312-
pip install -e ".[dev]"
313-
```
314-
315-
### Configuring a Remote Interpreter
316-
317-
If you wish to use a remote SSH interpreter (e.g., via VSCode), you must install and run an SSH server on your Windows VM. We recommend to install OpenSSH Server by navigating to `Settings > Apps > Manage optional features > Add a feature`, selecting `OpenSSH Server` in the list and clicking `Install`. To start the SSH server, navigate to `Control Panel > System and Security > Administrative Tools > View local services`, select `OpenSSH Server` and press `Start`. If you wish to configure the server to start automatically on startup, select `Actions > Properties` while `OpenSSH Server` is selected from the list (or just double-click on `OpenSSH Server`), select `Automatic` in the `Startup type` dropdown and hit `Apply`.
318-
319-
You must also ensure that port 22 of your Windows VM is reachable by your SSH client.
320-
321-
- If using an Azure VM, this can be accomplished by defining an appropriate inbound port rule for TCP on port 22 either during creation of the virtual machine or after creation in the VM's networking settings.
322-
- If using Parallels Desktop, navigate to `Preferences > Network` and define a port forwarding rule for TCP on destination port 22.
323-
324-
### Troubleshooting
325-
326-
- In our experience, the `workon` command familiar to users of `virtualenvwrapper` may not properly run on Windows with `virtualenvwrapper-win`. In order to activate a virtual environment, you can manually run the appropriate activation script (`activate.ps1` if using Powershell) typically located in `$env:USERPROFILE\Envs\<env-name>\Scripts`.
327-
328201
## Publishing a New Release
329202

330203
To publish a new release, follow the steps below.

0 commit comments

Comments
 (0)