Skip to content

Files

Latest commit

 Cannot retrieve latest commit at this time.

History

History
123 lines (77 loc) · 5.06 KB

DEVELOPMENT.md

File metadata and controls

123 lines (77 loc) · 5.06 KB

Development

This project uses the Hatch project manager (installation instructions).

Hatch automatically manages dependencies and runs testing, type checking, and other operations in isolated environments.

Testing

You can run the tests on your local machine with:

hatch test

The test command supports options such as -c for measuring test coverage, -a for testing with a matrix of Python versions, and appending an argument like tests/test_codex_tool.py::test_to_llamaindex_tool for running a single test.

Type checking

You can run the mypy static type checker with:

hatch run types:check

Formatting and linting

You can run the Ruff formatter and linter with:

hatch fmt

This will automatically make safe fixes to your code. If you want to only check your files without making modifications, run hatch fmt --check.

Pre-commit

You can install the pre-commit hooks to automatically run type checking, formatting, and linting on every commit.

First, install [pre-commit][pre-commit], for example, with pipx:

pipx install pre-commit

Then, install the hooks:

pre-commit install

Packaging

You can use hatch build to create build artifacts, a source distribution ("sdist") and a built distribution ("wheel").

You can use hatch publish if you want to manually publish build artifacts to PyPI.

Automated releases

Automated releases are handled by the release workflow which is triggered by pushing a new tag to the repository. To create a new release:

  1. Bump the version in src/cleanlab_codex/__about__.py. You can use the hatch version command to do this.
  2. Ensure that the release notes are updated in CHANGELOG.md:
    • You should update the [Unreleased] header to the new version and add a new [Unreleased] section at the top of the file.
    • You should update the link for the [Unreleased] code and add a new link to the code diff for the new version.
  3. Create a PR and merge these changes into the main branch.
  4. After the PR is merged into main, create a new release tag by running git tag v<output of hatch version> (i.e. git tag v0.0.1).
  5. Push the tag to the repository by running git push origin <tag>.
  6. This will trigger the release workflow which will build the package, create a release on GitHub, and publish the package version to PyPI. The GitHub release notes will be automatically generated from the changelog.

How to build and install the package locally

You may want to build and install the package locally - for example, to see how your changes affect other Python code in a script or Jupyter notebook.

To do this, you can build the package with hatch build and then install it in your local environment with pip install dist/cleanlab_codex-<version>-py3-none-any.whl.

Alternatively, you can use pip install -e /path/to/cleanlab-codex to install the package from your local code. Note that if you make further local changes after that, you may need to reload the module, i.e. reload(cleanlab_codex), or restart the kernel.

Continuous integration

Testing, type checking, and formatting/linting is checked in CI.

Developing against different environments

To target a different Codex backend environment (i.e. staging or local), set the CODEX_BASE_URL environment variable. Example: export CODEX_BASE_URL=http://localhost:8080.

Style guide

Adding integrations with external libraries

When adding integrations with external libraries, always use a lazy import. The external dependency should not be required to use the cleanlab-codex library. Wrap the lazy import in a try/except block to catch the ImportError and raise a MissingDependencyError with a helpful message. See codex_tool.py file for examples one of which is shown below:

try:
    from cleanlab_codex.utils.smolagents import CodexTool as SmolagentsCodexTool
except ImportError as e:
    raise MissingDependencyError("smolagents", "https://github.com/huggingface/smolagents") from e