Skip to content

Commit 0c8a03d

Browse files
authored
build: Convert to poetry (#242)
1 parent 3f85677 commit 0c8a03d

28 files changed

+238
-3342
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +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-
pip install setuptools
25-
26-
- name: Building publishable packages
27-
shell: bash
28-
run: python setup.py sdist bdist_wheel
29-
3014
- name: Publish package distributions to PyPI
3115
uses: pypa/gh-action-pypi-publish@release/v1
3216
if: ${{ inputs.dry_run == 'false' }}

.github/workflows/ci.yml

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,27 @@ jobs:
3939
with:
4040
python-version: ${{ matrix.python-version }}
4141

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

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

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

6051
- name: Verify typehints
6152
run: make lint
6253

63-
- name: Verify docs can be successfully built
64-
run: make docs
54+
#
55+
# SDK contract tests
56+
#
6557

66-
- name: Build contract tests
67-
run: make build-contract-tests
58+
- name: install contract test dependencies
59+
run: make install-contract-tests-deps
6860

69-
- name: Start contract test service
70-
run: make start-contract-test-service &
61+
- name: start contract test service
62+
run: make start-contract-test-service-bg
7163

7264
- name: run contract tests
7365
run: make run-contract-tests
@@ -123,12 +115,8 @@ jobs:
123115
124116
- name: Install requirements
125117
run: |
126-
pip install setuptools
127-
pip install -r test-requirements.txt
128-
pip install -r test-filesource-optional-requirements.txt
129-
pip install -r consul-requirements.txt
130-
python setup.py install
131-
pip freeze
118+
pipx install poetry
119+
poetry install --all-extras
132120
133121
- name: Run tests
134-
run: pytest -s testing -W error::SyntaxWarning
122+
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.8
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.8
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

.readthedocs.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ version: 2
33
build:
44
os: "ubuntu-22.04"
55
tools:
6-
python: "3.8"
7-
8-
python:
9-
install:
10-
- requirements: docs/requirements.txt
11-
- requirements: requirements.txt
6+
python: "3.10"
7+
jobs:
8+
post_create_environment:
9+
- pip install poetry
10+
- poetry config virtualenvs.create false
11+
post_install:
12+
- poetry install --with docs
1213

1314
sphinx:
1415
builder: html

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: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,72 @@
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 is already used in the CI environment because we're running a DynamoDB container
26-
PORT=10000
27-
28-
build-contract-tests:
29-
@cd contract-tests && pip install -r requirements.txt
30-
11+
PORT=9000
12+
13+
.PHONY: help
14+
help: #! Show this help message
15+
@echo 'Usage: make [target] ... '
16+
@echo ''
17+
@echo 'Targets:'
18+
@grep -h -F '#!' $(MAKEFILE_LIST) | grep -v grep | sed 's/:.*#!/:/' | column -t -s":"
19+
20+
.PHONY: install
21+
install:
22+
@poetry install --all-extras
23+
24+
#
25+
# Quality control checks
26+
#
27+
28+
.PHONY: test
29+
test: #! Run unit tests
30+
test: install
31+
@poetry run pytest $(PYTEST_FLAGS)
32+
33+
.PHONY: lint
34+
lint: #! Run type analysis and linting checks
35+
lint: install
36+
@poetry run mypy ldclient testing
37+
38+
#
39+
# Documentation generation
40+
#
41+
42+
.PHONY: docs
43+
docs: #! Generate sphinx-based documentation
44+
@poetry install --with docs
45+
@cd docs
46+
@poetry run $(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
47+
48+
#
49+
# Contract test service commands
50+
#
51+
52+
.PHONY: install-contract-tests-deps
53+
install-contract-tests-deps:
54+
poetry install --with contract-tests
55+
56+
.PHONY: start-contract-test-service
3157
start-contract-test-service:
32-
@cd contract-tests && python service.py $(PORT)
58+
@cd contract-tests && poetry run python service.py $(PORT)
3359

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

65+
.PHONY: run-contract-tests
3866
run-contract-tests:
39-
curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v2/downloader/run.sh \
40-
| VERSION=v2 PARAMS="-url http://localhost:$(PORT) -debug -stop-service-at-end $(TEST_HARNESS_PARAMS)" sh
41-
42-
contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests
67+
@curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v2/downloader/run.sh \
68+
| VERSION=v2 PARAMS="-url http://localhost:$(PORT) -debug -stop-service-at-end" sh
4369

44-
.PHONY: build-contract-tests start-contract-test-service run-contract-tests contract-tests
70+
.PHONY: contract-tests
71+
contract-tests: #! Run the contract test harness
72+
contract-tests: install-contract-tests-deps start-contract-test-service-bg run-contract-tests

consul-requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

contract-tests/requirements.txt

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

docs/Makefile

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

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
# ones.
4747
extensions = [
4848
'sphinx.ext.autodoc',
49-
'sphinx_autodoc_typehints',
5049
'sphinx.ext.coverage',
5150
'sphinx.ext.viewcode',
5251
]

docs/requirements.txt

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

dynamodb-requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

mypy.ini

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

0 commit comments

Comments
 (0)