-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ def get_opts(param): | |
| if any_slashes: | ||
| any_prefix_is_slash[:] = [True] | ||
| if not param.is_flag and not param.count: | ||
| rv += " " + param.make_metavar() | ||
| rv += f" {param.make_metavar()}" | ||
| return rv | ||
|
|
||
| rv = [_write(param.opts)] | ||
|
|
@@ -27,7 +27,7 @@ def get_opts(param): | |
|
|
||
| def write_page(out, data): | ||
| path = data["path"] | ||
| filename = os.path.join(out, *path[1:]) + "/index.rst" | ||
| filename = f"{os.path.join(out, *path[1:])}/index.rst" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if len(path) == 1: | ||
| filename += ".inc" | ||
|
|
||
|
|
@@ -38,29 +38,44 @@ def write_page(out, data): | |
| pass | ||
|
|
||
| args = [x["metavar"] for x in data["arguments"]] | ||
| title = "`%s`" % " ".join(data["path"] + args) | ||
| body = [title, "-" * len(title), "", data["help"] or ""] | ||
| title = f'`{" ".join(data["path"] + args)}`' | ||
| body = [ | ||
| title, | ||
| "-" * len(title), | ||
| "", | ||
| data["help"] or "", | ||
| "", | ||
| "Options", | ||
| "```````", | ||
| "", | ||
| ] | ||
|
|
||
|
|
||
| body.append("") | ||
| body.append("Options") | ||
| body.append("```````") | ||
| body.append("") | ||
| for opt in data["options"]: | ||
| prefix = "- ``%s``: " % opt["opt_string"] | ||
| for line in click.wrap_text(opt["help"], 74, prefix, " ").splitlines() or [""]: | ||
| body.append(line) | ||
| prefix = f'- ``{opt["opt_string"]}``: ' | ||
| body.extend( | ||
| iter( | ||
| click.wrap_text(opt["help"], 74, prefix, " ").splitlines() | ||
| or [""] | ||
| ) | ||
| ) | ||
|
|
||
| body.append("- ``--help``: print this help page.") | ||
|
|
||
| if data["subcommands"]: | ||
| body.append("") | ||
| body.append("Subcommands") | ||
| body.append("```````````") | ||
| body.append("") | ||
| body.append(".. toctree::") | ||
| body.append(" :maxdepth: 1") | ||
| body.append("") | ||
| for subcmd in data["subcommands"]: | ||
| body.append(f" {subcmd} <{subcmd}/index>") | ||
| body.extend( | ||
| ( | ||
| "", | ||
| "Subcommands", | ||
| "```````````", | ||
| "", | ||
| ".. toctree::", | ||
| " :maxdepth: 1", | ||
| "", | ||
| ) | ||
| ) | ||
|
|
||
| body.extend(f" {subcmd} <{subcmd}/index>" for subcmd in data["subcommands"]) | ||
| body.append("") | ||
|
|
||
| with open(filename, "w") as f: | ||
|
|
@@ -88,10 +103,11 @@ def dump_command(out, cmd, path): | |
| help_text = param.help or "" | ||
| if param.show_default: | ||
| help_text += " [default: %s]" % ( | ||
| ", ".join("%s" % d for d in param.default) | ||
| ", ".join(f"{d}" for d in param.default) | ||
| if isinstance(param.default, (list, tuple)) | ||
| else (param.default,) | ||
| ) | ||
|
|
||
|
Comment on lines
-91
to
+110
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| data["options"].append({"opt_string": get_opts(param), "help": help_text}) | ||
| else: | ||
| data["arguments"].append({"metavar": param.make_metavar()}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,12 +11,7 @@ MINIMUM = 80 | |
|
|
||
|
|
||
| def is_translated(msg): | ||
| if isinstance(msg.string, bytes): | ||
| return bool(msg.string) | ||
| for item in msg.string: | ||
| if not item: | ||
| return False | ||
| return True | ||
| return bool(msg.string) if isinstance(msg.string, bytes) else all(msg.string) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| @click.command() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,7 +120,7 @@ def generate_commits(user): | |
| if i == 1: | ||
| filename = "raven/base.py" | ||
| else: | ||
| filename = random.choice(loremipsum.words) + ".js" | ||
| filename = f"{random.choice(loremipsum.words)}.js" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if random.randint(0, 5) == 1: | ||
| author = (user.name, user.email) | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ def merge_message(msg, frontend_msg): | |
| @click.command() | ||
| @click.argument("locale") | ||
| def cli(locale): | ||
| catalog_file = "src/sentry/locale/%s/LC_MESSAGES/django.po" % locale | ||
| catalog_file = f"src/sentry/locale/{locale}/LC_MESSAGES/django.po" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| frontend_file = "build/javascript.po" | ||
| if not os.path.isfile(frontend_file): | ||
| return | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ def main(slow=False): | |
| org = Organization.get_default() | ||
| print(f"Mocking org {org.name}") # NOQA | ||
| else: | ||
| print("Mocking org {}".format("Default")) # NOQA | ||
| print('Mocking org Default') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| org, _ = Organization.objects.get_or_create(slug="default") | ||
|
|
||
| for project_name in project_names: | ||
|
|
@@ -54,7 +54,7 @@ def main(slow=False): | |
|
|
||
| timestamp = timezone.now() | ||
|
|
||
| print(f" > Loading normal trace") # NOQA | ||
| print(" > Loading normal trace") | ||
| # Normal trace | ||
| create_trace( | ||
| slow, | ||
|
|
@@ -94,7 +94,7 @@ def main(slow=False): | |
| }, | ||
| ) | ||
|
|
||
| print(f" > Loading orphan data") # NOQA | ||
| print(" > Loading orphan data") | ||
| # Trace only with orphans | ||
| create_trace( | ||
| slow, | ||
|
|
@@ -136,7 +136,7 @@ def main(slow=False): | |
| }, | ||
| ) | ||
|
|
||
| print(f" > Loading trace with many siblings") # NOQA | ||
| print(" > Loading trace with many siblings") | ||
| create_trace( | ||
| slow, | ||
| timestamp - timedelta(milliseconds=random_normal(4000, 250, 1000)), | ||
|
|
@@ -158,7 +158,7 @@ def main(slow=False): | |
| ], | ||
| }, | ||
| ) | ||
| print(f" > Loading trace with many roots") # NOQA | ||
| print(" > Loading trace with many roots") | ||
| trace_id = uuid4().hex | ||
| for _ in range(15): | ||
| create_trace( | ||
|
|
@@ -182,7 +182,7 @@ def main(slow=False): | |
| }, | ||
| ) | ||
|
|
||
| print(f" > Loading chained trace with orphans") # NOQA | ||
| print(" > Loading chained trace with orphans") | ||
| trace_id = uuid4().hex | ||
| create_trace( | ||
| slow, | ||
|
|
@@ -247,7 +247,7 @@ def main(slow=False): | |
| }, | ||
| ) | ||
|
|
||
| print(f" > Loading traces missing instrumentation") # NOQA | ||
| print(" > Loading traces missing instrumentation") | ||
| create_trace( | ||
| slow, | ||
| timestamp - timedelta(milliseconds=random_normal(4000, 250, 1000)), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ text_type = str | |
| if "VIRTUAL_ENV" in os.environ: | ||
| # If pre-commit is not installed outside of the virtualenv, glob will return [] | ||
| try: | ||
| site_packages = glob("%s/lib/*/site-packages" % os.environ["VIRTUAL_ENV"])[0] | ||
| site_packages = glob(f'{os.environ["VIRTUAL_ENV"]}/lib/*/site-packages')[0] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| sys.path.insert(0, site_packages) | ||
| except IndexError: | ||
| pass | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,9 @@ | |
| CONF_ROOT = os.path.dirname(__file__) | ||
| env = os.environ.get | ||
|
|
||
| postgres = env("SENTRY_POSTGRES_HOST") or (env("POSTGRES_PORT_5432_TCP_ADDR") and "postgres") | ||
| if postgres: | ||
| if postgres := env("SENTRY_POSTGRES_HOST") or ( | ||
| env("POSTGRES_PORT_5432_TCP_ADDR") and "postgres" | ||
| ): | ||
|
Comment on lines
-44
to
+46
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||
| DATABASES = { | ||
| "default": { | ||
| "ENGINE": "sentry.db.postgres", | ||
|
|
@@ -103,38 +104,25 @@ | |
| } | ||
| ) | ||
|
|
||
| ######### | ||
| # Cache # | ||
| ######### | ||
|
|
||
| # Sentry currently utilizes two separate mechanisms. While CACHES is not a | ||
| # requirement, it will optimize several high throughput patterns. | ||
|
|
||
| memcached = env("SENTRY_MEMCACHED_HOST") or (env("MEMCACHED_PORT_11211_TCP_ADDR") and "memcached") | ||
| if memcached: | ||
| if memcached := env("SENTRY_MEMCACHED_HOST") or ( | ||
| env("MEMCACHED_PORT_11211_TCP_ADDR") and "memcached" | ||
| ): | ||
| memcached_port = env("SENTRY_MEMCACHED_PORT") or "11211" | ||
| CACHES = { | ||
| "default": { | ||
| "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", | ||
| "LOCATION": [memcached + ":" + memcached_port], | ||
| "LOCATION": [f"{memcached}:{memcached_port}"], | ||
| "TIMEOUT": 3600, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| # A primary cache is required for things such as processing events | ||
| SENTRY_CACHE = "sentry.cache.redis.RedisCache" | ||
|
|
||
| ######### | ||
| # Queue # | ||
| ######### | ||
|
|
||
| # See https://develop.sentry.dev/services/queue/ for more information on | ||
| # configuring your queue broker and workers. Sentry relies on a Python | ||
| # framework called Celery to manage queues. | ||
|
|
||
| rabbitmq = env("SENTRY_RABBITMQ_HOST") or (env("RABBITMQ_PORT_5672_TCP_ADDR") and "rabbitmq") | ||
|
|
||
| if rabbitmq: | ||
| if rabbitmq := env("SENTRY_RABBITMQ_HOST") or ( | ||
| env("RABBITMQ_PORT_5672_TCP_ADDR") and "rabbitmq" | ||
| ): | ||
| BROKER_URL = ( | ||
| "amqp://" | ||
| + (env("SENTRY_RABBITMQ_USERNAME") or env("RABBITMQ_ENV_RABBITMQ_DEFAULT_USER") or "guest") | ||
|
|
@@ -146,7 +134,7 @@ | |
| + (env("SENTRY_RABBITMQ_VHOST") or env("RABBITMQ_ENV_RABBITMQ_DEFAULT_VHOST") or "/") | ||
| ) | ||
| else: | ||
| BROKER_URL = "redis://:" + redis_password + "@" + redis + ":" + redis_port + "/" + redis_db | ||
| BROKER_URL = f"redis://:{redis_password}@{redis}:{redis_port}/{redis_db}" | ||
|
|
||
|
|
||
| ############### | ||
|
|
@@ -211,13 +199,9 @@ | |
| # 'workers': 1, # the number of web workers | ||
| } | ||
|
|
||
| ############### | ||
| # Mail Server # | ||
| ############### | ||
|
|
||
|
|
||
| email = env("SENTRY_EMAIL_HOST") or (env("SMTP_PORT_25_TCP_ADDR") and "smtp") | ||
| if email: | ||
| if email := env("SENTRY_EMAIL_HOST") or ( | ||
| env("SMTP_PORT_25_TCP_ADDR") and "smtp" | ||
| ): | ||
| SENTRY_OPTIONS["mail.backend"] = "smtp" | ||
| SENTRY_OPTIONS["mail.host"] = email | ||
| SENTRY_OPTIONS["mail.password"] = env("SENTRY_EMAIL_PASSWORD") or "" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,9 +39,8 @@ | |
| def index(): | ||
| access_token = session.get("access_token") | ||
| if access_token is None: | ||
| return ("<h1>Who are you?</h1>" '<p><a href="{}">Login with Sentry</a></p>').format( | ||
| url_for("login") | ||
| ) | ||
| return f'<h1>Who are you?</h1><p><a href="{url_for("login")}">Login with Sentry</a></p>' | ||
|
|
||
|
Comment on lines
-42
to
+43
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| from urllib.error import HTTPError, URLError | ||
| from urllib.request import Request, urlopen | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,6 @@ def create_event(self, name, **kwargs): | |
| "user": {"id": self.user.id, "email": self.user.email}, | ||
| "release": name, | ||
| } | ||
| data.update(kwargs) | ||
| data |= kwargs | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| return self.store_event(data=data, project_id=self.project.id) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,8 +48,7 @@ def get_create_meta_for_project(self, project): | |
| """ | ||
| self._throw_if_broken() | ||
|
|
||
| createmeta = self._get_data(project, "createmeta") | ||
| if createmeta: | ||
| if createmeta := self._get_data(project, "createmeta"): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return createmeta | ||
|
|
||
| # Fallback to stub data | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,7 @@ def get_stub_data(service_name, name): | |
| :return: object | ||
| """ | ||
| cache_key = f"{service_name}.{name}" | ||
| cached = StubService.stub_data_cache.get(cache_key) | ||
| if cached: | ||
| if cached := StubService.stub_data_cache.get(cache_key): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| data = cached | ||
| else: | ||
| data = json.loads(StubService.get_stub_json(service_name, name)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,8 +53,7 @@ def _stub_vsts(self): | |
|
|
||
| responses.add( | ||
| responses.GET, | ||
| "https://app.vssps.visualstudio.com/_apis/accounts?memberId=%s&api-version=4.1" | ||
| % self.vsts_user_id, | ||
| f"https://app.vssps.visualstudio.com/_apis/accounts?memberId={self.vsts_user_id}&api-version=4.1", | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| json={ | ||
| "count": 1, | ||
| "value": [ | ||
|
|
@@ -68,12 +67,13 @@ def _stub_vsts(self): | |
| }, | ||
| ) | ||
|
|
||
|
|
||
| responses.add( | ||
| responses.GET, | ||
| "https://app.vssps.visualstudio.com/_apis/resourceareas/79134C72-4A58-4B42-976C-04E7115F32BF?hostId=%s&api-preview=5.0-preview.1" | ||
| % self.vsts_account_id, | ||
| f"https://app.vssps.visualstudio.com/_apis/resourceareas/79134C72-4A58-4B42-976C-04E7115F32BF?hostId={self.vsts_account_id}&api-preview=5.0-preview.1", | ||
| json={"locationUrl": self.vsts_base_url}, | ||
| ) | ||
|
|
||
| responses.add( | ||
| responses.GET, | ||
| "https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=1.0", | ||
|
|
@@ -130,9 +130,7 @@ def _stub_vsts(self): | |
|
|
||
| responses.add( | ||
| responses.GET, | ||
| "https://{}.visualstudio.com/{}/_apis/wit/workitemtypes/{}/states".format( | ||
| self.vsts_account_name.lower(), self.project_a["name"], "Bug" | ||
| ), | ||
| f'https://{self.vsts_account_name.lower()}.visualstudio.com/{self.project_a["name"]}/_apis/wit/workitemtypes/Bug/states', | ||
| json={ | ||
| "value": [ | ||
| {"name": "resolve_status"}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,8 +68,7 @@ def appconnect_config(): | |
| for config in symbol_sources: | ||
| if config["type"] == "appStoreConnect": | ||
| return config | ||
| else: | ||
| raise KeyError("appStoreConnect config not found") | ||
| raise KeyError("appStoreConnect config not found") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,8 +113,7 @@ def __init__(self, flags, default=None, *args, **kwargs): | |
| self.labels = labels | ||
|
|
||
| def pre_save(self, instance, add): | ||
| value = getattr(instance, self.attname) | ||
| return value | ||
| return getattr(instance, self.attname) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def get_prep_value(self, value): | ||
| if value is None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
get_opts._writerefactored with the following changes:use-fstring-for-concatenation)