From f12ebbe6884945f7ec3f997bf6c63e35f0fe6e04 Mon Sep 17 00:00:00 2001 From: Maxine Hartnett Date: Thu, 24 Aug 2023 10:35:44 -0600 Subject: [PATCH] Adding poetry documentation, cleaning up existing naming conventions for the style guide Also includes some notes from the PR, Co-authored-by: Matthew Bourque Update poetry.rst --- .gitignore | 3 + docs/source/development/index.rst | 3 +- docs/source/development/poetry.rst | 108 ++++++++++++++++++ .../api-documentation.rst | 0 .../checklist-for-pull-requests.rst | 0 .../git-and-github-workflow.rst | 0 .../naming-conventions.rst | 0 .../poetry-environment.rst | 2 +- .../python-coding.rst | 0 .../{style_guide => style-guide}/security.rst | 0 .../style-guide.rst | 0 .../tools-and-library-recommendations.rst | 0 .../versioning.rst | 0 docs/source/index.rst | 4 +- 14 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 docs/source/development/poetry.rst rename docs/source/development/{style_guide => style-guide}/api-documentation.rst (100%) rename docs/source/development/{style_guide => style-guide}/checklist-for-pull-requests.rst (100%) rename docs/source/development/{style_guide => style-guide}/git-and-github-workflow.rst (100%) rename docs/source/development/{style_guide => style-guide}/naming-conventions.rst (100%) rename docs/source/development/{style_guide => style-guide}/poetry-environment.rst (91%) rename docs/source/development/{style_guide => style-guide}/python-coding.rst (100%) rename docs/source/development/{style_guide => style-guide}/security.rst (100%) rename docs/source/development/{style_guide => style-guide}/style-guide.rst (100%) rename docs/source/development/{style_guide => style-guide}/tools-and-library-recommendations.rst (100%) rename docs/source/development/{style_guide => style-guide}/versioning.rst (100%) diff --git a/.gitignore b/.gitignore index 1dafa0220..7e4468cea 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ .DS_Store + +# VSCode +.vscode/ diff --git a/docs/source/development/index.rst b/docs/source/development/index.rst index fa70d97f2..8c72310d5 100644 --- a/docs/source/development/index.rst +++ b/docs/source/development/index.rst @@ -39,4 +39,5 @@ A typical development workflow might look like the following: doc-overview release-workflow - style_guide/style-guide \ No newline at end of file + style-guide/style-guide + poetry \ No newline at end of file diff --git a/docs/source/development/poetry.rst b/docs/source/development/poetry.rst new file mode 100644 index 000000000..bc964c41b --- /dev/null +++ b/docs/source/development/poetry.rst @@ -0,0 +1,108 @@ +.. _poetry-link: + +Poetry +====== + +We are using `Poetry `_ for the dependency management in both ``sds-data-manager`` and ``imap_processing``. All dependency management should go through Poetry. + +.. _poetry-overview-link: + +Poetry overview +--------------- + +Poetry is a tool which provides the ability to manage :ref:`dependencies ` in Python. Although there are lots of tools which do this, including the built-in pip, Poetry has several specific advantages: + +#. Poetry allows you to "lock" dependency versions in place. +#. Poetry will automatically determine if dependencies are compatible. +#. Poetry can provide dependency groups, which allow you to specify which subset of dependencies you would like to install. + +These advantages ensure that we can all install the same versions of tools, that these versions are compatible with each other, and that we can manage dependencies in a fine tuned way. When you run ``poetry install`` to install your dependencies, you can be confident that they are the dependency versions that other people have been testing with. + +Poetry also provides tools for automatically bumping dependency versions only where it makes sense. You can specify when a dependency should get a version change using Poetry's extensive `dependency specification `_ formatting. + +Finally, Poetry provides a :ref:`shell `, which you can use as a virtual environment. This shell is automatically tied to the project directory, and allows developers to install dependency versions in an isolated environment. This means that, for example, if you have a different project using the same package with a different version, you can have each project with it's own version kept separate from conflicts. + +We have a :ref:`Poetry style guide` for specific recommendations about using Poetry in these projects. + +.. _using-poetry-link: + +Using Poetry +------------ + +Poetry can be installed with the `official instructions `_. + +The dependencies for the project are all specified in the ``pyproject.toml`` file in the base level of the repository. + +The Poetry project has a great `basic usage guide `_ which introduces the basic capabilities. This covers the basic commands which are used in installing and managing Poetry. + +You can use Poetry in addition to other Python tools. Unlike with Conda, installing Poetry should not interfere with other projects which may use other tools. You can also use different methods for virtual environments if you prefer, which is covered under the :ref:`Poetry shell section `. Poetry uses pip to install under the hood. + +.. _poetry-dependency-link: + +Adding Dependencies +------------------- + +Poetry has a command to `add a new dependency `_, with an optional version specification: + +:: + + # Add a new dependency + poetry add pendulum@^2.0.5 + + # Add a new dependency with default latest version + poetry add pendulum + +These dependencies are then added automatically to the ``pyproject.toml`` file. The overall project dependencies go under ``[tool.poetry.dependencies]``. The main project dependencies are always installed. + +You can also update the ``pyproject.toml`` file directly, using the existing formatting or the `Poetry documentation on it `_ as a guide. + +After you update any dependencies, you will need to update the lock file:: + poetry lock + +This will create a new version of the ``poetry.lock`` file, which should be committed to the repository. Our pre-commit tools also do this step automatically if needed. + +.. _poetry-dependency-groups-link: + +Dependency groups +^^^^^^^^^^^^^^^^^^ + +Poetry also provides dependency groups for separating dependencies into logical separations. If you are installing the project as an end user, you do not need the development tools. The testing environment does not need the documentation generation dependencies. In our case, the AWS Lambda environment does not need the same dependencies as the CDK deployment. Before you add a dependency to the main group, ask yourself if it would make more sense in one of the other existing dependency groups. + +To add a dependency to an existing group, you can use the ``--group`` flag:: + + poetry add mkdocs --group docs + +These groups can be made optional as well, meaning they will not be installed by default when the user runs ``poetry install``. You can specify what groups to install using the ``--with`` or ``--without`` flags. + +Pip also provides a standard for optional dependencies. These can be installed when using ``pip`` instead of Poetry to install the dependencies. This goes under the ``[tool.poetry.extras]`` section in ``pyproject.toml``. These are separate, but similar to the optional dependencies. They can only be all installed or all not installed, with no splitting out into specific groups like the dependency groups. + +.. _poetry-shell-link: + +Installing and the Poetry Shell +-------------------------------- + +To install the Poetry project, you can use the `install `_ command:: + + # Install main dependencies and any dependency groups which are installed by default + poetry install + + # install without specific dependency groups + poetry install --without test,docs + + # Install with optional dependency groups + poetry install --with lambda_dev + +By default, this command will install dependencies out of the ``poetry.lock`` file. This will also install into your Poetry shell for the project. + +The Poetry shell is a virtual environment tool provided by Poetry. To start the Poetry shell, with your dependencies installed, you can use the poetry `shell `_ command:: + + poetry shell + + # To exit the shell + exit + +However, you are not required to use the Poetry shell as your virtual environment manager if you have another tool you prefer. + +Poetry will, by default, not create a new virtual environment if it detects that it is running in a virtual environment already. So, for example, you can use a `Conda environment `_ by activating the environment first, and then running `poetry install`. + +There are also `settings `_ surrounding the virtual environment that you can change to suit your workflow. diff --git a/docs/source/development/style_guide/api-documentation.rst b/docs/source/development/style-guide/api-documentation.rst similarity index 100% rename from docs/source/development/style_guide/api-documentation.rst rename to docs/source/development/style-guide/api-documentation.rst diff --git a/docs/source/development/style_guide/checklist-for-pull-requests.rst b/docs/source/development/style-guide/checklist-for-pull-requests.rst similarity index 100% rename from docs/source/development/style_guide/checklist-for-pull-requests.rst rename to docs/source/development/style-guide/checklist-for-pull-requests.rst diff --git a/docs/source/development/style_guide/git-and-github-workflow.rst b/docs/source/development/style-guide/git-and-github-workflow.rst similarity index 100% rename from docs/source/development/style_guide/git-and-github-workflow.rst rename to docs/source/development/style-guide/git-and-github-workflow.rst diff --git a/docs/source/development/style_guide/naming-conventions.rst b/docs/source/development/style-guide/naming-conventions.rst similarity index 100% rename from docs/source/development/style_guide/naming-conventions.rst rename to docs/source/development/style-guide/naming-conventions.rst diff --git a/docs/source/development/style_guide/poetry-environment.rst b/docs/source/development/style-guide/poetry-environment.rst similarity index 91% rename from docs/source/development/style_guide/poetry-environment.rst rename to docs/source/development/style-guide/poetry-environment.rst index 597410aec..8c7109724 100644 --- a/docs/source/development/style_guide/poetry-environment.rst +++ b/docs/source/development/style-guide/poetry-environment.rst @@ -3,7 +3,7 @@ Poetry Environment ------------------ -Poetry is used for dependency management within this project. To update dependencies, you can either update +:ref:`_poetry-link ` is used for dependency management within this project. To update dependencies, you can either update ``pyproject.toml`` manually, or use ``poetry add ``. If you do add dependencies, please make sure you define the version numbers mindfully. The best way to do this is to use diff --git a/docs/source/development/style_guide/python-coding.rst b/docs/source/development/style-guide/python-coding.rst similarity index 100% rename from docs/source/development/style_guide/python-coding.rst rename to docs/source/development/style-guide/python-coding.rst diff --git a/docs/source/development/style_guide/security.rst b/docs/source/development/style-guide/security.rst similarity index 100% rename from docs/source/development/style_guide/security.rst rename to docs/source/development/style-guide/security.rst diff --git a/docs/source/development/style_guide/style-guide.rst b/docs/source/development/style-guide/style-guide.rst similarity index 100% rename from docs/source/development/style_guide/style-guide.rst rename to docs/source/development/style-guide/style-guide.rst diff --git a/docs/source/development/style_guide/tools-and-library-recommendations.rst b/docs/source/development/style-guide/tools-and-library-recommendations.rst similarity index 100% rename from docs/source/development/style_guide/tools-and-library-recommendations.rst rename to docs/source/development/style-guide/tools-and-library-recommendations.rst diff --git a/docs/source/development/style_guide/versioning.rst b/docs/source/development/style-guide/versioning.rst similarity index 100% rename from docs/source/development/style_guide/versioning.rst rename to docs/source/development/style-guide/versioning.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 6f2a5e205..e2b885fa5 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -26,11 +26,11 @@ medium and particle acceleration in our galaxy. Together, we can advance our knowledge of the cosmos and pave the way for future discoveries in space exploration. -The [IMAP Website](https://imap.princeton.edu/) contains information about the +The `IMAP Website `_ contains information about the entire mission, including the science goals, the spacecraft, and the instruments. The Science Operations Center (SOC) is responsible for the data processing on the IMAP mission and being developed at -[LASP (Laboratory of Atmospheric and Space Physics)](https://lasp.colorado.edu/). +`LASP (Laboratory of Atmospheric and Space Physics) `_. The explicit code interfaces and structure are described in the :ref:`api`.