Skip to content
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

Py3 #67

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open

Py3 #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 102 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,103 @@
# 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

# 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
/ve/
*.pyc
*.egg-info
/dist/
/docs/_build/

/htmlcov/
/vepypy/
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Additional custom rules
ve/
.test_repos/
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
sudo: false
language: python
python:
- "2.7"
- "pypy"
- '2.7'
- '3.4'
- '3.5'
- '3.6'
services:
- elasticsearch
install:

before_install:
- pip install --upgrade pip
install:
- pip install -r requirements-dev.txt
- pip install -e .
- pip install coveralls
- pip install flake8
script:
- flake8 elasticgit
- py.test elasticgit -s --cov ./elasticgit
- flake8
after_success:
- coveralls
deploy:
Expand Down
12 changes: 9 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
include LICENSE
include README.rst
include VERSION
include requirements.txt
include scripts/eg-tools
recursive-include elasticgit *.py *.txt
include requirements-dev.txt

recursive-include elasticgit/templates *

recursive-include docs *
prune docs/build

global-exclude __pycache__
global-exclude *.py[co]
6 changes: 4 additions & 2 deletions elasticgit/commands/avro.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import

from jinja2 import Environment, PackageLoader
from functools import partial
from functools import partial, reduce
import argparse
import imp
import json
Expand All @@ -20,6 +20,8 @@
ToolCommand, ToolCommandError, CommandArgument)
from elasticgit.utils import load_class

from six import exec_


def deserialize(data, field_mapping={}, module_name=None):
"""
Expand Down Expand Up @@ -61,7 +63,7 @@ def deserialize(data, field_mapping={}, module_name=None):
else:
scope = {}

exec model_code in scope
exec_(model_code, scope)

return scope.pop(model_name)

Expand Down
4 changes: 4 additions & 0 deletions elasticgit/commands/gitmodel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import glob
import json
import sys
import warnings

from elasticgit.commands.base import ToolCommand, CommandArgument
Expand All @@ -9,6 +10,9 @@

from git import Repo

if sys.version_info[0] == 3:
unicode = str


class NotAGitModelException(Exception):
pass
Expand Down
2 changes: 1 addition & 1 deletion elasticgit/commands/resync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import json

from ConfigParser import ConfigParser
from six.moves.configparser import ConfigParser

from elasticgit import EG
from elasticgit.commands.base import (
Expand Down
4 changes: 3 additions & 1 deletion elasticgit/commands/shell.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import os

from elasticgit.commands.base import ToolCommand, CommandArgument
Expand Down Expand Up @@ -84,7 +86,7 @@ def run(self, workdir, models=None, introspect_models=None):
found_models = load_models(models)
namespace.update(found_models)
except ValueError:
print '%s does not look like a models module.' % (models,)
print('%s does not look like a models module.' % (models,))

namespace.update({
'workspace': EG.workspace(workdir),
Expand Down
11 changes: 6 additions & 5 deletions elasticgit/commands/tests/test_gitmodel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import json

from StringIO import StringIO
import os
from contextlib import contextmanager
from uuid import uuid4
from elasticgit.commands.gitmodel import MigrateGitModelRepo

from six import StringIO

from elasticgit.commands import avro
from elasticgit.commands.gitmodel import MigrateGitModelRepo
from elasticgit.tests.base import ToolBaseTest
from contextlib import contextmanager


class TestMigrateGitModelRepo(ToolBaseTest):
Expand Down
4 changes: 2 additions & 2 deletions elasticgit/commands/tests/test_resync.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from StringIO import StringIO
from ConfigParser import ConfigParser
from six import StringIO
from six.moves.configparser import ConfigParser

from elasticgit.tests.base import ToolBaseTest, TestPerson
from elasticgit.commands.resync import ResyncTool, DEFAULT_SECTION
Expand Down
3 changes: 2 additions & 1 deletion elasticgit/commands/tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from StringIO import StringIO
import json

from six import StringIO

from elasticgit.models import version_info
from elasticgit.tests.base import ToolBaseTest
from elasticgit.commands.version import VersionTool, DEFAULT_FILE_NAME
Expand Down
15 changes: 9 additions & 6 deletions elasticgit/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import sys
import pkg_resources
from copy import deepcopy
from urllib2 import urlparse
import uuid

from confmodel.config import Config, ConfigField
from confmodel.errors import ConfigError
from confmodel.fallbacks import SingleFieldFallback
from six.moves import urllib


if sys.version_info[0] == 3:
unicode = str

version_info = {
'language': 'python',
'language_version_string': sys.version,
Expand Down Expand Up @@ -49,8 +52,8 @@ class TextField(ModelField):
field_type = 'str'

def clean(self, value):
if not isinstance(value, basestring):
self.raise_config_error("is not a base string.")
if not isinstance(value, str):
self.raise_config_error("is not a string.")
return value


Expand Down Expand Up @@ -116,7 +119,7 @@ class BooleanField(ModelField):
}

def clean(self, value):
if isinstance(value, basestring):
if isinstance(value, str):
return value.strip().lower() not in ('false', '0', '')
return bool(value)

Expand Down Expand Up @@ -200,12 +203,12 @@ class URLField(ModelField):
}

def clean(self, value):
if not isinstance(value, basestring):
if not isinstance(value, str):
self.raise_config_error("is not a URL string.")
# URLs must be bytes, not unicode.
if isinstance(value, unicode):
value = value.encode('utf-8')
return urlparse.urlparse(value)
return urllib.parse.urlparse(value)


class UUIDField(TextField):
Expand Down
7 changes: 4 additions & 3 deletions elasticgit/search.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
from urllib import quote

from git import Repo

from elasticutils import (
MappingType, Indexable, S as SBase,
ObjectSearchResults, DictSearchResults, ListSearchResults)

from six.moves import urllib

from elasticgit.utils import introspect_properties
from elasticgit.storage.remote import RemoteStorageManager

Expand All @@ -23,7 +24,7 @@ def index_name(prefix, name):
The name to use for the index.
:returns: str
"""
return '-'.join(map(quote, [prefix, name]))
return '-'.join(map(urllib.parse.quote, [prefix, name]))


