Skip to content

Commit bcb8555

Browse files
committed
build: Convert to poetry
1 parent 59b8827 commit bcb8555

28 files changed

+265
-275
lines changed

.github/actions/build-docs/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Build Documentation
2+
description: 'Build Documentation.'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Build Documentation
8+
shell: bash
9+
run: make docs

.github/actions/build/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Build distribution files
2+
description: 'Build distribution files'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Build distribution files
8+
shell: bash
9+
run: poetry build

.github/actions/publish/action.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ inputs:
1111
runs:
1212
using: composite
1313
steps:
14-
- name: Set up Python 3.11
15-
uses: actions/setup-python@v4
16-
with:
17-
python-version: 3.11
18-
19-
- name: Install dependencies
20-
shell: bash
21-
run: |
22-
pip install -r requirements.txt
23-
pip install wheel
24-
25-
- name: Building publishable packages
26-
shell: bash
27-
run: python setup.py sdist bdist_wheel
28-
2914
- name: Publish package distributions to PyPI
3015
uses: pypa/gh-action-pypi-publish@release/v1
3116
if: ${{ inputs.dry_run == 'false' }}

.github/workflows/ci.yml

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,54 +39,45 @@ jobs:
3939
with:
4040
python-version: ${{ matrix.python-version }}
4141

42-
- name: Install requirements
43-
run: |
44-
pipx install virtualenv
45-
pip install -r test-requirements.txt
46-
pip install -r test-filesource-optional-requirements.txt
47-
pip install -r consul-requirements.txt
48-
python setup.py install
49-
pip freeze
42+
- name: Install poetry
43+
run: pipx install poetry
5044

51-
- name: Run tests
52-
run: pytest -s testing -W error::SyntaxWarning
45+
- uses: ./.github/actions/build
46+
- uses: ./.github/actions/build-docs
5347

54-
- name: Test packaging
55-
run: |
56-
sudo rm -rf dist *.egg-info
57-
./test-packaging/test-packaging.sh
48+
- name: Run tests
49+
run: make test
5850

5951
- name: Verify typehints
6052
run: make lint
6153

62-
- name: Verify docs can be successfully built
63-
run: make docs
54+
#
55+
# SSE contract tests
56+
#
6457

65-
- name: build SSE contract test service
58+
- name: install sse contract test dependencies
6659
if: ${{ matrix.python-version != 3.7 }}
67-
run: |
68-
cd sse-contract-tests
69-
make build-test-service
60+
run: make install-sse-contract-tests-deps
7061

71-
- name: start SSE contract test service
62+
- name: start sse contract test service
7263
if: ${{ matrix.python-version != 3.7 }}
73-
run: |
74-
cd sse-contract-tests
75-
make start-test-service &
64+
run: make start-sse-contract-test-service-bg
7665

77-
- name: run SSE contract tests
66+
- name: run sse contract tests
7867
if: ${{ matrix.python-version != 3.7 }}
79-
run: |
80-
cd sse-contract-tests
81-
make run-contract-tests
68+
run: make run-sse-contract-tests
69+
70+
#
71+
# SDK contract tests
72+
#
8273

83-
- name: Build contract tests
74+
- name: install contract test dependencies
8475
if: ${{ matrix.python-version != 3.7 }}
85-
run: make build-contract-tests
76+
run: make install-contract-tests-deps
8677

87-
- name: Start contract test service
78+
- name: start contract test service
8879
if: ${{ matrix.python-version != 3.7 }}
89-
run: make start-contract-test-service &
80+
run: make start-contract-test-service-bg
9081

9182
- name: run contract tests
9283
if: ${{ matrix.python-version != 3.7 }}
@@ -143,11 +134,8 @@ jobs:
143134
144135
- name: Install requirements
145136
run: |
146-
pip install -r test-requirements.txt
147-
pip install -r test-filesource-optional-requirements.txt
148-
pip install -r consul-requirements.txt
149-
python setup.py install
150-
pip freeze
137+
pipx install poetry
138+
poetry install --all-extras
151139
152140
- name: Run tests
153-
run: pytest -s testing -W error::SyntaxWarning
141+
run: make test

.github/workflows/manual-publish.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919

20+
- uses: actions/setup-python@v4
21+
with:
22+
python-version: 3.7
23+
24+
- name: Install poetry
25+
run: pipx install poetry
26+
2027
- uses: launchdarkly/gh-actions/actions/[email protected]
2128
name: 'Get PyPI token'
2229
with:
2330
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
2431
ssm_parameter_pairs: '/production/common/releasing/pypi/token = PYPI_AUTH_TOKEN'
2532

