Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from poetry to uv #454

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v15.0.6"
rev: "v19.1.7"
hooks:
- id: clang-format
types_or: [c++]
Expand Down
4 changes: 2 additions & 2 deletions docs/developer_documentation/git_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ To make a change to SPECFEM++ (This development workflow is similar to the one s

.. note::

It is also recommended that you run :code:`poetry install` every time you pull the develop branch. Please check :ref:`style section<style>` for more information on poetry.
It is also recommended that you run :code:`uv sync --extra dev` every time you pull the develop branch. Please check :ref:`style section<style>` for more information on uv.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The underline in this file's header is too long


.. note::

Please also install pre-commit hooks after you've cloned repo. :code:`poetry run pre-commit install`
Please also install pre-commit hooks after you've cloned repo. :code:`uv run pre-commit install`

- Next create a feature branch against develop branch called a feature branch. Please be explicit while naming the feature branch.

Expand Down
46 changes: 18 additions & 28 deletions docs/developer_documentation/style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,59 @@ Style
Pre-commit
----------

SPECFEM++ uses pre-commit to check style. Pre-commit can be installed inside python virtual environments. There are several methods for creating virtual environments, but I've found poetry tool is great at managing python environments. Especailly in collaborative environments poetry gives easy method for managing consistency of environments between all contributors via :code:`pyproject.toml` and :code:`poetry.lock` files.
SPECFEM++ uses pre-commit to check style. Pre-commit can be installed inside python virtual environments. There are several methods for creating virtual environments, but I've found uv tool is great at managing python environments. Especailly in collaborative environments uv gives easy method for managing consistency of environments between all contributors via :code:`pyproject.toml` and :code:`uv.lock` files.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Header here at the very top is too long.


Install poetry
~~~~~~~~~~~~~~~
Install uv
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also the underline for headers in RST files require the exact length of the title string

~~~~~~~~~~

Download and install poetry using the `official instructions <https://python-poetry.org/docs/#installation>`_.
Download and install uv using the `official instructions <https://docs.astral.sh/uv/getting-started/installation>`_.

Install SPECFEM++ development environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: bash

poetry install
uv sync --extra dev
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you not need the extra line for the code-block?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't run clang-format for all files yet. Maybe do it after we merge devel to main.

Copy link
Collaborator

Choose a reason for hiding this comment

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

if you run make html in docs, there are a lot of errors but most errors are related to formatting and tell you where the underlines are too short/long


When you run this command one of two things happen,

1. If a correct version of a package already exists within :code:`poetry.lock` file then poetry installs that version. Here the assumption is that a `poetry.lock` already exists, if not then one is created for you (within SPECFEM++ `poetry.lock` should already exist). `poetry.lock` ensures that all developers have consistent environments.
1. If a correct version of a package already exists within :code:`uv.lock` file then uv installs that version. Here the assumption is that a `uv.lock` already exists, if not then one is created for you (within SPECFEM++ `uv.lock` should already exist). `uv.lock` ensures that all developers have consistent environments.

2. If a correct version of a package doesn't exist within :code:`poetry.lock` then poetry will install a correct version and update `poetry.lock` file.
2. If a correct version of a package doesn't exist within :code:`uv.lock` then uv will install a correct version and update `uv.lock` file.

.. note::

Make sure you commit :code:`poetry.lock` and :code:`pyproject.toml` files upstream to the remote if you add any packages.
Make sure you commit :code:`uv.lock` and :code:`pyproject.toml` files upstream to the remote if you add any packages.

.. note::

It is also recommended that you run :code:`poetry install` every time you pull the develop branch
It is also recommended that you run :code:`uv sync --extra dev` every time you pull the develop branch

Using your python/poetry environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using your python/uv environment
Copy link
Collaborator

Choose a reason for hiding this comment

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

here

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you're in the SPECFEM++ root directory you should have access to the poetry environment. To run a command within the environment either

1. Explicitly activate the environment using :code:`poetry shell` as shown below

.. code-block:: bash

poetry shell
python <script_name>.py

Or

2. Directly run the command within environment using :code:`poetry run`
If you're in the SPECFEM++ root directory with an IDE with Python support, you should have access to the uv environment directly.
To explicitly activate the environment, you can run the following command

.. code-block:: bash

poetry run python <script_name>.py
source .venv/bin/activate

Pre-commit hooks
~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~

Next, we install pre-commit hooks to check style. Pre-commit hooks are defined in :code:`.pre-commit-config.yaml` within SPECFEM++ root directory. More documentation on pre-commit hooks can be found `here <https://pre-commit.com/hooks.html>`_.

To enable the hooks (This only needs to be done when you clone the repo or there is an update to :code:`.pre-commit-config.yaml`)

.. code-block:: bash

poetry run pre-commit install
uv run pre-commit install

After this, pre-commit should run every time you commit a change. Ensuring that coding style is consistent across all developers.

To manually run pre-commit on all files

.. code-block:: bash

poetry run pre-commit run --all-files
uv run pre-commit run --all-files
14 changes: 7 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ The examples use [snakemake](https://snakemake.readthedocs.io/en/stable/) to run

## Running the examples

To run the examples, you first need to install poetry following these [instructions](https://python-poetry.org/docs/#installation). Once you've done so, you can install the dependencies for the examples by running the following command in the current directory:
To run the examples, you first need to install uv following these [instructions](https://docs.astral.sh/uv/getting-started/installation). Once you've done so, you can install the dependencies for the examples by running the following command in the current directory:

```bash
# verify poetry is installed
poetry --version
# verify uv is installed
uv --version

# install dependencies
poetry install
uv sync --extra examples

```

Expand All @@ -26,10 +26,10 @@ After installing the dependencies, you can run the examples by running the follo
cd <example directory>

# run the example
poetry run snakemake -j 1
uv run snakemake -j 1

# or to run the example on a slurm cluster
poetry run snakemake --executor slurm -j 1
uv run snakemake --executor slurm -j 1

```

Expand All @@ -40,6 +40,6 @@ To clean up the example directory, you can run the following command in the dire
```bash

# clean up the example
poetry run snakemake clean
uv run snakemake clean -j 1

```
17 changes: 10 additions & 7 deletions examples/Tromp_2005/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ This example reproduces the results from Fig 9 of [Tromp et al. 2005](https://do

## Running the examples

To run the examples, you first need to install poetry following these [instructions](https://python-poetry.org/docs/#installation). Once you've done so, you can install the dependencies for the examples by running the following command in the current directory:
To run the examples, you first need to install uv following these
[instructions](https://docs.astral.sh/uv/getting-started/installation). Once you've done
so, you can install the dependencies for the examples by running the following
command in the current directory:

```bash
# verify poetry is installed
poetry --version
# verify uv is installed
uv --version

# install dependencies
poetry install
uv sync --extra examples

```

Expand All @@ -22,10 +25,10 @@ After installing the dependencies, you can run the examples by running the follo
cd <example directory>

# run the example
poetry run snakemake -j 1
uv run snakemake -j 1

# or to run the example on a slurm cluster
poetry run snakemake --executor slurm -j 1
uv run snakemake --executor slurm -j 1

```

Expand All @@ -36,6 +39,6 @@ To clean up the example directory, you can run the following command in the dire
```bash

# clean up the example
poetry run snakemake clean
uv run snakemake clean -j 1

```
16 changes: 8 additions & 8 deletions examples/fluid-solid-bathymetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ publication [Pipatprathanporn et al.

## Running the examples

To run the examples, you first need to install poetry following these
[instructions](https://python-poetry.org/docs/#installation). Once you've done
To run the examples, you first need to install uv following these
[instructions](https://docs.astral.sh/uv/getting-started/installation). Once you've done
so, you can install the dependencies for the examples by running the following
command in the current directory:

```bash
# verify poetry is installed
poetry --version
# verify uv is installed
uv --version

# install dependencies
poetry install
uv sync --extra examples

```

Expand All @@ -27,10 +27,10 @@ following command within the example directory you want to run:
```bash

# run the example
poetry run snakemake -j 1
uv run snakemake -j 1

# or to run the example on a slurm cluster
poetry run snakemake --executor slurm -j 1
uv run snakemake --executor slurm -j 1

```

Expand Down Expand Up @@ -68,6 +68,6 @@ directory of the example you want to clean up:
```bash

# clean up the example
poetry run snakemake clean
uv run snakemake clean -j 1

```
16 changes: 8 additions & 8 deletions examples/fluid-solid-interface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ guide on this example, please refer to the

## Running the examples

To run the examples, you first need to install poetry following these
[instructions](https://python-poetry.org/docs/#installation). Once you've done
To run the examples, you first need to install uv following these
[instructions](https://docs.astral.sh/uv/getting-started/installation). Once you've done
so, you can install the dependencies for the examples by running the following
command in the current directory:

```bash
# verify poetry is installed
poetry --version
# verify uv is installed
uv --version

# install dependencies
poetry install
uv sync --extra examples

```

Expand All @@ -27,10 +27,10 @@ following command within the example directory you want to run:
```bash

# run the example
poetry run snakemake -j 1
uv run snakemake -j 1

# or to run the example on a slurm cluster
poetry run snakemake --executor slurm -j 1
uv run snakemake --executor slurm -j 1

```

Expand All @@ -42,6 +42,6 @@ directory of the example you want to clean up:
```bash

# clean up the example
poetry run snakemake clean
uv run snakemake clean -j 1

```
17 changes: 10 additions & 7 deletions examples/homogeneous-medium-flat-topography/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ In this example we simulate wave propagation through a 2-dimensional homogeneous

## Running the examples

To run the examples, you first need to install poetry following these [instructions](https://python-poetry.org/docs/#installation). Once you've done so, you can install the dependencies for the examples by running the following command in the current directory:
To run the examples, you first need to install uv following these
[instructions](https://docs.astral.sh/uv/getting-started/installation). Once you've done
so, you can install the dependencies for the examples by running the following
command in the current directory:

```bash
# verify poetry is installed
poetry --version
# verify uv is installed
uv --version

# install dependencies
poetry install
uv sync --extra examples

```

Expand All @@ -20,10 +23,10 @@ After installing the dependencies, you can run the examples by running the follo
```bash

# run the example
poetry run snakemake -j 1
uv run snakemake -j 1

# or to run the example on a slurm cluster
poetry run snakemake --executor slurm -j 1
uv run snakemake --executor slurm -j 1

```

Expand All @@ -34,6 +37,6 @@ To clean up the example directory, you can run the following command in the dire
```bash

# clean up the example
poetry run snakemake clean
uv run snakemake clean -j 1

```
Loading