From 56d5a2c21b1ff33647f7139bdad1e3aef4c3c3bb Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Tue, 5 Mar 2019 20:06:50 +0100 Subject: [PATCH] doc: Contributing.md (#277) * doc: Contributing.md * fix: Revert change to scope.py * fix: Rename AWS credential envvars to avoid collisions --- CONTRIBUTING.md | 35 +++++++++++++++ Makefile | 55 +++++++++++++---------- scripts/aws-cleanup.sh | 7 ++- scripts/runtox.sh | 10 +++-- tests/integrations/aws_lambda/test_aws.py | 8 ++-- tox.ini | 6 +-- 6 files changed, 86 insertions(+), 35 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..e5496de9b1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,35 @@ +# How to contribute to the Sentry Python SDK + +`sentry-sdk` is an ordinary Python package. You can install it with `pip +install -e .` into some virtualenv, edit the sourcecode and test out your +changes manually. + +## Running tests and linters + +Make sure you have `virtualenv` installed, and the Python versions you care +about. You should have at least one version of Python 2 and Python 3 installed. + +You don't need to `workon` or `activate` anything, the `Makefile` will create +one for you. + +* Running basic tests without integrations: `make test` (Python 2.7 and 3.7) +* Running all tests: `make test-all` + + This really runs all tests, for all integrations, for all version + combinations we care about. This is the closest you can get to the CI build, + provided you have all relevant Python versions installed. + +* Running linting: `make check` or `make lint` +* Running autoformatting: `make format` + +## Releasing a new version + +We use [craft](https://github.com/getsentry/craft#python-package-index-pypi) to +release new versions. You need credentials for the `getsentry` PyPI user, and +must have `twine` installed globally. + +The usual release process goes like this: + +1. Go through git log and write new entry into `CHANGELOG.md`, commit to master +2. `craft p a.b.c` +3. `craft pp a.b.c` diff --git a/Makefile b/Makefile index 8af705c45d..f15cf66a4d 100644 --- a/Makefile +++ b/Makefile @@ -1,52 +1,59 @@ SHELL = /bin/bash -dist: +VENV_PATH = .venv + +.venv: + virtualenv $(VENV_PATH) + $(VENV_PATH)/bin/pip install tox + +dist: .venv rm -rf dist build - python setup.py sdist bdist_wheel + $(VENV_PATH)/bin/python setup.py sdist bdist_wheel .PHONY: dist -.venv: - @virtualenv .venv +format: .venv + $(VENV_PATH)/bin/tox -e linters --notest + .tox/linters/bin/black . +.PHONY: format test: .venv - @pip install -r test-requirements.txt - @pip install --editable . - @pytest tests + @$(VENV_PATH)/bin/tox -e py2.7,py3.7 .PHONY: test -format: - @black sentry_sdk tests -.PHONY: format +test-all: .venv + @TOXPATH=$(VENV_PATH)/bin/tox sh ./scripts/runtox.sh +.PHONY: test-all + +check: lint +.PHONY: check -tox-test: - @sh ./scripts/runtox.sh -.PHONY: tox-test +lint: .venv + @set -e && $(VENV_PATH)/bin/tox -e linters || ( \ + echo "================================"; \ + echo "Bad formatting? Run: make format"; \ + echo "================================"; \ + false) -lint: - @tox -e linters .PHONY: lint -apidocs: - @pip install pdoc==0.3.2 pygments - @pdoc --overwrite --html --html-dir build/apidocs sentry_sdk +apidocs: .venv + @$(VENV_PATH)/bin/pip install --editable . + @$(VENV_PATH)/bin/pip install pdoc==0.3.2 pygments + @$(VENV_PATH)/bin/pdoc --overwrite --html --html-dir build/apidocs sentry_sdk .PHONY: apidocs install-zeus-cli: npm install -g @zeus-ci/cli .PHONY: install-zeus-cli -travis-upload-docs: - @pip install --editable . - $(MAKE) apidocs +travis-upload-docs: apidocs install-zeus-cli cd build/apidocs && zip -r gh-pages ./sentry_sdk - $(MAKE) install-zeus-cli zeus upload -t "application/zip+docs" build/apidocs/gh-pages.zip \ || [[ ! "$(TRAVIS_BRANCH)" =~ ^release/ ]] .PHONY: travis-upload-docs -travis-upload-dist: dist - $(MAKE) install-zeus-cli +travis-upload-dist: dist install-zeus-cli zeus upload -t "application/zip+wheel" dist/* \ || [[ ! "$(TRAVIS_BRANCH)" =~ ^release/ ]] .PHONY: travis-upload-dist diff --git a/scripts/aws-cleanup.sh b/scripts/aws-cleanup.sh index 8a55e0668c..1219668855 100644 --- a/scripts/aws-cleanup.sh +++ b/scripts/aws-cleanup.sh @@ -1,6 +1,11 @@ #!/bin/sh # Delete all AWS Lambda functions -for func in $(aws lambda list-functions | jq .Functions[].FunctionName); do + +export AWS_ACCESS_KEY_ID="$SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID" +export AWS_SECRET_ACCESS_KEY="$SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY" +export AWS_IAM_ROLE="$SENTRY_PYTHON_TEST_AWS_IAM_ROLE" + +for func in $(aws lambda list-functions | jq -r .Functions[].FunctionName); do echo "Deleting $func" aws lambda delete-function --function-name $func done diff --git a/scripts/runtox.sh b/scripts/runtox.sh index 9b8c7618eb..9f7783e97d 100755 --- a/scripts/runtox.sh +++ b/scripts/runtox.sh @@ -1,13 +1,17 @@ #!/bin/bash -set -xe +set -e + +if [ -z "$TOXPATH" ]; then + TOXPATH=tox +fi # Usage: sh scripts/runtox.sh py3.7 # Runs all environments with substring py3.7 and the given arguments for pytest -if [ -z "$1" ]; then +if [ -z "$1" ] && [ -n "$TRAVIS_PYTHON_VERSION" ]; then searchstring="$(echo py$TRAVIS_PYTHON_VERSION | sed -e 's/pypypy/pypy/g' -e 's/-dev//g')" else searchstring="$1" fi -exec tox -p auto -e $(tox -l | grep $searchstring | tr '\n' ',') -- "${@:2}" +exec $TOXPATH -p auto -e $(tox -l | grep "$searchstring" | tr '\n' ',') -- "${@:2}" diff --git a/tests/integrations/aws_lambda/test_aws.py b/tests/integrations/aws_lambda/test_aws.py index 0d6e80c6d9..ca0176d10d 100644 --- a/tests/integrations/aws_lambda/test_aws.py +++ b/tests/integrations/aws_lambda/test_aws.py @@ -47,13 +47,13 @@ def init_sdk(**extra_init_args): @pytest.fixture def lambda_client(): - if "AWS_ACCESS_KEY_ID" not in os.environ: + if "SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID" not in os.environ: pytest.skip("AWS environ vars not set") return boto3.client( "lambda", - aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"], - aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"], + aws_access_key_id=os.environ["SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID"], + aws_secret_access_key=os.environ["SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY"], region_name="us-east-1", ) @@ -84,7 +84,7 @@ def inner(code, payload): lambda_client.create_function( FunctionName=fn_name, Runtime=runtime, - Role=os.environ["AWS_IAM_ROLE"], + Role=os.environ["SENTRY_PYTHON_TEST_AWS_IAM_ROLE"], Handler="test_lambda.test_handler", Code={"ZipFile": tmpdir.join("ball.zip").read(mode="rb")}, Description="Created as part of testsuite for getsentry/sentry-python", diff --git a/tox.ini b/tox.ini index 2661d51b6a..c4646511fc 100644 --- a/tox.ini +++ b/tox.ini @@ -122,9 +122,9 @@ setenv = COVERAGE_FILE=.coverage-{envname} passenv = - AWS_ACCESS_KEY_ID - AWS_SECRET_ACCESS_KEY - AWS_IAM_ROLE + SENTRY_PYTHON_TEST_AWS_ACCESS_KEY_ID + SENTRY_PYTHON_TEST_AWS_SECRET_ACCESS_KEY + SENTRY_PYTHON_TEST_AWS_IAM_ROLE usedevelop = True extras = flask: flask