-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you not need the extra line for the code-block? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you run |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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