Skip to content

Commit 9d2fb53

Browse files
authored
migrate to uv (#54)
* uv initial support * building * linter fix * pre-commit update * fix typings
1 parent 2f349c6 commit 9d2fb53

File tree

15 files changed

+3795
-58
lines changed

15 files changed

+3795
-58
lines changed

.github/workflows/codestyle.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,30 @@ on:
1212
jobs:
1313
build:
1414
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version:
18+
- "3.9"
19+
- "3.10"
20+
- "3.11"
21+
- "3.12"
1522
steps:
16-
- uses: actions/checkout@v3
17-
- name: Set up Python 3.10
18-
uses: actions/setup-python@v4
23+
- uses: actions/checkout@v5
24+
- name: Install uv
25+
uses: astral-sh/setup-uv@v7
1926
with:
20-
python-version: "3.10"
27+
version: "0.9.17"
28+
enable-cache: true
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Set up Python
32+
run: uv python install
33+
2134
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
pip install -e ".[dev]"
35+
run: uv sync --locked --all-extras --dev
2536
- name: check codestyle
2637
run: |
27-
ruff check --config pyproject.toml --diff .
38+
uv run ruff check --config pyproject.toml --diff .
2839
- name: check type hints
2940
run: |
30-
pyright --project=pyproject.toml src/xminigrid
41+
uv run pyright --project=pyproject.toml

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,6 @@ src/xminigrid/envs/xland_tmp.py
175175
scripts/*testing*
176176
configs/wip
177177
scripts/eval_example.py
178+
179+
.ruff_cache/
180+
.pyright/

.pre-commit-config.yaml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
default_stages: [pre-commit]
2+
fail_fast: false
3+
14
repos:
2-
# ruff checking
3-
- repo: https://github.com/astral-sh/ruff-pre-commit
4-
rev: v0.6.0
5+
- repo: local
56
hooks:
6-
# Run the linter.
77
- id: ruff
8-
args: [--fix]
9-
# Run the formatter.
8+
name: ruff (lint)
9+
entry: uv run ruff check --fix
10+
language: system
11+
types_or: [python, pyi]
12+
require_serial: true
13+
1014
- id: ruff-format
15+
name: ruff (format)
16+
entry: uv run ruff format
17+
language: system
18+
types_or: [python, pyi]
19+
require_serial: true
1120

12-
# pyright checking
13-
- repo: https://github.com/RobertCraigie/pyright-python
14-
rev: v1.1.376
15-
hooks:
1621
- id: pyright
17-
args: [--project=pyproject.toml]
22+
name: pyright
23+
entry: uv run pyright --project=pyproject.toml
24+
language: system
25+
types_or: [python, pyi]
26+
require_serial: true
27+
pass_filenames: false

CONTRIBUTING.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Do not be afraid to ask questions and share new ideas about possible directions
1313

1414
## Contributing to the codebase
1515

16-
Contributing code is done through standard github methods:
16+
We use uv for dependency management and virtual environments. Contributing code is done through standard github methods:
1717

1818
1. Fork this repo
1919
2. Make a change and commit your code
@@ -22,8 +22,22 @@ Contributing code is done through standard github methods:
2222
```commandline
2323
git clone [email protected]:corl-team/xland-minigrid.git
2424
cd xland-minigrid
25-
pip install -e ".[dev]"
25+
26+
# Create and sync the development environment
27+
uv venv
28+
uv sync --extra dev --extra baselines
29+
```
30+
31+
Add new dependencies using:
32+
2633
```
34+
uv add <package>
35+
36+
# development-only dependencies
37+
uv add <package> --group dev
38+
```
39+
40+
Do not use pip install for project dependencies, as it bypasses the lockfile and may cause inconsistent environments.
2741

2842
## Code style
2943

@@ -32,17 +46,17 @@ The CI will run several checks on the new code pushed to the repository.
3246
These checks can also be run locally without waiting for the CI by following the steps below:
3347

3448
1. install [pre-commit](https://pre-commit.com/#install)
35-
2. install the Git hooks by running `pre-commit install`
49+
2. install the Git hooks by running `uv run pre-commit install`
3650

3751
Once those two steps are done, the Git hooks will be run automatically at
3852
every new commit. The Git hooks can also be run manually with
39-
`pre-commit run --all-files`, and if needed they can be
53+
`uv run pre-commit run`, and if needed they can be
4054
skipped (not recommended) with `git commit --no-verify`.
4155

42-
Be sure to run and fix all issues from the `pre-commit run --all-files` before the push!
43-
If you want to see possible problems before pre-commit, you can run `ruff check --diff .`
44-
and `ruff format --check` to see exact linter and formatter suggestions and possible fixes.
45-
Similarly, run `pyright src/xminigrid` to see possible problems with type hints.
56+
Be sure to run and fix all issues from the `uv run pre-commit run --all-files` before the push!
57+
If you want to see possible problems before pre-commit, you can run `uv run ruff check --diff .`
58+
and `uv run ruff format --check` to see exact linter and formatter suggestions and possible fixes.
59+
Similarly, run `uv run pyright src/xminigrid` to see possible problems with type hints.
4660

4761
# License
4862

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ How cool is that? For more details, take a look at the [technical paper](https:/
6767
The latest release of XLand-MiniGrid can be installed directly from PyPI:
6868

6969
```commandline
70-
pip install xminigrid
70+
uv add xminigrid (or pip install xminigrid)
7171
# or, from github directly
72-
pip install "xminigrid @ git+https://github.com/corl-team/xland-minigrid.git"
72+
uv pip install "xminigrid @ git+https://github.com/corl-team/xland-minigrid.git"
7373
```
7474

7575
Alternatively, if you want to install the latest development version from the GitHub and run provided algorithms or scripts,
@@ -78,8 +78,8 @@ install the source as follows:
7878
git clone [email protected]:corl-team/xland-minigrid.git
7979
cd xland-minigrid
8080
81-
# additional dependencies for baselines
82-
pip install -e ".[dev,baselines]"
81+
# additional dependencies for dev and baselines
82+
uv sync --all-extras --dev
8383
```
8484
Note that the installation of JAX may differ depending on your hardware accelerator!
8585
We advise users to explicitly install the correct JAX version (see the [official installation guide](https://github.com/google/jax#installation)).

pyproject.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ readme = "README.md"
55
requires-python =">=3.9"
66
license = {file = "LICENSE"}
77
authors = [
8-
{name = "Alexander Nikulin", email = "[email protected]"},
8+
{name = "Alexander Nikulin", email = "[email protected]"},
99
]
1010
dynamic = ["version"]
1111

@@ -62,9 +62,16 @@ baselines = [
6262

6363

6464
[build-system]
65-
requires = ["setuptools>=61.0"]
65+
requires = ["setuptools>=61.0", "wheel"]
6666
build-backend = "setuptools.build_meta"
6767

68+
69+
[tool.setuptools]
70+
package-dir = {"" = "src"}
71+
72+
[tool.setuptools.packages.find]
73+
where = ["src"]
74+
6875
[tool.setuptools.dynamic]
6976
version = {attr = "xminigrid.__version__"}
7077

@@ -96,9 +103,13 @@ known-third-party = ["wandb"]
96103
include = ["src/xminigrid"]
97104
exclude = [
98105
'training',
106+
'scripts',
99107
"**/node_modules",
100108
"**/__pycache__",
101109
]
110+
executionEnvironments = [
111+
{ root = "src" }
112+
]
102113
reportMissingImports = "none"
103114
reportMissingTypeStubs = false
104115
reportMissingModuleSource = false

