Skip to content

Commit

Permalink
Merge pull request #454 from PrincetonUniversity/issue-161
Browse files Browse the repository at this point in the history
Migrate from poetry to uv
  • Loading branch information
icui authored Mar 5, 2025
2 parents d53af06 + 98ad071 commit 98b6fa6
Show file tree
Hide file tree
Showing 15 changed files with 1,922 additions and 3,672 deletions.
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _architecture:

SPECFEM++ Architecture
====================
======================

SPECFEM++ is designed with portability and modularity as primary goals. The goal is develop a code that is easy to maintain and extend, while maintaining performance characteristics of original `SPECFEM2D solver <https://specfem2d.readthedocs.io>`_. This is achieved using C++ templatized classes.

Expand Down
6 changes: 3 additions & 3 deletions docs/developer_documentation/git_workflow.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Git development workflow
=========================
========================

At SPECFEM++ we follow master-develop workflow. The master (main) branch is always a stable working code and is generally synced with the latest release of SPECFEM++. The develop branch is a stable code with potentially new features which haven't been released in the latest version of SPECFEM++ yet. If you are contributing to SPECFEM++ then issue your `pull request <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests>`_ against the develop branch.

Expand All @@ -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.

.. 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
48 changes: 19 additions & 29 deletions docs/developer_documentation/style.rst
Original file line number Diff line number Diff line change
@@ -1,72 +1,62 @@
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.

Install poetry
~~~~~~~~~~~~~~~
Install uv
~~~~~~~~~~

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
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

0 comments on commit 98b6fa6

Please sign in to comment.