class ModelMappingTypeBase(MappingType):
Expand Down Expand Up @@ -235,7 +236,7 @@ def get_repo_indexes(self):
return []

return map(
lambda (ip, r): index_name(ip, r.active_branch_name()),
lambda ip, r: index_name(ip, r.active_branch_name()),
zip(self.index_prefixes, self.repos))

def _clone(self, next_step=None):
Expand Down
11 changes: 5 additions & 6 deletions elasticgit/storage/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shutil
import logging

from zope.interface import implements
from zope.interface import implementer

from git import Repo, Actor
from git.diff import DiffIndex
Expand All @@ -20,6 +20,7 @@ class StorageException(Exception):
pass


@implementer(IStorageManager)
class StorageManager(object):
"""
An interface to :py:class:`elasticgit.models.Model` instances stored
Expand All @@ -28,8 +29,6 @@ class StorageManager(object):
:param git.Repo repo:
The repository to operate on.
"""
implements(IStorageManager)

serializer_class = JSONSerializer

def __init__(self, repo):
Expand Down Expand Up @@ -124,12 +123,12 @@ def path_info(self, file_path):
raise StorageException('%r does not subclass %r' % (
model_class, Model))
return model_class, uuid
except ValueError, e:
except ValueError as e:
log.warn('%s does not look like a model file path.' % (
file_path,), exc_info=True)
except ImportError, e:
except ImportError as e:
log.warn(e, exc_info=True)
except StorageException, e:
except StorageException as e:
log.warn(e, exc_info=True)

def load(self, file_path):
Expand Down
Loading