Skip to content

Commit

Permalink
doc: Contributing.md (#277)
Browse files Browse the repository at this point in the history
* doc: Contributing.md

* fix: Revert change to scope.py

* fix: Rename AWS credential envvars to avoid collisions
  • Loading branch information
untitaker authored Mar 5, 2019
1 parent d25fba8 commit 56d5a2c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 35 deletions.
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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`
55 changes: 31 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion scripts/aws-cleanup.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions scripts/runtox.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/bash
set -xe
set -e

if [ -z "$TOXPATH" ]; then
TOXPATH=tox
fi

# Usage: sh scripts/runtox.sh py3.7 <pytest-args>
# 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}"
8 changes: 4 additions & 4 deletions tests/integrations/aws_lambda/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 56d5a2c

Please sign in to comment.