You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/11/26 21:29:50 UTC

[GitHub] nickva closed pull request #1639: Switch to python 3

nickva closed pull request #1639: Switch to python 3
URL: https://github.com/apache/couchdb/pull/1639
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.travis.yml b/.travis.yml
index 01b2862a32..1349e986ee 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,7 +26,7 @@ addons:
     - shunit2
 
 python:
-  - "2.7"
+  - "3.4"
 
 git:
   depth: 10
@@ -52,11 +52,6 @@ before_script:
   - rm -rf /tmp/couchjslogs
   - mkdir -p /tmp/couchjslogs
   - ./configure -c --disable-docs --disable-fauxton
-  - cd src/mango
-  - make venv
-  - source venv/bin/activate
-  - make pip-install
-  - cd ../..
 
 script:
    - make check
diff --git a/Makefile b/Makefile
index 554694eaf5..019a76d293 100644
--- a/Makefile
+++ b/Makefile
@@ -280,7 +280,11 @@ build-test:
 .PHONY: mango-test
 # target: mango-test - Run Mango tests
 mango-test: devclean all
-	@cd src/mango && ../../dev/run -n 1 --admin=testuser:testpass nosetests
+	@cd src/mango && \
+		virtualenv --python=python3 venv && \
+		. ./venv/bin/activate && \
+		pip3 install -r requirements.txt
+	@cd src/mango && ../../dev/run -n 1 --admin=testuser:testpass ./venv/bin/nosetests
 
 ################################################################################
 # Developing
diff --git a/README-DEV.rst b/README-DEV.rst
index 9cfa1f2efa..7f483a7c78 100644
--- a/README-DEV.rst
+++ b/README-DEV.rst
@@ -14,10 +14,7 @@ Dependencies
 
 You need the following to run tests:
 
-* `Python                 <https://www.python.org/>`_
-* `nose                   <https://nose.readthedocs.io/en/latest/>`_
-* `requests               <http://docs.python-requests.org/>`_
-* `hypothesis             <https://pypi.python.org/pypi/hypothesis>`_
+* `Python 3               <https://www.python.org/>`_
 
 You need the following optionally to build documentation:
 
@@ -60,7 +57,7 @@ Debian-based (inc. Ubuntu) Systems
 ::
 
     sudo apt-get install help2man python-sphinx gnupg nodejs npm \
-         python-hypothesis python-requests python-nose
+         python3 python3-virtualenv
 
 Gentoo-based Systems
 ~~~~~~~~~~~~~~~~~~~~
@@ -70,14 +67,14 @@ Gentoo-based Systems
     sudo emerge gnupg coreutils pkgconfig help2man sphinx python
     sudo pip install hypothesis requests nose
 
-RedHat-based (Fedora, Centos, RHEL) Systems
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Centos 7 and RHEL 7
+~~~~~~~~~~~~~~~~~~~
 
 ::
 
     sudo yum install help2man python-sphinx python-docutils \
-        python-pygments gnupg nodejs npm python-nose python-requests \
-        python-hypothesis
+        python-pygments gnupg nodejs npm python34-virtualenv
+
 
 Mac OS X
 ~~~~~~~~
@@ -89,7 +86,7 @@ Unless you want to install the optional dependencies, skip to the next section.
 
 Install what else we can with Homebrew::
 
-    brew install help2man gnupg md5sha1sum node
+    brew install help2man gnupg md5sha1sum node python
 
 If you don't already have pip installed, install it::
 
@@ -97,7 +94,7 @@ If you don't already have pip installed, install it::
 
 Now, install the required Python packages::
 
-    sudo pip install sphinx docutils pygments nose requests hypothesis sphinx_rtd_theme
+    sudo pip install sphinx docutils pygments sphinx_rtd_theme
 
 FreeBSD
 ~~~~~~~
diff --git a/build-aux/logfile-uploader.py b/build-aux/logfile-uploader.py
index a1ff7e4a72..c95eab5322 100755
--- a/build-aux/logfile-uploader.py
+++ b/build-aux/logfile-uploader.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
 # use this file except in compliance with the License. You may obtain a copy of
@@ -12,7 +12,7 @@
 # License for the specific language governing permissions and limitations under
 # the License.
 
-from __future__ import print_function
+
 
 import datetime
 import glob
diff --git a/dev/run b/dev/run
index f63c0e091b..a4fbfbf8d3 100755
--- a/dev/run
+++ b/dev/run
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
 # use this file except in compliance with the License. You may obtain a copy of
