diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..e41cc6f2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,29 @@ +# Copyright 2018 RebirthDB +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +root = true + +[*] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +insert_final_newline = true +charset = utf-8 +end_of_line = lf + +[LICENSE] +insert_final_newline = false + +[Makefile] +indent_style = tab diff --git a/.gitignore b/.gitignore index e21c3d1f..300d5763 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,73 @@ -dist -rethinkdb.egg-info +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# pyenv +.python-version + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +virtualenv/ + +# RebirthDB rethinkdb/ql2_pb2.py +rethinkdb/*.proto + +# Editors +.vscode/ +.idea/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..1a3de248 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +sudo: false +language: python +python: + - "2.7" + - "3.4" + - "3.5" + - "3.6" + +before_script: make prepare +script: tox diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..c17a2c5e --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright 2018 RebirthDB + +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/Makefile b/Makefile index e11a5858..e10758f0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,63 @@ -# Copyright 2014 RethinkDB, all rights reserved. +# Copyright 2018 RebirthDB +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -OVERRIDE_GOALS := clean=py-clean publish=py-publish sdist=py-sdist bdist=py-bdist install=py-install default-goal=py-driver +.PHONY: default help clean prepare package publish + +PACKAGE_NAME = rethinkdb + +BUILD_DIR = ./build +PACKAGE_DIR = ${BUILD_DIR}/package + +PROTO_FILE_NAME = ql2.proto +PROTO_FILE_URL = https://raw.githubusercontent.com/RebirthDB/rebirthdb/next/src/rdb_protocol/${PROTO_FILE_NAME} +TARGET_PROTO_FILE = ${PACKAGE_NAME}/${PROTO_FILE_NAME} + +FILE_CONVERTER_NAME = convert_protofile.py +FILE_CONVERTER_URL = https://raw.githubusercontent.com/RebirthDB/rebirthdb/next/scripts/${FILE_CONVERTER_NAME} + +CONVERTED_PROTO_FILE_NAME = ql2_pb2.py +TARGET_CONVERTED_PROTO_FILE = ${PACKAGE_NAME}/${CONVERTED_PROTO_FILE_NAME} + + +default: help + +help: + @echo "Usage:" + @echo + @echo " make help Print this help message" + @echo " make test Run unit tests" + @echo " make clean Cleanup source directory" + @echo " make prepare Prepare ${PACKAGE_NAME} for build" + @echo " make package Build ${PACKAGE_NAME} package" + @echo " make publish Publish ${PACKAGE_NAME} package on PyPi" + +clean: + @rm -rf \ + ${TARGET_PROTO_FILE} \ + ${TARGET_CONVERTED_PROTO_FILE} \ + ${BUILD_DIR} + +prepare: + curl -qo ${TARGET_PROTO_FILE} ${PROTO_FILE_URL} + curl -qo ${FILE_CONVERTER_NAME} ${FILE_CONVERTER_URL} + python ./${FILE_CONVERTER_NAME} -l python -i ${TARGET_PROTO_FILE} -o ${TARGET_CONVERTED_PROTO_FILE} + rsync -av ./ ${BUILD_DIR} --filter=':- .gitignore' + cp ${TARGET_PROTO_FILE} ${BUILD_DIR}/${PACKAGE_NAME} + +package: prepare + cd ${BUILD_DIR} && python ./setup.py sdist --dist-dir=$(abspath ${PACKAGE_DIR}) + +publish: + cd ${BUILD_DIR} && python ./setup.py register upload -TOP := ../.. -include $(TOP)/Makefile diff --git a/build.mk b/build.mk deleted file mode 100644 index 7bdfea97..00000000 --- a/build.mk +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2014 RethinkDB, all rights reserved. - -PY_SRC_DIR = $(TOP)/drivers/python -PY_BUILD_DIR = $(TOP)/build/drivers/python -PY_PKG_DIR = $(TOP)/build/packages/python - -PY_PROTO_FILE_NAME = ql2_pb2.py - -PY_PROTO_BUILD_FILE := $(PY_BUILD_DIR)/rethinkdb/$(PY_PROTO_FILE_NAME) -# convenience file for driver development -PY_PROTO_DEV_FILE := $(PY_SRC_DIR)/rethinkdb/$(PY_PROTO_FILE_NAME) - -PY_SRC_FILES := $(filter-out $(PY_SRC_DIR)/rethinkdb/$(PY_PROTO_FILE_NAME),$(shell find $(PY_SRC_DIR)/rethinkdb/ -type f ! -iname '*.pyc')) -PY_BUILD_FILES := $(patsubst $(PY_SRC_DIR)/rethinkdb/%,$(PY_BUILD_DIR)/rethinkdb/%,$(PY_SRC_FILES)) $(PY_PROTO_BUILD_FILE) - -.PHONY: py-driver -py-driver: $(PY_BUILD_FILES) $(PY_PROTO_DEV_FILE) | $(PY_BUILD_DIR)/. - -$(PY_BUILD_DIR)/rethinkdb/%: $(PY_SRC_DIR)/rethinkdb/% py_build_files - mkdir -p $(@D) - cp $< $@ - -.INTERMEDIATE: py_build_files -py_build_files: - $P CP $(PY_BUILD_DIR)/rethinkdb/ - -$(PY_PROTO_DEV_FILE) $(PY_PROTO_BUILD_FILE): $(PROTO_FILE_SRC) - $P CONVERT_PROTOFILE - mkdir -p $(dir $@) - $(PYTHON) $(TOP)/drivers/convert_protofile --language python --input-file $(PROTO_FILE_SRC) --output-file $@ - -$(PY_BUILD_DIR)/setup.py: $(PY_SRC_DIR)/setup.py | $(PY_BUILD_DIR) - $P CP - cp $< $@ - -.PHONY: py-clean -py-clean: - $P RM $(PY_BUILD_DIR) - rm -rf $(PY_BUILD_DIR) - $P RM $(PY_PKG_DIR) - rm -rf $(PY_PKG_DIR) - $P RM $(PY_PROTO_DEV_FILE) - rm -f $(PY_PROTO_DEV_FILE) - -.PHONY: py-sdist -py-sdist: py-driver $(PY_BUILD_DIR)/setup.py | $(PY_PKG_DIR)/. - $P SDIST - cd $(PY_BUILD_DIR) && $(PYTHON) setup.py sdist --dist-dir=$(abspath $(PY_PKG_DIR)) - -.PHONY: py-bdist -py-bdist: py-driver $(PY_BUILD_DIR)/setup.py | $(PY_PKG_DIR)/. - $P BDIST_EGG - cd $(PY_BUILD_DIR) && $(PYTHON) setup.py bdist_egg --dist-dir=$(abspath $(PY_PKG_DIR)) - -.PHONY: py-publish -py-publish: py-driver $(PY_BUILD_DIR)/setup.py | $(PY_PKG_DIR)/. - $P REGISTER SDIST - cd $(PY_BUILD_DIR) && $(PYTHON) setup.py register sdist --dist-dir=$(abspath $(PY_PKG_DIR)) upload - -.PHONY: py-install -py-install: py-driver $(PY_BUILD_DIR)/setup.py | $(PY_PKG_DIR)/. - $P INSTALL - cd $(PY_BUILD_DIR) && $(PYTHON) setup.py install diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..cfe5bbd3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +# CI requirements +tox-travis==0.10 + +# Test requirements +pytest==3.6.3 +tox==3.1.1 diff --git a/rethinkdb/.gitignore b/rethinkdb/.gitignore deleted file mode 100644 index 4f67eee8..00000000 --- a/rethinkdb/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -ql2.proto - diff --git a/rethinkdb/version.py b/rethinkdb/version.py index 071546be..f92fdbf4 100644 --- a/rethinkdb/version.py +++ b/rethinkdb/version.py @@ -1 +1,18 @@ -version = '2.3.0.post3' +# Copyright 2018 RebirthDB +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This file incorporates work covered by the following copyright: +# Copyright 2010-2016 RethinkDB, all rights reserved. + +version = '2.3.1' diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..da415b1c --- /dev/null +++ b/setup.cfg @@ -0,0 +1,23 @@ +# Copyright 2018 RebirthDB +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +[bdist_wheel] +universal = 1 + +[aliases] +test = pytest + +[tool:pytest] +collect_ignore = ['setup.py'] diff --git a/setup.py b/setup.py index 1c6f47b6..84a003f7 100644 --- a/setup.py +++ b/setup.py @@ -1,38 +1,54 @@ -# Copyright 2010-2015 RethinkDB, all rights reserved. -""" -Please see the following links for more information:: +# Copyright 2018 RebirthDB +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This file incorporates work covered by the following copyright: +# Copyright 2010-2016 RethinkDB, all rights reserved. -- `Python API documentation `_ -- `GitHub Project `_ -- `Python Driver Source `_ +''' -""" +''' -import os, setuptools, sys +import setuptools -modulePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'rethinkdb') -sys.path.insert(0, modulePath) -from version import version -sys.path.remove(modulePath) +try: + import asyncio + conditional_packages = ['rethinkdb.asyncio_net'] +except ImportError: + conditional_packages = [] + +from rethinkdb.version import version -conditionalPackages = [] -if 'upload' in sys.argv: # ensure that uplodas always have everything while uploading to pypi - conditionalPackages = ['rethinkdb.asyncio_net'] -else: - try: # only add asyncio when it is supported per #4702 - import asyncio - conditionalPackages = ['rethinkdb.asyncio_net'] - except ImportError: pass setuptools.setup( - name="rethinkdb", + name='rethinkdb', zip_safe=True, version=version, - description="Python driver library for the RethinkDB database server.", + description='Python driver library for the RethinkDB database server.', long_description=__doc__, - url="http://rethinkdb.com", - maintainer="RethinkDB Inc.", - maintainer_email="bugs@rethinkdb.com", + url='https://github.com/RebirthDB/rebirthdb-python', + maintainer='RebirthDB.', + maintainer_email='bugs@rethinkdb.com', + classifiers=[ + 'Intended Audience :: Developers', + 'Natural Language :: English', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + ], packages=[ 'rethinkdb', 'rethinkdb.tornado_net', @@ -40,7 +56,7 @@ 'rethinkdb.gevent_net', 'rethinkdb.backports', 'rethinkdb.backports.ssl_match_hostname' - ] + conditionalPackages, + ] + conditional_packages, package_dir={'rethinkdb':'rethinkdb'}, package_data={ 'rethinkdb':['backports/ssl_match_hostname/*.txt'] }, entry_points={ @@ -52,5 +68,8 @@ 'rethinkdb-index-rebuild = rethinkdb._index_rebuild:main', 'rethinkdb-repl = rethinkdb.__main__:startInterpreter' ] - } + }, + setup_requires=['pytest-runner'], + test_suite='tests', + tests_require=['pytest'] ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e9c525c7 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2018 RebirthDB +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/tests/test_dummy.py b/tests/test_dummy.py new file mode 100644 index 00000000..8c281116 --- /dev/null +++ b/tests/test_dummy.py @@ -0,0 +1,9 @@ +class TestDummy(object): + def setup_method(self, test_method): + pass + + def teardown_method(self, test_method): + pass + + def test_true(self): + assert True diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..bbb9ef63 --- /dev/null +++ b/tox.ini @@ -0,0 +1,41 @@ +# Copyright 2018 RebirthDB +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[tox] +envlist = py27, py34, py35, py36 #, flake8 +skipsdist = {env:TOXBUILD:false} + +[flake8] +max-line-length = 120 +import-order-style = google +exclude = + .git, + __pycache__, + build, + dist + +[testenv] +passenv = LANG +setenv = + PYTHONPATH = {toxinidir} +deps = + -r{toxinidir}/requirements.txt +commands = {env:TOXBUILD:pytest} + +[testenv:flake8] +basepython = python +deps = + flake8 + flake8-import-order +commands = flake8 rethinkdb