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

Static checks #12

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
hooks:
- id: trailing-whitespace
- id: check-ast
- id: check-merge-conflict
- id: flake8
- repo: https://github.com/asottile/seed-isort-config
rev: v1.8.0
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.17
hooks:
- id: isort
- repo: https://github.com/ambv/black
rev: 19.3b0
hooks:
- id: black
- repo: local
hooks:
- id: pylint
name: pylint
entry: python -m pylint.__main__ --disable=R,C,W0221
language: system
files: ^nameko_salesforce/
types: [python]
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
- redis-server

stages:
- static
- test

jobs:
Expand All @@ -26,6 +27,13 @@ jobs:
env: DEPS="nameko>=2.12.0"
- python: 3.5
env: DEPS="nameko>=2.12.0"
- python: 3.6
stage: static
install:
- pip install -U -e ".[dev]"
- pip install pre-commit
script: make static
env:

matrix:
allow_failures:
Expand All @@ -38,7 +46,7 @@ install:
- pip install -U $DEPS

script:
- make test
- make pytest

deploy:

Expand Down
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
test: flake8 pylint pytest
test: static pytest

flake8:
flake8 nameko_salesforce tests

pylint:
pylint nameko_salesforce -E
static:
pre-commit run --all-files

pytest:
coverage run --concurrency=eventlet --source nameko_salesforce --branch -m pytest tests
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ has an RPC endpoint for creating new Contact objects in Salesforce:
@handle_sobject_notification('Contact', exclude_current_user=False)
def handle_contact_updates(
self, sobject_type, record_type, notification
):
):
""" Handle Salesforce contacts updates
"""
print(notification)
Expand Down
74 changes: 41 additions & 33 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sphinx_rtd_theme


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand All @@ -31,36 +34,38 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.viewcode']
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['.templates']
templates_path = [".templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'Nameko Salesforce'
copyright = '2017, Student.com'
author = 'Student.com'
project = "Nameko Salesforce"
copyright = "2017, Student.com"
author = "Student.com"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = ''
version = ""
# The full version, including alpha/beta/rc tags.
release = ''
release = ""

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -72,10 +77,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['.build', 'Thumbs.db', '.DS_Store']
exclude_patterns = [".build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
Expand All @@ -86,28 +91,26 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'
html_theme = "alabaster"
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

import sphinx_rtd_theme
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['.static']
html_static_path = [".static"]


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'NamekoSalesforcedoc'
htmlhelp_basename = "NamekoSalesforcedoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -116,15 +119,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -134,8 +134,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'NamekoSalesforce.tex', 'Nameko Salesforce Documentation',
'Student.com', 'manual'),
(
master_doc,
"NamekoSalesforce.tex",
"Nameko Salesforce Documentation",
"Student.com",
"manual",
)
]


Expand All @@ -144,8 +149,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'namekosalesforce', 'Nameko Salesforce Documentation',
[author], 1)
(master_doc, "namekosalesforce", "Nameko Salesforce Documentation", [author], 1)
]


Expand All @@ -155,13 +159,17 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'NamekoSalesforce', 'Nameko Salesforce Documentation',
author, 'NamekoSalesforce', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"NamekoSalesforce",
"Nameko Salesforce Documentation",
author,
"NamekoSalesforce",
"One line description of project.",
"Miscellaneous",
)
]




# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}
8 changes: 4 additions & 4 deletions docs/streaming-api-client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ There are more options available for defining Push Topics:
notify_for_operation_delete=False)
def handle_contact_updates(self, name, notification):
""" Handle Salesforce contacts name changes

Handles only first and last name changes of existing contacts.
Ignores any other modification.

Expand Down Expand Up @@ -145,7 +145,7 @@ Declaring notification of Salesforce object changes:
@handle_sobject_notification('Contact')
def handle_contact_updates(
self, sobject_type, record_type, notification
):
):
""" Handle Salesforce contacts updates
"""

Expand Down Expand Up @@ -189,10 +189,10 @@ The following example shows available notification options:
self, sobject_type, record_type, notification
):
""" Handle Salesforce student contacts name changes

Handles only name changes of existing contacts of type of student.
Ignores any other modification.

Also ignores changes done by this service (more precisely changes
done by the same API user as this extension use for connection
to Salesforce streaming API).
Expand Down
25 changes: 8 additions & 17 deletions nameko_salesforce/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def __init__(self, pool, get_method_ref):
self.pool = pool
self.get_method_ref = get_method_ref

@retry(
max_attempts=None,
for_exceptions=simple_salesforce.SalesforceExpiredSession)
@retry(max_attempts=None, for_exceptions=simple_salesforce.SalesforceExpiredSession)
def __call__(self, *args, **kwargs):

with self.pool.get() as client:
Expand All @@ -57,7 +55,7 @@ def __call__(self, *args, **kwargs):
return method(*args, **kwargs)
except (
simple_salesforce.SalesforceExpiredSession,
requests.exceptions.ConnectionError
requests.exceptions.ConnectionError,
):
self.pool.discard(client)
raise
Expand All @@ -81,7 +79,6 @@ def __init__(self, attr_name, *args):
super().__init__(*args)

def __getattr__(self, name):

def get_method_ref(client):
attr = getattr(client, self.attr_name)
return getattr(attr, name)
Expand All @@ -104,13 +101,10 @@ def __init__(self, pool):
self.pool = pool

def __getattr__(self, name):

def get_method_ref(client):
return getattr(client, name)

return ClientAttributeProxy(
name, self.pool, get_method_ref
)
return ClientAttributeProxy(name, self.pool, get_method_ref)


class ClientPool(object):
Expand All @@ -122,8 +116,7 @@ class ClientPool(object):
"""

def __init__(
self, username, password, security_token,
sandbox=False, api_version=None
self, username, password, security_token, sandbox=False, api_version=None
):
self.username = username
self.password = password
Expand Down Expand Up @@ -154,21 +147,19 @@ def create(self):
session = requests.Session()
retry_adapter = requests.adapters.HTTPAdapter(
max_retries=Retry(
connect=CONNECT_RETRIES,
read=READ_RETRIES,
redirect=REDIRECT_RETRIES
connect=CONNECT_RETRIES, read=READ_RETRIES, redirect=REDIRECT_RETRIES
)
)
session.mount('http://', retry_adapter)
session.mount('https://', retry_adapter)
session.mount("http://", retry_adapter)
session.mount("https://", retry_adapter)

client = simple_salesforce.Salesforce(
username=self.username,
password=self.password,
security_token=self.security_token,
sandbox=self.sandbox,
version=self.api_version,
session=session
session=session,
)
return client

Expand Down
Loading