26-
- id: publish
27-
name: Publish Package
28-
uses: ./.github/actions/publish
33+
- uses: ./.github/actions/build
34+
35+
- uses: ./.github/actions/publish
2936
with:
3037
token: ${{env.PYPI_AUTH_TOKEN}}
3138
dry_run: ${{ inputs.dry_run }}

.github/workflows/release-please.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,29 @@ jobs:
2424
with:
2525
fetch-depth: 0 # If you only need the current version keep this.
2626

27+
- uses: actions/setup-python@v4
28+
if: ${{ steps.release.outputs.releases_created }}
29+
with:
30+
python-version: 3.7
31+
32+
- name: Install poetry
33+
if: ${{ steps.release.outputs.releases_created }}
34+
run: pipx install poetry
35+
2736
- uses: launchdarkly/gh-actions/actions/[email protected]
2837
if: ${{ steps.release.outputs.releases_created }}
2938
name: 'Get PyPI token'
3039
with:
3140
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
3241
ssm_parameter_pairs: '/production/common/releasing/pypi/token = PYPI_AUTH_TOKEN'
3342

34-
- id: publish
35-
name: Publish Package
36-
uses: ./.github/actions/publish
43+
- uses: ./.github/actions/build
44+
if: ${{ steps.release.outputs.releases_created }}
45+
46+
- uses: ./.github/actions/build-docs
47+
if: ${{ steps.release.outputs.releases_created }}
48+
49+
- uses: ./.github/actions/publish
3750
if: ${{ steps.release.outputs.releases_created }}
3851
with:
3952
token: ${{env.PYPI_AUTH_TOKEN}}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ __pycache__/
1010
.Python
1111
env/
1212
build/
13+
!.github/actions/build/
1314
develop-eggs/
1415
dist/
1516
downloads/
@@ -70,3 +71,6 @@ test-packaging-venv
7071

7172
.vscode/
7273
.python-version
74+
75+
# Poetry
76+
poetry.lock

CONTRIBUTING.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ We encourage pull requests and other contributions from the community. Before su
1414

1515
### Setup
1616

