Skip to content

Commit b4d2663

Browse files
authored
CONTRIBUTING.md Quick Start: focus on langchain core; clarify docs and experimental are separate (#10906)
follow up to #7959 , explaining better to focus just on langchain core no dependencies twitter @cjcjameson
1 parent f30b469 commit b4d2663

File tree

5 files changed

+142
-125
lines changed

5 files changed

+142
-125
lines changed

.github/CONTRIBUTING.md

+74-80
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Please do not try to push directly to this repo unless you are a maintainer.
1414
Please follow the checked-in pull request template when opening pull requests. Note related issues and tag relevant
1515
maintainers.
1616

17-
Pull requests cannot land without passing the formatting, linting and testing checks first. See
18-
[Common Tasks](#-common-tasks) for how to run these checks locally.
17+
Pull requests cannot land without passing the formatting, linting and testing checks first. See [Testing](#testing) and
18+
[Formatting and Linting](#formatting-and-linting) for how to run these checks locally.
1919

2020
It's essential that we maintain great documentation and testing. If you:
2121
- Fix a bug
@@ -59,43 +59,85 @@ we do not want these to get in the way of getting good code into the codebase.
5959

6060
## 🚀 Quick Start
6161

62-
> **Note:** You can run this repository locally (which is described below) or in a [development container](https://containers.dev/) (which is described in the [.devcontainer folder](https://github.com/hwchase17/langchain/tree/master/.devcontainer)).
62+
This quick start describes running the repository locally.
63+
For a [development container](https://containers.dev/), see the [.devcontainer folder](https://github.com/hwchase17/langchain/tree/master/.devcontainer).
6364

64-
This project uses [Poetry](https://python-poetry.org/) v1.5.1 as a dependency manager. Check out Poetry's [documentation on how to install it](https://python-poetry.org/docs/#installation) on your system before proceeding.
65+
### Dependency Management: Poetry and other env/dependency managers
6566

66-
❗Note: If you use `Conda` or `Pyenv` as your environment/package manager, avoid dependency conflicts by doing the following first:
67-
1. *Before installing Poetry*, create and activate a new Conda env (e.g. `conda create -n langchain python=3.9`)
68-
2. Install Poetry v1.5.1 (see above)
69-
3. Tell Poetry to use the virtualenv python environment (`poetry config virtualenvs.prefer-active-python true`)
70-
4. Continue with the following steps.
67+
This project uses [Poetry](https://python-poetry.org/) v1.5.1+ as a dependency manager.
68+
69+
❗Note: *Before installing Poetry*, if you use `Conda`, create and activate a new Conda env (e.g. `conda create -n langchain python=3.9`)
70+
71+
Install Poetry: **[documentation on how to install it](https://python-poetry.org/docs/#installation)**.
72+
73+
❗Note: If you use `Conda` or `Pyenv` as your environment/package manager, after installing Poetry,
74+
tell Poetry to use the virtualenv python environment (`poetry config virtualenvs.prefer-active-python true`)
75+
76+
### Core vs. Experimental
7177

7278
There are two separate projects in this repository:
7379
- `langchain`: core langchain code, abstractions, and use cases
74-
- `langchain.experimental`: more experimental code
80+
- `langchain.experimental`: see the [Experimental README](../libs/experimental/README.md) for more information.
81+
82+
Each of these has their own development environment. Docs are run from the top-level makefile, but development
83+
is split across separate test & release flows.
7584

76-
Each of these has their OWN development environment.
77-
In order to run any of the commands below, please move into their respective directories.
78-
For example, to contribute to `langchain` run `cd libs/langchain` before getting started with the below.
85+
For this quickstart, start with langchain core:
7986

80-
To install requirements:
87+
```bash
88+
cd libs/langchain
89+
```
90+
91+
### Local Development Dependencies
92+
93+
Install langchain development requirements (for running langchain, running examples, linting, formatting, tests, and coverage):
8194

8295
```bash
8396
poetry install --with test
8497
```
8598

86-
This will install all requirements for running the package, examples, linting, formatting, tests, and coverage.
99+
Then verify dependency installation:
87100

88-
❗Note: If during installation you receive a `WheelFileValidationError` for `debugpy`, please make sure you are running Poetry v1.5.1. This bug was present in older versions of Poetry (e.g. 1.4.1) and has been resolved in newer releases. If you are still seeing this bug on v1.5.1, you may also try disabling "modern installation" (`poetry config installer.modern-installation false`) and re-installing requirements. See [this `debugpy` issue](https://github.com/microsoft/debugpy/issues/1246) for more details.
101+
```bash
102+
make test
103+
```
89104

90-
Now assuming `make` and `pytest` are installed, you should be able to run the common tasks in the following section. To double check, run `make test` under `libs/langchain`, all tests should pass. If they don't, you may need to pip install additional dependencies, such as `numexpr` and `openapi_schema_pydantic`.
105+
If the tests don't pass, you may need to pip install additional dependencies, such as `numexpr` and `openapi_schema_pydantic`.
91106

92-
## ✅ Common Tasks
107+
If during installation you receive a `WheelFileValidationError` for `debugpy`, please make sure you are running
108+
Poetry v1.5.1+. This bug was present in older versions of Poetry (e.g. 1.4.1) and has been resolved in newer releases.
109+
If you are still seeing this bug on v1.5.1, you may also try disabling "modern installation"
110+
(`poetry config installer.modern-installation false`) and re-installing requirements.
111+
See [this `debugpy` issue](https://github.com/microsoft/debugpy/issues/1246) for more details.
93112

94-
Type `make` for a list of common tasks.
113+
### Testing
95114

96-
### Code Formatting
115+
_some test dependencies are optional; see section about optional dependencies_.
97116

98-
Formatting for this project is done via a combination of [Black](https://black.readthedocs.io/en/stable/) and [isort](https://pycqa.github.io/isort/).
117+
Unit tests cover modular logic that does not require calls to outside APIs.
118+
If you add new logic, please add a unit test.
119+
120+
To run unit tests:
121+
122+
```bash
123+
make test
124+
```
125+
126+
To run unit tests in Docker:
127+
128+
```bash
129+
make docker_tests
130+
```
131+
132+
There are also [integration tests and code-coverage](../libs/langchain/tests/README.md) available.
133+
134+
### Formatting and Linting
135+
136+
Run these locally before submitting a PR; the CI system will check also.
137+
138+
#### Code Formatting
139+
140+
Formatting for this project is done via a combination of [Black](https://black.readthedocs.io/en/stable/) and [ruff](https://docs.astral.sh/ruff/rules/).
99141

100142
To run formatting for this project:
101143

@@ -111,9 +153,9 @@ make format_diff
111153

112154
This is especially useful when you have made changes to a subset of the project and want to ensure your changes are properly formatted without affecting the rest of the codebase.
113155

114-
### Linting
156+
#### Linting
115157

116-
Linting for this project is done via a combination of [Black](https://black.readthedocs.io/en/stable/), [isort](https://pycqa.github.io/isort/), [flake8](https://flake8.pycqa.org/en/latest/), and [mypy](http://mypy-lang.org/).
158+
Linting for this project is done via a combination of [Black](https://black.readthedocs.io/en/stable/), [ruff](https://docs.astral.sh/ruff/rules/), and [mypy](http://mypy-lang.org/).
117159

118160
To run linting for this project:
119161

@@ -131,7 +173,7 @@ This can be very helpful when you've made changes to only certain parts of the p
131173

132174
We recognize linting can be annoying - if you do not want to do it, please contact a project maintainer, and they can help you with it. We do not want this to be a blocker for good code getting contributed.
133175

134-
### Spellcheck
176+
#### Spellcheck
135177

136178
Spellchecking for this project is done via [codespell](https://github.com/codespell-project/codespell).
137179
Note that `codespell` finds common typos, so it could have false-positive (correctly spelled but rarely used) and false-negatives (not finding misspelled) words.
@@ -157,17 +199,7 @@ If codespell is incorrectly flagging a word, you can skip spellcheck for that wo
157199
ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure'
158200
```
159201

160-
### Coverage
161-
162-
Code coverage (i.e. the amount of code that is covered by unit tests) helps identify areas of the code that are potentially more or less brittle.
163-
164-
To get a report of current coverage, run the following:
165-
166-
```bash
167-
make coverage
168-
```
169-
170-
### Working with Optional Dependencies
202+
## Working with Optional Dependencies
171203

172204
Langchain relies heavily on optional dependencies to keep the Langchain package lightweight.
173205

@@ -192,51 +224,7 @@ To introduce the dependency to the pyproject.toml file correctly, please do the
192224
test makes use of lightweight fixtures to test the logic of the code.
193225
5. Please use the `@pytest.mark.requires(package_name)` decorator for any tests that require the dependency.
194226

195-
### Testing
196-
197-
See section about optional dependencies.
198-
199-
#### Unit Tests
200-
201-
Unit tests cover modular logic that does not require calls to outside APIs.
202-
203-
To run unit tests:
204-
205-
```bash
206-
make test
207-
```
208-
209-
To run unit tests in Docker:
210-
211-
```bash
212-
make docker_tests
213-
```
214-
215-
If you add new logic, please add a unit test.
216-
217-
218-
219-
#### Integration Tests
220-
221-
Integration tests cover logic that requires making calls to outside APIs (often integration with other services).
222-
223-
**warning** Almost no tests should be integration tests.
224-
225-
Tests that require making network connections make it difficult for other
226-
developers to test the code.
227-
228-
Instead favor relying on `responses` library and/or mock.patch to mock
229-
requests using small fixtures.
230-
231-
To run integration tests:
232-
233-
```bash
234-
make integration_tests
235-
```
236-
237-
If you add support for a new external API, please add a new integration test.
238-
239-
### Adding a Jupyter Notebook
227+
## Adding a Jupyter Notebook
240228

241229
If you are adding a Jupyter Notebook example, you'll want to install the optional `dev` dependencies.
242230

@@ -259,6 +247,12 @@ When you run `poetry install`, the `langchain` package is installed as editable
259247
While the code is split between `langchain` and `langchain.experimental`, the documentation is one holistic thing.
260248
This covers how to get started contributing to documentation.
261249

250+
From the top-level of this repo, install documentation dependencies:
251+
252+
```bash
253+
poetry install
254+
```
255+
262256
### Contribute Documentation
263257

264258
The docs directory contains Documentation and API Reference.

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ spell_fix:
4242
######################
4343

4444
help:
45-
@echo '----'
45+
@echo '===================='
46+
@echo '-- DOCUMENTATION --'
4647
@echo 'clean - run docs_clean and api_docs_clean'
4748
@echo 'docs_build - build the documentation'
4849
@echo 'docs_clean - clean the documentation build artifacts'
@@ -51,4 +52,5 @@ help:
5152
@echo 'api_docs_clean - clean the API Reference documentation build artifacts'
5253
@echo 'api_docs_linkcheck - run linkchecker on the API Reference documentation'
5354
@echo 'spell_check - run codespell on the project'
54-
@echo 'spell_fix - run codespell on the project and fix the errors'
55+
@echo 'spell_fix - run codespell on the project and fix the errors'
56+
@echo '-- TEST and LINT tasks are within libs/*/ per-package --'

libs/experimental/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Some of the code here may be marked with security notices. However,
1313
given the exploratory and experimental nature of the code in this package,
1414
the lack of a security notice on a piece of code does not mean that
1515
the code in question does not require additional security considerations
16-
in order to be safe to use.
16+
in order to be safe to use.

libs/langchain/Makefile

+1-28
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,6 @@ coverage:
1414
--cov-report xml \
1515
--cov-report term-missing:skip-covered
1616

17-
######################
18-
# DOCUMENTATION
19-
######################
20-
21-
clean: docs_clean api_docs_clean
22-
23-
24-
docs_build:
25-
docs/.local_build.sh
26-
27-
docs_clean:
28-
rm -r docs/_dist
29-
30-
docs_linkcheck:
31-
poetry run linkchecker docs/_dist/docs_skeleton/ --ignore-url node_modules
32-
33-
api_docs_build:
34-
poetry run python docs/api_reference/create_api_rst.py
35-
cd docs/api_reference && poetry run make html
36-
37-
api_docs_clean:
38-
rm -f docs/api_reference/api_reference.rst
39-
cd docs/api_reference && poetry run make clean
40-
41-
api_docs_linkcheck:
42-
poetry run linkchecker docs/api_reference/_build/html/index.html
43-
4417
# Define a variable for the test file path.
4518
TEST_FILE ?= tests/unit_tests/
4619

@@ -98,7 +71,6 @@ spell_fix:
9871

9972
help:
10073
@echo '===================='
101-
@echo '-- DOCUMENTATION --'
10274
@echo 'clean - run docs_clean and api_docs_clean'
10375
@echo 'docs_build - build the documentation'
10476
@echo 'docs_clean - clean the documentation build artifacts'
@@ -120,3 +92,4 @@ help:
12092
@echo 'test_watch - run unit tests in watch mode'
12193
@echo 'integration_tests - run integration tests'
12294
@echo 'docker_tests - run unit tests in docker'
95+
@echo '-- DOCUMENTATION tasks are from the top-level Makefile --'

libs/langchain/tests/README.md

+62-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,52 @@
1-
# Readme tests(draft)
1+
# Langchain Tests
22

3-
## Integrations Tests
3+
## Unit Tests
4+
5+
Unit tests cover modular logic that does not require calls to outside APIs.
6+
If you add new logic, please add a unit test.
7+
8+
To run unit tests:
9+
10+
```bash
11+
make test
12+
```
13+
14+
To run unit tests in Docker:
15+
16+
```bash
17+
make docker_tests
18+
```
19+
20+
## Integration Tests
21+
22+
Integration tests cover logic that requires making calls to outside APIs (often integration with other services).
23+
If you add support for a new external API, please add a new integration test.
24+
25+
**warning** Almost no tests should be integration tests.
26+
27+
Tests that require making network connections make it difficult for other
28+
developers to test the code.
29+
30+
Instead favor relying on `responses` library and/or mock.patch to mock
31+
requests using small fixtures.
32+
33+
To install dependencies for integration tests:
34+
35+
```bash
36+
poetry install --with test_integration
37+
```
38+
39+
To run integration tests:
40+
41+
```bash
42+
make integration_tests
43+
```
444

545
### Prepare
646

7-
This repository contains functional tests for several search engines and databases. The
8-
tests aim to verify the correct behavior of the engines and databases according to their
9-
specifications and requirements.
47+
The integration tests exercise several search engines and databases. The tests
48+
aim to verify the correct behavior of the engines and databases according to
49+
their specifications and requirements.
1050

1151
To run some integration tests, such as tests located in
1252
`tests/integration_tests/vectorstores/`, you will need to install the following
@@ -15,14 +55,6 @@ software:
1555
- Docker
1656
- Python 3.8.1 or later
1757

18-
We have optional group `test_integration` in the `pyproject.toml` file. This group
19-
should contain dependencies for the integration tests and can be installed using the
20-
command:
21-
22-
```bash
23-
poetry install --with test_integration
24-
```
25-
2658
Any new dependencies should be added by running:
2759

2860
```bash
@@ -70,4 +102,20 @@ pytest tests/integration_tests/vectorstores/test_elasticsearch.py --vcr-record=n
70102
pytest tests/integration_tests/vectorstores/test_elasticsearch.py --cov=langchain --cov-report=html
71103
start "" htmlcov/index.html || open htmlcov/index.html
72104

73-
```
105+
```
106+
107+
## Coverage
108+
109+
Code coverage (i.e. the amount of code that is covered by unit tests) helps identify areas of the code that are potentially more or less brittle.
110+
111+
Coverage requires the dependencies for integration tests:
112+
113+
```bash
114+
poetry install --with test_integration
115+
```
116+
117+
To get a report of current coverage, run the following:
118+
119+
```bash
120+
make coverage
121+
```

0 commit comments

Comments
 (0)