Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(py3): pre-commit upgrade + sweeping rerun + __future__ removals #23197

Merged
merged 18 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .github/workflows/backend-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
lint:
name: backend lint
runs-on: ubuntu-16.04
timeout-minutes: 3
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
Expand Down
19 changes: 10 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ exclude: >
^src/sentry/data/
)
repos:
- repo: https://github.com/ambv/black
rev: 19.10b0
- repo: local
hooks:
# Configuration for black exists in pyproject.toml,
# but we let pre-commit take care of the file filtering.
- id: black
name: black
entry: black
language: python
types: [python]
exclude: (migrations/)
- repo: local
joshuarli marked this conversation as resolved.
Show resolved Hide resolved
hooks:
# Configuration for flake8 exists in setup.cfg,
# but we let pre-commit take care of the file filtering.
- id: flake8
name: flake8
entry: flake8
language: python
files: \.py$
types: [python]
log_file: '.artifacts/flake8.pycodestyle.log'
additional_dependencies:
- sentry-flake8==0.4.0
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v3.4.0
hooks:
- id: check-case-conflict
- id: check-executables-have-shebangs
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ setup-git: ensure-venv setup-git-config
@echo "--> Installing git hooks"
mkdir -p .git/hooks && cd .git/hooks && ln -sf ../../config/hooks/* ./
@python3 -c '' || (echo 'Please run `make setup-pyenv` to install the required Python 3 version.'; exit 1)
@# pre-commit loosely pins virtualenv, which has caused problems in the past.
$(PIP) install "pre-commit==1.18.2" "virtualenv==20.0.32"
$(PIP) install -r requirements-pre-commit.txt
joshuarli marked this conversation as resolved.
Show resolved Hide resolved
@pre-commit install --install-hooks
@echo ""

Expand Down
1 change: 1 addition & 0 deletions bin/dump-command-help
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python

import os
import six
import click
Expand Down
5 changes: 3 additions & 2 deletions bin/find-good-catalogs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python


import os
import json
import json # noqa: b317
import click

from babel.messages.pofile import read_po
Expand All @@ -11,7 +12,7 @@ MINIMUM = 80


def is_translated(msg):
if isinstance(msg.string, basestring):
if isinstance(msg.string, bytes):
return bool(msg.string)
for item in msg.string:
if not item:
Expand Down
1 change: 0 additions & 1 deletion bin/lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import absolute_import

import os
import sys
Expand Down
9 changes: 5 additions & 4 deletions bin/load-mocks
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import absolute_import

from sentry.runner import configure

Expand Down Expand Up @@ -63,7 +62,6 @@ from sentry.models import (
)
from sentry.signals import mocks_loaded
from sentry.similarity import features
from sentry.snuba.models import QueryAggregations
from sentry.utils import loremipsum
from sentry.utils.hashlib import md5_text
from sentry.utils.samples import create_sample_event as _create_sample_event
Expand Down Expand Up @@ -164,7 +162,7 @@ def generate_tombstones(project, user):
GroupTombstone.objects.create(
previous_group_id=prev_group_id,
actor_id=user.id,
**{name: getattr(group, name) for name in TOMBSTONE_FIELDS_FROM_GROUP}
**{name: getattr(group, name) for name in TOMBSTONE_FIELDS_FROM_GROUP},
)
prev_group_id += 1

Expand Down Expand Up @@ -260,7 +258,10 @@ def create_sample_time_series(event, release=None):
int(count * 1.1),
)
tsdb.incr(
tsdb.models.project_total_forwarded, project.id, now, int(count * 1.1),
tsdb.models.project_total_forwarded,
project.id,
now,
int(count * 1.1),
)
tsdb.incr_multi(
(
Expand Down
1 change: 1 addition & 0 deletions bin/merge-catalogs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python


import os
import click

Expand Down
4 changes: 2 additions & 2 deletions bin/mock-event
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# isort:skip_file

from sentry.runner import configure

configure()
Expand Down Expand Up @@ -28,7 +28,7 @@ def main(project, sample_type):
if not project.first_event:
project.update(first_event=timezone.now())

print("> Created event {}".format(event.event_id))
sys.stdout.write("> Created event {}\n".format(event.event_id))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion bin/mock-user
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# isort:skip_file

from sentry.runner import configure

configure()
Expand Down
11 changes: 6 additions & 5 deletions config/hooks/post-merge
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ trap "rm -f ${files_changed_upstream}" EXIT

git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD > "$files_changed_upstream"

grep -E --quiet 'requirements.*\.txt' "$files_changed_upstream" && py="install-py-dev "
grep -E --quiet 'yarn.lock' "$files_changed_upstream" && js="install-js-dev "
grep -E --quiet 'migrations' "$files_changed_upstream" && migrations="apply-migrations "
grep -E --quiet 'requirements-pre-commit\.txt' "$files_changed_upstream" && pc="setup-git "
joshuarli marked this conversation as resolved.
Show resolved Hide resolved
grep -E --quiet 'requirements-(base|dev)\.txt' "$files_changed_upstream" && py="install-py-dev "
grep -E --quiet 'yarn\.lock' "$files_changed_upstream" && js="install-js-dev "
grep -E --quiet 'migrations' "$files_changed_upstream" && migrations="apply-migrations "

[[ "$py" || "$js" || "$migrations" ]] && needs_update=1
update_command="make ${py}${js}${migrations}"
[[ "$pc" || "$py" || "$js" || "$migrations" ]] && needs_update=1
update_command="make ${pc}${py}${js}${migrations}"

[[ "$needs_update" ]] && cat <<EOF

Expand Down
3 changes: 1 addition & 2 deletions config/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
from __future__ import absolute_import

import os
import sys

from glob import glob

text_type = type(u"")
text_type = type("")

# git usurbs your bin path for hooks and will always run system python
if "VIRTUAL_ENV" in os.environ:
Expand Down
2 changes: 0 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import os
import sys

Expand Down
1 change: 0 additions & 1 deletion docker/sentry.conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# flake8: noqa
from __future__ import absolute_import

# This file is just Python, with a touch of Django which means
# you can inherit and tweak settings to your hearts content.
Expand Down
4 changes: 1 addition & 3 deletions examples/oauth2_consumer_webserver/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from __future__ import absolute_import

import json
import json # noqa
import os
import six

Expand Down
11 changes: 2 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ requires = ["setuptools>=40.2.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
# File filtering is taken care of in pre-commit.
line-length=100
target-version=['py27']
include='\.py$'
exclude='''
(
\.venv/
| node_modules/
| migrations/
)
'''
target-version=['py36']
3 changes: 3 additions & 0 deletions requirements-pre-commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pre-commit==2.9.3
black==20.8b1
sentry-flake8==0.4.0
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ markers =
snuba: mark a test as requiring snuba

[flake8]
# File filtering is taken care of in pre-commit.
# TODO(joshuarli): B102 doesn't apply to Python 3. Could remove it from sentry-flake8 in a future release.
# E203 false positive, see https://github.com/PyCQA/pycodestyle/issues/373
# W605 false positive until python3.8: https://github.com/PyCQA/pycodestyle/issues/755
ignore = F999,E203,E501,E128,E124,E402,W503,W504,W605,E731,C901,B007,B306,B009,B010
exclude = .venv/.git,*/migrations/*,node_modules/*,src/sentry/static/sentry/vendor/*,docs/*,src/south/*,examples/*
ignore = B102,F999,E203,E501,E128,E124,E402,W503,W504,W605,E731,C901,B007,B306,B009,B010

# XXX: E501 is ignored, which disables line length checking.
# Currently, the black formatter doesn't wrap long strings: https://github.com/psf/black/issues/182#issuecomment-385325274
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import absolute_import

import os
import sys
Expand Down Expand Up @@ -81,7 +80,7 @@ def run(self):


def get_requirements(env):
with open(u"requirements-{}.txt".format(env)) as fp:
with open("requirements-{}.txt".format(env)) as fp:
return [x.strip() for x in fp.read().split("\n") if not x.startswith("#")]


Expand Down
2 changes: 0 additions & 2 deletions src/bitfield/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from bitfield.models import Bit, BitHandler, BitField # NOQA

default_app_config = "bitfield.apps.BitFieldAppConfig"
2 changes: 0 additions & 2 deletions src/bitfield/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import six
from django.contrib.admin import FieldListFilter
from django.contrib.admin.options import IncorrectLookupParameters
Expand Down
2 changes: 0 additions & 2 deletions src/bitfield/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from django.apps import AppConfig


Expand Down
2 changes: 0 additions & 2 deletions src/bitfield/compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

__all__ = ("bitand", "bitor")


Expand Down
2 changes: 0 additions & 2 deletions src/bitfield/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import six

from django.db.models.fields import BigIntegerField
Expand Down
2 changes: 0 additions & 2 deletions src/bitfield/query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from bitfield.types import Bit, BitHandler

from django.db.models.lookups import Exact
Expand Down
2 changes: 0 additions & 2 deletions src/bitfield/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import six

from six import string_types
Expand Down
2 changes: 0 additions & 2 deletions src/sentry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import os
import os.path

Expand Down
2 changes: 0 additions & 2 deletions src/sentry/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from .runner import main

main()
4 changes: 1 addition & 3 deletions src/sentry/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from django import forms
from django.conf import settings
from django.conf.urls import url
Expand Down Expand Up @@ -40,7 +38,7 @@ class OptionAdmin(admin.ModelAdmin):
search_fields = ("key",)

def value_repr(self, instance):
return u'<pre style="display:inline-block;white-space:pre-wrap;">{}</pre>'.format(
return '<pre style="display:inline-block;white-space:pre-wrap;">{}</pre>'.format(
escape(saferepr(instance.value))
)

Expand Down
2 changes: 0 additions & 2 deletions src/sentry/adoption/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from .manager import AdoptionManager

manager = AdoptionManager()
Expand Down
2 changes: 0 additions & 2 deletions src/sentry/adoption/manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from collections import defaultdict, namedtuple

FEATURE_LOCATION = {"language", "integration", "code", "web", "admin", "api"}
Expand Down
2 changes: 0 additions & 2 deletions src/sentry/analytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from django.conf import settings

from sentry import options
Expand Down
2 changes: 0 additions & 2 deletions src/sentry/analytics/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

__all__ = ("Analytics",)

import six
Expand Down
9 changes: 4 additions & 5 deletions src/sentry/analytics/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function
from sentry.utils.compat import map

__all__ = ("Attribute", "Event", "Map")
Expand Down Expand Up @@ -56,13 +55,13 @@ def extract(self, value):
for attr in self.attributes:
nv = items.pop(attr.name, None)
if attr.required and nv is None:
raise ValueError(u"{} is required (cannot be None)".format(attr.name))
raise ValueError("{} is required (cannot be None)".format(attr.name))

data[attr.name] = attr.extract(nv)

if items:
raise ValueError(
u"Unknown attributes: {}".format(", ".join(map(six.text_type, six.iterkeys(items))))
"Unknown attributes: {}".format(", ".join(map(six.text_type, six.iterkeys(items))))
)

return data
Expand All @@ -89,11 +88,11 @@ def __init__(self, type=None, datetime=None, **items):
for attr in self.attributes:
nv = items.pop(attr.name, None)
if attr.required and nv is None:
raise ValueError(u"{} is required (cannot be None)".format(attr.name))
raise ValueError("{} is required (cannot be None)".format(attr.name))
data[attr.name] = attr.extract(nv)

if items:
raise ValueError(u"Unknown attributes: {}".format(", ".join(six.iterkeys(items))))
raise ValueError("Unknown attributes: {}".format(", ".join(six.iterkeys(items))))

self.data = data

Expand Down
2 changes: 0 additions & 2 deletions src/sentry/analytics/event_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

__all__ = ("default_manager", "EventManager")


Expand Down
2 changes: 0 additions & 2 deletions src/sentry/analytics/events/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function

from sentry.utils.imports import import_submodules

import_submodules(globals(), __name__, __path__)
2 changes: 0 additions & 2 deletions src/sentry/analytics/events/advanced_search_feature_gated.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from sentry import analytics


Expand Down