17-
It's advisable to use [`virtualenv`](https://virtualenv.pypa.io/) to create a development environment within the project directory:
17+
This project is built using [poetry](https://python-poetry.org/). To learn more about the basics of working with this tool, read [Poetry's basic usage guide](https://python-poetry.org/docs/basic-usage/).
18+
19+
To begin development, active the poetry shell and ensure your dependencies are installed.
1820

1921
```
20-
mkvirtualenv python-server-sdk
21-
source ~/.virtualenvs/python-server-sdk/bin/activate
22+
poetry shell
23+
poetry install
2224
```
2325

24-
To install the runtime and test requirements:
26+
This library defines several extra dependencies to optionally enhance the SDK's capabilities. Use the following commands to install one or more of the available extras.
2527

2628
```
27-
pip install -r requirements.txt
28-
pip install -r test-requirements.txt
29+
poetry install --extras "redis consul dynamodb test-filesource"
30+
poetry install -E redis -E consul -E dynamodb -E test-filesource
31+
poetry install --all-extras
2932
```
3033

31-
The additional requirements files `consul-requirements.txt`, `dynamodb-requirements.txt`, `redis-requirements.txt`, and `test-filesource-optional-requirements.txt` can also be installed if you need to test the corresponding features.
32-
3334
### Testing
3435

3536
To run all unit tests except for the database integrations:

MANIFEST.in

Lines changed: 0 additions & 7 deletions
This file was deleted.

Makefile

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,99 @@
1-
21
PYTEST_FLAGS=-W error::SyntaxWarning
32

4-
test:
5-
LD_SKIP_DATABASE_TESTS=1 pytest $(PYTEST_FLAGS)
6-
7-
test-all:
8-
pytest $(PYTEST_FLAGS)
9-
10-
lint:
11-
mypy --install-types --non-interactive --config-file mypy.ini ldclient testing
12-
13-
docs:
14-
cd docs && make html
15-
16-
.PHONY: test test-all lint docs
17-
18-
193
TEMP_TEST_OUTPUT=/tmp/contract-test-service.log
204

21-
# TEST_HARNESS_PARAMS can be set to add -skip parameters for any contract tests that cannot yet pass
22-
# TEST_HARNESS_PARAMS := $(TEST_HARNESS_PARAMS) \
23-
24-
5+
SPHINXOPTS = -W --keep-going
6+
SPHINXBUILD = sphinx-build
7+
SPHINXPROJ = launchdarkly-server-sdk
8+
SOURCEDIR = docs
9+
BUILDDIR = $(SOURCEDIR)/build
2510
# port 8000 and 9000 is already used in the CI environment because we're
2611
# running a DynamoDB container and an SSE contract test
2712
PORT=10000
2813

29-
build-contract-tests:
30-
@cd contract-tests && pip install -r requirements.txt
31-
14+
.PHONY: help
15+
help: #! Show this help message
16+
@echo 'Usage: make [target] ... '
17+
@echo ''
18+
@echo 'Targets:'
19+
@grep -h -F '#!' $(MAKEFILE_LIST) | grep -v grep | sed 's/:.*#!/:/' | column -t -s":"
20+
21+
.PHONY: install
22+
install:
23+
@poetry install --all-extras
24+
25+
#
26+
# Quality control checks
27+
#
28+
29+
.PHONY: test
30+
test: #! Run unit tests
31+
test: install
32+
@poetry run pytest $(PYTEST_FLAGS)
33+
34+
.PHONY: lint
35+
lint: #! Run type analysis and linting checks
36+
lint: install
37+
@poetry run mypy ldclient testing
38+
39+
#
40+
# Documentation generation
41+
#
42+
43+
.PHONY: docs
44+
docs: #! Generate sphinx-based documentation
45+
@poetry install --with docs
46+
@cd docs
47+
@poetry run $(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
48+
49+
#
50+
# Contract test service commands
51+
#
52+
53+
.PHONY: install-contract-tests-deps
54+
install-contract-tests-deps:
55+
poetry install --with contract-tests
56+
57+
.PHONY: start-contract-test-service
3258
start-contract-test-service:
33-
@cd contract-tests && python service.py $(PORT)
59+
@cd contract-tests && poetry run python service.py $(PORT)
3460

61+
.PHONY: start-contract-test-service-bg
3562
start-contract-test-service-bg:
3663
@echo "Test service output will be captured in $(TEMP_TEST_OUTPUT)"
3764
@make start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 &
3865

66+
.PHONY: run-contract-tests
3967
run-contract-tests:
40-
curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v2/downloader/run.sh \
41-
| VERSION=v2 PARAMS="-url http://localhost:$(PORT) -debug -stop-service-at-end $(TEST_HARNESS_PARAMS)" sh
68+
@curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v2/downloader/run.sh \
69+
| VERSION=v2 PARAMS="-url http://localhost:$(PORT) -debug -stop-service-at-end" sh
70+
71+
.PHONY: contract-tests
72+
contract-tests: #! Run the contract test harness
73+
contract-tests: install-contract-tests-deps start-contract-test-service-bg run-contract-tests
74+
75+
#
76+
# SSE contract test service commands
77+
#
78+
79+
.PHONY: install-sse-contract-tests-deps
80+
install-sse-contract-tests-deps:
81+
poetry install --with contract-tests
82+
83+
.PHONY: start-sse-contract-test-service
84+
start-sse-contract-test-service:
85+
@cd sse-contract-tests && poetry run python service.py $(PORT)
86+
87+
.PHONY: start-sse-contract-test-service-bg
88+
start-sse-contract-test-service-bg:
89+
@echo "Test service output will be captured in $(TEMP_TEST_OUTPUT)"
90+
@make start-sse-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 &
4291

43-
contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests
92+
.PHONY: run-sse-contract-tests
93+
run-sse-contract-tests:
94+
@curl -s https://raw.githubusercontent.com/launchdarkly/sse-contract-tests/v2.0.0/downloader/run.sh \
95+
| VERSION=v1 PARAMS="-url http://localhost:$(PORT) -debug -stop-service-at-end -skip reconnection" sh
4496

45-
.PHONY: build-contract-tests start-contract-test-service run-contract-tests contract-tests
97+
.PHONY: sse-contract-tests
98+
sse-contract-tests: #! Run the sse contract test harness
99+
sse-contract-tests: install-sse-contract-tests-deps start-sse-contract-test-service-bg run-sse-contract-tests

0 commit comments

Comments
 (0)