@@ -34,12 +34,12 @@ from pbkdf2 import pbkdf2_hex
 COMMON_SALT = uuid.uuid4().hex
 
 try:
-    from urllib import urlopen
+    from urllib.request import urlopen
 except ImportError:
     from urllib.request import urlopen
 
 try:
-    import httplib as httpclient
+    import http.client as httpclient
 except ImportError:
     import http.client as httpclient
 
@@ -58,7 +58,8 @@ def log(msg):
                 if log.verbose:
                     sys.stdout.write(chars)
                     sys.stdout.flush()
-            callargs = dict(list(zip(inspect.getargspec(func).args, args)))
+            argnames = list(inspect.signature(func).parameters.keys())
+            callargs = dict(list(zip(argnames, args)))
             callargs.update(kwargs)
             print_('[ * ] ' + msg.format(**callargs) + ' ... ')
             try:
@@ -365,7 +366,7 @@ def boot_nodes(ctx):
 
 
 def ensure_all_nodes_alive(ctx):
-    status = dict((num, False) for num in range(ctx['N']))
+    status = dict((num, False) for num in list(range(ctx['N'])))
     for _ in range(10):
         for num in range(ctx['N']):
             if status[num]:
diff --git a/rel/overlay/bin/couchup b/rel/overlay/bin/couchup
index 75b7d7e947..41ac4b857c 100755
--- a/rel/overlay/bin/couchup
+++ b/rel/overlay/bin/couchup
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
 # use this file except in compliance with the License. You may obtain a copy of
 # the License at
@@ -19,7 +19,7 @@ import threading
 import time
 import sys
 try:
-    from urllib import quote
+    from urllib.parse import quote
 except ImportError:
     from urllib.parse import quote
 import requests
