Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions mlir/docs/Bindings/Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
### Recommended development practices

It is recommended to use a Python virtual environment. Many ways exist for this,
but the following is the simplest:
but one of the following is generally recommended:

```shell
# Make sure your 'python' is what you expect. Note that on multi-python
Expand All @@ -37,7 +37,22 @@ but the following is the simplest:
which python
python -m venv ~/.venv/mlirdev
source ~/.venv/mlirdev/bin/activate
```

Or, if you have uv installed on your system, you can also use the following commands
to create the same environment (targeting a Python 3.12 toolchain in this example):

```shell
uv venv ~/.venv/mlirdev --seed -p 3.12
source ~/.venv/mlirdev/bin/activate
```

You can change the Python version (`-p` flag) as needed - if you request any Python interpreter
not present on your system, uv will attempt to download it, unless the `--no-python-downloads` option is given.
For information on how to install uv, refer to the official documentation at
https://docs.astral.sh/uv/getting-started/installation/

```shell
# Note that many LTS distros will bundle a version of pip itself that is too
# old to download all of the latest binaries for certain platforms.
# The pip version can be obtained with `python -m pip --version`, and for
Expand All @@ -46,11 +61,13 @@ source ~/.venv/mlirdev/bin/activate
# It is recommended to upgrade pip:
python -m pip install --upgrade pip


# Now the `python` command will resolve to your virtual environment and
# packages will be installed there.
python -m pip install -r mlir/python/requirements.txt

# In a uv-generated virtual environment, you can instead run:
uv pip install -r mlir/python/requirements.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious - the uv prefix is necessary even after source ~/.venv/mlirdev/bin/activate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In fact, uv's resolver is arguably their main feature, so it would miss the point to drop the uv here (even though --seed does install normal pip).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense!


# Now run your build command with `cmake`, `ninja`, et al.

# Run mlir tests. For example, to run Python bindings tests only using ninja:
Expand Down Expand Up @@ -228,7 +245,8 @@ For example if `py_op1` and `py_op2` wrap the same operation under a root `py_op
transformed such that the operation referenced (by `py_op1`, `py_op2`) is erased. Then `py_op1`, `py_op2`
become "undefined" in a sense; manipulating them in any way is "formally forbidden". Note, this also applies to
`SymbolTable` mutation, which is considered a transformation of the root `SymbolTable`-supporting operation for the
purposes of the discussion here. Metaphorically, one can think of this similarly to how STL container iterators are invalidated once the container itself is changed. The "best practices" recommendation is to structure your code such that
purposes of the discussion here. Metaphorically, one can think of this similarly to how STL container iterators are invalidated
once the container itself is changed. The "best practices" recommendation is to structure your code such that

1. First, query/manipulate various Python wrapper objects `py_op1`, `py_op2`, `py_op3`, etc.;
2. Second, transform the AST/erase operations/etc. via a single root object;
Expand Down
Loading