From 1f9c93eee2d8ad1bc2e02b2a315134241ca48f00 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Sat, 24 Oct 2015 16:50:58 -0700 Subject: [PATCH 1/5] Some Python2/3 compatibility fixes. --- readthedocs/api/base.py | 2 +- readthedocs/api/utils.py | 2 +- readthedocs/core/utils/__init__.py | 4 ++-- readthedocs/core/views.py | 2 +- readthedocs/oauth/migrations/0003_move_github.py | 4 ++-- readthedocs/projects/tasks.py | 4 ++-- requirements/pip.txt | 7 +++++-- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/readthedocs/api/base.py b/readthedocs/api/base.py index eeb8b5ed487..b9448a1edb8 100644 --- a/readthedocs/api/base.py +++ b/readthedocs/api/base.py @@ -93,7 +93,7 @@ def sync_versions(self, request, **kwargs): self._sync_versions(project, data['tags']) self._sync_versions(project, data['branches']) deleted_versions = self._delete_versions(project, data) - except Exception, e: + except Exception as e: return self.create_response( request, {'exception': e.message}, diff --git a/readthedocs/api/utils.py b/readthedocs/api/utils.py index cc4c2810382..56ec26d94cb 100644 --- a/readthedocs/api/utils.py +++ b/readthedocs/api/utils.py @@ -165,7 +165,7 @@ def obj_get_list(self, request=None, *args, **kwargs): try: return self.get_object_list(request).filter(**applicable_filters) - except ValueError, e: + except ValueError as e: raise NotFound(ugettext("Invalid resource lookup data provided " "(mismatched type).: %(error)s") % {'error': e}) diff --git a/readthedocs/core/utils/__init__.py b/readthedocs/core/utils/__init__.py index 79183160f41..b47e49e74f5 100644 --- a/readthedocs/core/utils/__init__.py +++ b/readthedocs/core/utils/__init__.py @@ -2,7 +2,7 @@ import logging import os -from urlparse import urlparse +from six.moves import urllib_parse from django.conf import settings from django.core.mail import EmailMultiAlternatives @@ -35,7 +35,7 @@ def run_on_app_servers(command): def clean_url(url): - parsed = urlparse(url) + parsed = urllib_parse.urlparse(url) if parsed.scheme: scheme, netloc = parsed.scheme, parsed.netloc elif parsed.netloc: diff --git a/readthedocs/core/views.py b/readthedocs/core/views.py index 11227610271..8b6d911882c 100644 --- a/readthedocs/core/views.py +++ b/readthedocs/core/views.py @@ -184,7 +184,7 @@ def _build_url(url, branches): url, ' '.join(not_building)) pc_log.info(msg) return HttpResponse(msg) - except Exception, e: + except Exception as e: if e.__class__ == NoProjectException: raise msg = "(URL Build) Failed: %s:%s" % (url, e) diff --git a/readthedocs/oauth/migrations/0003_move_github.py b/readthedocs/oauth/migrations/0003_move_github.py index d739a48078a..4f6159e3319 100644 --- a/readthedocs/oauth/migrations/0003_move_github.py +++ b/readthedocs/oauth/migrations/0003_move_github.py @@ -108,7 +108,7 @@ def forwards_move_repos(apps, schema_editor): else: new_repo.clone_url = data.get('clone_url') new_repo.json = json.dumps(data) - except SyntaxError, ValueError: + except SyntaxError as ValueError: pass new_repo.save() log.info('Migrated project: %s', project.name) @@ -149,7 +149,7 @@ def forwards_move_repos(apps, schema_editor): new_repo.clone_url = clone_urls.get('ssh', project.git_url) else: new_repo.clone_url = clone_urls.get('https', project.html_url) - except SyntaxError, ValueError: + except SyntaxError as ValueError: pass new_repo.save() log.info('Migrated project: %s', project.name) diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index d9257682461..e46c9f27665 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -108,7 +108,7 @@ def run(self, pk, version_pk=None, build_pk=None, record=True, docker=False, _('Builds for this project are temporarily disabled')) try: self.setup_vcs() - except vcs_support_utils.LockTimeout, e: + except vcs_support_utils.LockTimeout as e: self.retry(exc=e, throw=False) raise BuildEnvironmentError( 'Version locked, retrying in 5 minutes.', @@ -499,7 +499,7 @@ def update_imported_docs(version_pk): try: api_v2.project(project.pk).sync_versions.post(version_post_data) - except Exception, e: + except Exception as e: print "Sync Versions Exception: %s" % e.message return ret_dict diff --git a/requirements/pip.txt b/requirements/pip.txt index f251f39d2bb..6cad0066273 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -18,9 +18,12 @@ django-vanilla-views==1.0.4 pytest-django==2.8.0 requests==2.3.0 -slumber==0.6.0 +slumber==0.7.1 lxml==3.3.5 +# Python 2/3 compat +six + # Basic tools redis==2.7.1 celery==3.1.18 @@ -45,7 +48,7 @@ beautifulsoup4==4.1.3 Unipath==0.2.1 django-kombu==0.9.4 django-secure==0.1.2 -mimeparse==0.1.3 +mimeparse==0.1.4 mock==1.0.1 stripe==1.20.2 django-copyright==1.0.0 From cbd7040573ed50bfa60c1eb52d1dda300a48e080 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Sat, 24 Oct 2015 20:18:36 -0700 Subject: [PATCH 2/5] use PyPI hosted mimeparse for latest pip --- requirements/pip.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/pip.txt b/requirements/pip.txt index 6cad0066273..7a0167a3742 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -48,7 +48,7 @@ beautifulsoup4==4.1.3 Unipath==0.2.1 django-kombu==0.9.4 django-secure==0.1.2 -mimeparse==0.1.4 +python-mimeparse==0.1.4 mock==1.0.1 stripe==1.20.2 django-copyright==1.0.0 From 542e1040e002142b582e0bba48fd560b423b56ba Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 26 Oct 2015 19:02:15 -0700 Subject: [PATCH 3/5] 'revert change package version to investigate faillurs' --- requirements/pip.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/pip.txt b/requirements/pip.txt index 7a0167a3742..a2b7c3a9b6c 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -18,7 +18,7 @@ django-vanilla-views==1.0.4 pytest-django==2.8.0 requests==2.3.0 -slumber==0.7.1 +slumber==0.6 lxml==3.3.5 # Python 2/3 compat @@ -48,7 +48,7 @@ beautifulsoup4==4.1.3 Unipath==0.2.1 django-kombu==0.9.4 django-secure==0.1.2 -python-mimeparse==0.1.4 +mimeparse==0.1.3 mock==1.0.1 stripe==1.20.2 django-copyright==1.0.0 From 09d3d15b3fc18486f1ac0040e08c27e02bb64bc2 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Fri, 15 Jan 2016 11:44:16 -0800 Subject: [PATCH 4/5] Remove six --- readthedocs/core/utils/__init__.py | 32 ++++++++++++++++++++---------- requirements/pip.txt | 5 +---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/readthedocs/core/utils/__init__.py b/readthedocs/core/utils/__init__.py index b47e49e74f5..c4f17166504 100644 --- a/readthedocs/core/utils/__init__.py +++ b/readthedocs/core/utils/__init__.py @@ -2,7 +2,7 @@ import logging import os -from six.moves import urllib_parse +from urlparse import urlparse from django.conf import settings from django.core.mail import EmailMultiAlternatives @@ -35,7 +35,7 @@ def run_on_app_servers(command): def clean_url(url): - parsed = urllib_parse.urlparse(url) + parsed = urlparse(url) if parsed.scheme: scheme, netloc = parsed.scheme, parsed.netloc elif parsed.netloc: @@ -54,8 +54,10 @@ def cname_to_slug(host): def trigger_build(project, version=None, record=True, force=False, basic=False): - """ - An API to wrap the triggering of a build. + """Trigger build for project and version + + If project has a ``build_queue``, execute task on this build queue. Queue + will be prefixed with ``build-`` to unify build queue names. """ # Avoid circular import from readthedocs.projects.tasks import update_docs @@ -66,6 +68,15 @@ def trigger_build(project, version=None, record=True, force=False, basic=False): if not version: version = project.versions.get(slug=LATEST) + kwargs = dict( + pk=project.pk, + version_pk=version.pk, + record=record, + force=force, + basic=basic, + ) + + build = None if record: build = Build.objects.create( project=project, @@ -74,12 +85,13 @@ def trigger_build(project, version=None, record=True, force=False, basic=False): state='triggered', success=True, ) - update_docs.delay(pk=project.pk, version_pk=version.pk, record=record, - force=force, basic=basic, build_pk=build.pk) - else: - build = None - update_docs.delay(pk=project.pk, version_pk=version.pk, record=record, - force=force, basic=basic) + kwargs['build_pk'] = build.pk + + options = {} + if project.build_queue: + options['queue'] = 'build-{0}'.format(project.build_queue) + + update_docs.apply_async(kwargs=kwargs, **options) return build diff --git a/requirements/pip.txt b/requirements/pip.txt index a2b7c3a9b6c..f251f39d2bb 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -18,12 +18,9 @@ django-vanilla-views==1.0.4 pytest-django==2.8.0 requests==2.3.0 -slumber==0.6 +slumber==0.6.0 lxml==3.3.5 -# Python 2/3 compat -six - # Basic tools redis==2.7.1 celery==3.1.18 From 72feec4d08849791b1ed24abf3ac471925dca70b Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Fri, 15 Jan 2016 17:27:18 -0800 Subject: [PATCH 5/5] Fix migration --- readthedocs/oauth/migrations/0003_move_github.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readthedocs/oauth/migrations/0003_move_github.py b/readthedocs/oauth/migrations/0003_move_github.py index 4f6159e3319..dda92d0371c 100644 --- a/readthedocs/oauth/migrations/0003_move_github.py +++ b/readthedocs/oauth/migrations/0003_move_github.py @@ -108,7 +108,7 @@ def forwards_move_repos(apps, schema_editor): else: new_repo.clone_url = data.get('clone_url') new_repo.json = json.dumps(data) - except SyntaxError as ValueError: + except (SyntaxError, ValueError) as e: pass new_repo.save() log.info('Migrated project: %s', project.name) @@ -149,7 +149,7 @@ def forwards_move_repos(apps, schema_editor): new_repo.clone_url = clone_urls.get('ssh', project.git_url) else: new_repo.clone_url = clone_urls.get('https', project.html_url) - except SyntaxError as ValueError: + except (SyntaxError, ValueError) as e: pass new_repo.save() log.info('Migrated project: %s', project.name)