# Contributing Guidelines

*Pull requests, bug reports, and all other forms of contribution are welcomed and highly encouraged!* :octocat:

### Contents

- [Code of Conduct](#book-code-of-conduct)
- [Asking Questions](#bulb-asking-questions)
- [Opening an Issue](#inbox_tray-opening-an-issue)
- [Feature Requests](#love_letter-feature-requests)
- [Triaging Issues](#mag-triaging-issues)
- [Submitting Pull Requests](#repeat-submitting-pull-requests)
- [Writing Commit Messages](#memo-writing-commit-messages)
- [Code Review](#white_check_mark-code-review)
- [Coding Style](#nail_care-coding-style)
- [Certificate of Origin](#medal_sports-certificate-of-origin)

> **This guide serves to set clear expectations for everyone involved with the project so that we can improve it seekr while also creating a welcoming space for everyone to participate. Following these guidelines will help ensure a positive experience for contributors and maintainers.**

## Contributing Code

To contribute to this project, please follow the ["fork and pull request"](https://docs.github.com/en/get-started/quickstart/contributing-to-projects) workflow.
Please do not try to push directly to this repo unless you are a maintainer.

Please follow the checked-in pull request template when opening pull requests. Note related issues and tag relevant
maintainers.

Pull requests cannot land without passing the formatting, linting, and testing checks first. See [Testing](#running-tests) and
[Formatting and Linting](#formatting-and-linting) for how to run these checks locally.

### Dependency Management: uv and other env/dependency managers

This project uses [uv](https://docs.astral.sh/uv/) for dependency management, environment syncing, locking, and package workflows.

❗Note: *Before installing uv*, if you use `Conda`, create and activate a new Conda env (e.g. `conda create -n seekrflow python=3.10`)

Install uv: **[documentation on how to install it](https://docs.astral.sh/uv/getting-started/installation/)**.

### Local Development Dependencies

Install SeekrFlow development requirements (for running SeekrFlow, running examples, linting, formatting, and tests):

```bash
uv sync --group dev --group quality --group tests
```

And set up pre-commit for auto-formatting and linting
```bash
uv run --group dev pre-commit install
```

### Formatting and Linting

Run these locally before submitting a PR; the CI system will check also.

```
$ make check
```

### Running tests

#### Unit Tests

```bash
make tests
```

#### Integration Tests
> 🚧 Warning: Integration Tests requires an API key to be exported and you will be charged for usage. It is recommended to let the CI system handle integration tests.

```bash
make integration_tests
```

### Working with Optional Dependencies

If you're adding a new dependency to SeekrFlow, add it to the narrowest dependency scope that fits the use case.

Use runtime dependencies for user-facing library requirements, and `dependency-groups` for development-only tooling such as tests, linting, or local developer utilities.

To introduce the dependency to the `pyproject.toml` file correctly, please do the following:

1. Add the dependency with uv.
  ```bash
  uv add [package_name]
  ```
2. If the dependency is only needed for a tooling/test workflow, add it to the appropriate group instead.
  ```bash
  uv add --group tests [package_name]
  ```
3. Refresh the lockfile after editing dependency declarations directly.
  ```bash
  uv lock
  ```
4. Add a unit test that at the very least attempts to import the new code. Ideally, the unit
test makes use of lightweight fixtures to test the logic of the code.
5. Please use the `@pytest.mark.requires(package_name)` decorator for any tests that require the dependency.

## :memo: Writing Commit Messages

This repository uses semantic-release and conventional commits for automated versioning and release tagging.

At least one commit in every merge request must follow conventional commit format:

```text
type(scope): short description
```

Examples:

- `feat(client): add async retry support for ingestion jobs`
- `fix(files): handle empty upload metadata payload`
- `chore(ci): update release workflow tag handling`

## :rocket: Release Process

This repository currently uses a split release process:

- Internal package releases are automated from `main` through GitLab CI.
- Public PyPI releases remain manual and are triggered through the GitHub Release workflow.
- The GitHub Release workflow must publish from the semantic-release-created tag/version so the public package matches the internal release.
- The GitLab internal release and the GitHub/PyPI public release are intentionally separate workflows.


## :repeat: Submitting Pull Requests

We **love** pull requests! Before [forking the repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo) and [creating a pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/proposing-changes-to-your-work-with-pull-requests) for non-trivial changes, it is usually best to first open an issue to discuss the changes, or discuss your intended approach for solving the problem in the comments for an existing issue.

For most contributions, after your first pull request is accepted and merged, you will be [invited to the project](https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/inviting-collaborators-to-a-personal-repository) and given **push access**. :tada:

*Note: All contributions will be licensed under the project's license.*

- **Smaller is better.** Submit **one** pull request per bug fix or feature. A pull request should contain isolated changes pertaining to a single bug fix or feature implementation. **Do not** refactor or reformat code that is unrelated to your change. It is better to **submit many small pull requests** rather than a single large one. Enormous pull requests will take enormous amounts of time to review, or may be rejected alseekrflow.

- **Coordinate bigger changes.** For large and non-trivial changes, open an issue to discuss a strategy with the maintainers. Otherwise, you risk doing a lot of work for nothing!

- **Prioritize understanding over cleverness.** Write code clearly and concisely. Remember that source code usually gets written once and read often. Ensure the code is clear to the reader. The purpose and logic should be obvious to a reasonably skilled developer, otherwise you should add a comment that explains it.

- **Follow existing coding style and conventions.** Keep your code consistent with the style, formatting, and conventions in the rest of the code base. When possible, these will be enforced with a linter. Consistency makes it easier to review and modify in the future.

- **Include test coverage.** Add unit tests or integration tests when possible. Follow existing patterns for implementing tests.

- **Update the examples** if one exists to exercise any new functionality you have added.

- **Add documentation.** Document your changes with code doc comments or in existing guides.

- **[Resolve any merge conflicts](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/resolving-a-merge-conflict-on-github)** that occur.

- **Promptly address any CI failures**. If your pull request fails to build or pass tests, please push another commit to fix it.

- When writing comments, use properly constructed sentences, including punctuation.

- Use spaces, not tabs.


## :medal_sports: Certificate of Origin

*Developer's Certificate of Origin 1.1*

By making a contribution to this project, I certify that:

> 1. The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
> 1. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
> 1. The contribution was provided directly to me by some other person who certified (1), (2) or (3) and I have not modified it.
> 1. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