diff --git a/src/mango/Makefile b/src/mango/Makefile
deleted file mode 100644
index 59f4a29c22..0000000000
--- a/src/mango/Makefile
+++ /dev/null
@@ -1,56 +0,0 @@
-REBAR?=rebar
-
-
-.PHONY: all
-# target: all - Makes everything
-all: build
-
-
-.PHONY: build
-# target: build - Builds the project
-build:
-	$(REBAR) compile
-
-
-.PHONY: check
-# target: check - Checks if project builds and passes all the tests
-check: build test
-
-
-.PHONY: clean
-# target: clean - Prints this help
-clean:
-	$(REBAR) clean
-	rm -f test/*.pyc
-
-
-.PHONY: distclean
-# target: distclean - Removes all unversioned files
-distclean: clean
-	git clean -fxd
-
-
-.PHONY: help
-# target: help - Prints this help
-help:
-	@egrep "^# target:" Makefile | sed -e 's/^# target: //g' | sort
-
-
-.PHONY: test
-# target: test - Runs test suite
-test:
-	nosetests
-
-
-.PHONY: pip-install
-# target: pip-install - Installs requires Python packages
-pip-install:
-	pip install nose requests
-	pip install hypothesis==3.79.0
-
-
-.PHONY: venv
-# target: venv - Initializes virtual environment (requires virtualenv)
-venv:
-	virtualenv --python=python2.7 venv
-	@echo "VirtualEnv has been created. Don't forget to run . venv/bin/active"
diff --git a/src/mango/requirements.txt b/src/mango/requirements.txt
new file mode 100644
index 0000000000..a56acebd0f
--- /dev/null
+++ b/src/mango/requirements.txt
@@ -0,0 +1,4 @@
+nose==1.3.7
+requests==2.20.1
+hypothesis==3.79.0
+
diff --git a/src/mango/test/02-basic-find-test.py b/src/mango/test/02-basic-find-test.py
index 6a31d33ee8..cfb0bae096 100644
--- a/src/mango/test/02-basic-find-test.py
+++ b/src/mango/test/02-basic-find-test.py
@@ -339,4 +339,4 @@ def test_sort_with_all_docs(self):
             "_id": {"$gt": 0},
             "age": {"$gt": 0}
         }, sort=["_id"], explain=True)
-        self.assertEquals(explain["index"]["type"], "special")
+        self.assertEqual(explain["index"]["type"], "special")
diff --git a/src/mango/test/04-key-tests.py b/src/mango/test/04-key-tests.py
index 4956d4689f..29451912d8 100644
--- a/src/mango/test/04-key-tests.py
+++ b/src/mango/test/04-key-tests.py
@@ -75,9 +75,9 @@ def test_dot_key(self):
         fields = ["title", "dot\\.key", "none.dot"]
         def check(docs):
             assert len(docs) == 4
-            assert docs[1].has_key("dot.key")
+            assert "dot.key" in docs[1]
             assert docs[1]["dot.key"] == "dot's value"
-            assert docs[1].has_key("none")
+            assert "none" in docs[1]
             assert docs[1]["none"]["dot"] == "none dot's value"
         self.run_check(query, check, fields=fields)
 
@@ -86,9 +86,9 @@ def test_peso_key(self):
         fields = ["title", "$key", "deep.$key"]
         def check(docs):
             assert len(docs) == 4
-            assert docs[2].has_key("$key")
+            assert "$key" in docs[2]
             assert docs[2]["$key"] == "peso"
-            assert docs[2].has_key("deep")
+            assert "deep" in docs[2]
             assert docs[2]["deep"]["$key"] == "deep peso"
         self.run_check(query, check, fields=fields)
 
@@ -98,8 +98,8 @@ def test_unicode_in_fieldname(self):
         def check(docs):
             assert len(docs) == 4
             # note:  == \uf8ff
-            assert docs[3].has_key(u'\uf8ff')
-            assert docs[3][u'\uf8ff'] == "apple"
+            assert '\uf8ff' in docs[3]
+            assert docs[3]['\uf8ff'] == "apple"
         self.run_check(query, check, fields=fields)
 
     # The rest of these tests are only run against the text
@@ -110,7 +110,7 @@ def test_unicode_in_selector_field(self):
         query = {"" : "apple"}
         def check(docs):
             assert len(docs) == 1
-            assert docs[0][u"\uf8ff"] == "apple"
+            assert docs[0]["\uf8ff"] == "apple"
         self.run_check(query, check, indexes=["text"])
 
     def test_internal_field_tests(self):
diff --git a/src/mango/test/06-basic-text-test.py b/src/mango/test/06-basic-text-test.py
index 3783006ab9..d48948bae7 100644
--- a/src/mango/test/06-basic-text-test.py
+++ b/src/mango/test/06-basic-text-test.py
@@ -285,7 +285,7 @@ def test_in_with_value(self):
             assert d["user_id"] in (1, 9)
 
         # Limits on boolean clauses?
-        docs = self.db.find({"age": {"$in": range(1000)}})
+        docs = self.db.find({"age": {"$in": list(range(1000))}})
         assert len(docs) == 15
 
     def test_in_with_array(self):
@@ -323,7 +323,7 @@ def test_nin_with_value(self):
             assert d["user_id"] not in (1, 9)
 
         # Limits on boolean clauses?
-        docs = self.db.find({"age": {"$nin": range(1000)}})
+        docs = self.db.find({"age": {"$nin": list(range(1000))}})
         assert len(docs) == 0
 
     def test_nin_with_array(self):
diff --git a/src/mango/test/README.md b/src/mango/test/README.md
index 3c99cab9dd..3e75f72d16 100644
--- a/src/mango/test/README.md
+++ b/src/mango/test/README.md
@@ -5,10 +5,10 @@ CouchDB should be started with `./dev/run -a testuser:testpass`.
 
 To run these, do this in the Mango top level directory:
 
-    $ virtualenv venv
-    $ source venv/bin/activate
-    $ make pip-install
-    $ make test
+    $ virtualenv --python=python3 venv
+    $ . venv/bin/activate
+    $ pip3 install -r requirements.txt
+    $ ./venv/bin/nosetests
 
 To run an individual test suite:
     nosetests --nocapture test/12-use-correct-index.py 
diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py
index 59486c8610..dfe220d2b1 100644
--- a/src/mango/test/mango.py
+++ b/src/mango/test/mango.py
@@ -67,7 +67,7 @@ def url(self):
         return "{}/{}".format(self.root_url, self.dbname)
 
     def path(self, parts):
-        if isinstance(parts, ("".__class__, u"".__class__)):
+        if isinstance(parts, ("".__class__, "".__class__)):
             parts = [parts]
         return "/".join([self.url] + parts)
 
diff --git a/test/javascript/run b/test/javascript/run
index ec12431b03..283a7f7795 100755
--- a/test/javascript/run
+++ b/test/javascript/run
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
 # use this file except in compliance with the License. You may obtain a copy of


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services