setup.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/xminigrid/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .registration import make, register, registered_environments
33

44
# TODO: add __all__
5-
__version__ = "0.9.1"
5+
__version__ = "0.9.2"
66

77
# ---------- XLand-MiniGrid environments ----------
88

src/xminigrid/core/goals.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@ def check_goal(
4444
# should I inherit from abc.ABC?
4545
class BaseGoal(struct.PyTreeNode):
4646
@abc.abstractmethod
47-
def __call__(self, grid: GridState, agent: AgentState, action: int | jax.Array, position: jax.Array) -> jax.Array:
48-
...
47+
def __call__(
48+
self, grid: GridState, agent: AgentState, action: int | jax.Array, position: jax.Array
49+
) -> jax.Array: ...
4950

5051
@classmethod
5152
@abc.abstractmethod
52-
def decode(cls, encoding: jax.Array) -> BaseGoal:
53-
...
53+
def decode(cls, encoding: jax.Array) -> BaseGoal: ...
5454

5555
@abc.abstractmethod
56-
def encode(self) -> jax.Array:
57-
...
56+
def encode(self) -> jax.Array: ...
5857

5958

6059
class EmptyGoal(BaseGoal):

src/xminigrid/core/rules.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,14 @@ class BaseRule(struct.PyTreeNode):
5252
@abc.abstractmethod
5353
def __call__(
5454
self, grid: GridState, agent: AgentState, action: int | jax.Array, position: jax.Array
55-
) -> tuple[GridState, AgentState]:
56-
...
55+
) -> tuple[GridState, AgentState]: ...
5756

5857
@classmethod
5958
@abc.abstractmethod
60-
def decode(cls, encoding: jax.Array) -> BaseRule:
61-
...
59+
def decode(cls, encoding: jax.Array) -> BaseRule: ...
6260

6361
@abc.abstractmethod
64-
def encode(self) -> jax.Array:
65-
...
62+
def encode(self) -> jax.Array: ...
6663

6764

6865
# TODO: checks on only some actions can produce bugs, but it is faster. If it's going to cause trouble, reconsider.

0 commit comments

Comments
 (0)