Skip to content

Commit

Permalink
Merge pull request #7494 from srijan-deepsource/master
Browse files Browse the repository at this point in the history
Fix some code quality issues
  • Loading branch information
stsewd committed Sep 29, 2020
2 parents 839b800 + ec45216 commit e35988f
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion readthedocs/builds/managers.py
Expand Up @@ -83,7 +83,7 @@ def get_object_or_log(self, **kwargs):
try:
return super().get(**kwargs)
except ObjectDoesNotExist:
log.warning('Version not found for given kwargs. %s' % kwargs)
log.warning('Version not found for given kwargs. %s', kwargs)


class InternalVersionManagerBase(VersionManagerBase):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/builds/models.py
Expand Up @@ -347,7 +347,7 @@ def is_editable(self):
@property
def supports_wipe(self):
"""Return True if version is not external."""
return not self.type == EXTERNAL
return self.type != EXTERNAL

@property
def is_sphinx_type(self):
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/config/tests/test_yaml_loader.py
Expand Up @@ -16,5 +16,5 @@ def test_yaml_load_safely():
''')
data = yaml_load_safely(content)
assert data == expected
assert type(data['int']) == int
assert type(data['float']) == float
assert type(data['int']) is int
assert type(data['float']) is float
6 changes: 3 additions & 3 deletions readthedocs/doc_builder/base.py
Expand Up @@ -118,7 +118,6 @@ def create_index(self, extension='md', **__):
return 'README'

if not self.project.has_feature(Feature.DONT_CREATE_INDEX):
index_file = open(index_filename, 'w+')
index_text = """
Welcome to Read the Docs
Expand All @@ -135,8 +134,9 @@ def create_index(self, extension='md', **__):
familiar with Read the Docs.
"""

index_file.write(index_text.format(dir=docs_dir, ext=extension))
index_file.close()
with open(index_filename, 'w+') as index_file:
index_file.write(index_text.format(dir=docs_dir, ext=extension))

return 'index'

def run(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/payments/forms.py
Expand Up @@ -188,7 +188,7 @@ def clean(self):
'exp_month': 'cc_expiry',
'exp_year': 'cc_expiry',
}
error_field = field_lookup.get(e.param, None)
error_field = field_lookup.get(e.param)
self.add_error(
error_field,
forms.ValidationError(str(e)),
Expand Down
7 changes: 4 additions & 3 deletions readthedocs/projects/tasks.py
Expand Up @@ -1433,12 +1433,13 @@ def warn(self, msg):
).first()

if not html_file:
log.debug('[%s] [%s] [Build: %s] HTMLFile object not found. File: %s' % (
log.debug(
'[%s] [%s] [Build: %s] HTMLFile object not found. File: %s',
version.project,
version,
build,
doc_name,
))
doc_name
)

# Don't create Sphinx Domain objects
# if the HTMLFile object is not found.
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/rtd_tests/mocks/mock_api.py
Expand Up @@ -10,7 +10,7 @@

class ProjectData:
def get(self):
return dict()
return {}

def put(self, x=None):
return x
Expand Down
5 changes: 4 additions & 1 deletion readthedocs/rtd_tests/tests/test_build_notifications.py
Expand Up @@ -24,7 +24,10 @@ def setUp(self):
def test_send_notification_none_if_wrong_version_pk(self, mock_logger):
self.assertFalse(Version.objects.filter(pk=345343).exists())
send_notifications(version_pk=345343, build_pk=None)
mock_logger.warning.assert_called_with("Version not found for given kwargs. {'pk': 345343}")
mock_logger.warning.assert_called_with(
'Version not found for given kwargs. %s',
{'pk': 345343},
)


def test_send_notification_none(self):
Expand Down
5 changes: 4 additions & 1 deletion readthedocs/rtd_tests/tests/test_celery.py
Expand Up @@ -334,7 +334,10 @@ def test_fileify_logging_when_wrong_version_pk(self, mock_logger):
search_ranking={},
search_ignore=[],
)
mock_logger.warning.assert_called_with("Version not found for given kwargs. {'pk': 345343}")
mock_logger.warning.assert_called_with(
'Version not found for given kwargs. %s',
{'pk': 345343},
)

@patch('readthedocs.oauth.services.github.GitHubService.send_build_status')
def test_send_build_status_with_remote_repo_github(self, send_build_status):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/rtd_tests/tests/test_privacy_urls.py
Expand Up @@ -96,7 +96,7 @@ def setUp(self):
for key in list(response.context.keys()):
obj = response.context[key]
for not_obj in self.context_data:
if isinstance(obj, list) or isinstance(obj, set) or isinstance(obj, tuple):
if isinstance(obj, (list, set, tuple)):
self.assertNotIn(not_obj, obj)
print('{} not in {}'.format(not_obj, obj))
else:
Expand Down
14 changes: 8 additions & 6 deletions readthedocs/search/documents.py
Expand Up @@ -123,19 +123,21 @@ def prepare_domains(self, html_file):
for domain in domains_qs
]

log.debug("[%s] [%s] Total domains for file %s are: %s" % (
log.debug(
"[%s] [%s] Total domains for file %s are: %s",
html_file.project.slug,
html_file.version.slug,
html_file.path,
len(all_domains),
))
len(all_domains)
)

except Exception:
log.exception("[%s] [%s] Error preparing domain data for file %s" % (
log.exception(
"[%s] [%s] Error preparing domain data for file %s",
html_file.project.slug,
html_file.version.slug,
html_file.path,
))
html_file.path
)

return all_domains

Expand Down
16 changes: 7 additions & 9 deletions readthedocs/search/tasks.py
Expand Up @@ -148,9 +148,11 @@ def record_search_query(project_slug, version_slug, query, total_results, time_s
if not project_slug or not version_slug or not query:
log.debug(
'Not recording the search query. Passed arguments: '
'project_slug: %s, version_slug: %s, query: %s, total_results: %s, time: %s' % (
project_slug, version_slug, query, total_results, time_string
)
'project_slug: %s, version_slug: %s, query: %s, total_results: %s, time: %s',
project_slug,
version_slug,
query, total_results,
time_string
)
return

Expand All @@ -175,9 +177,7 @@ def record_search_query(project_slug, version_slug, query, total_results, time_s
if not project:
log.debug(
'Not recording the search query because project does not exist. '
'project_slug: %s' % (
project_slug
)
'project_slug: %s', project_slug
)
return

Expand All @@ -186,9 +186,7 @@ def record_search_query(project_slug, version_slug, query, total_results, time_s
if not version:
log.debug(
'Not recording the search query because version does not exist. '
'project_slug: %s, version_slug: %s' % (
project_slug, version_slug
)
'project_slug: %s, version_slug: %s', project_slug, version_slug
)
return

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/settings/docker_compose.py
Expand Up @@ -46,7 +46,7 @@ class DockerBaseSettings(CommunityDevSettings):
ADSERVER_API_TIMEOUT = 2 # seconds - Docker for Mac is very slow

# Enable auto syncing elasticsearch documents
ELASTICSEARCH_DSL_AUTOSYNC = True if 'SEARCH' in os.environ else False
ELASTICSEARCH_DSL_AUTOSYNC = 'SEARCH' in os.environ

RTD_CLEAN_AFTER_BUILD = True

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/settings/proxito/base.py
Expand Up @@ -18,7 +18,7 @@ def DATABASES(self):
# This keeps connections to the DB alive,
# which reduces latency with connecting to postgres
dbs = getattr(super(), 'DATABASES', {})
for db in dbs.keys():
for db in dbs:
dbs[db]['CONN_MAX_AGE'] = 86400
return dbs

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/vcs_support/backends/git.py
Expand Up @@ -38,7 +38,7 @@ class Backend(BaseVCS):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.token = kwargs.get('token', None)
self.token = kwargs.get('token')
self.repo_url = self._get_clone_url()

def _get_clone_url(self):
Expand Down

0 comments on commit e35988f

Please sign in to comment.