Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zensoup committed Dec 21, 2018
1 parent 0dddfb4 commit 18e2d0f
Show file tree
Hide file tree
Showing 32 changed files with 751 additions and 631 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ settings.py
README.pdf
docs/_build/
examples
.pre-commit-config.yaml
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FHIRBUG

.. image:: https://img.shields.io/badge/python-3.6%20%7C%203.7-blue.svg
:alt: Python Versions
:target:
:target: https://github.com/zensoup/fhirbug

Fhirbug intends to be a full-featured `FHIR`_ server for python >= **3.6**. It has been
designed to be easy to set up and configure and be flexible when it comes to
Expand Down
58 changes: 29 additions & 29 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

# -- Project information -----------------------------------------------------
import sys
sys.path.append('..')

project = 'fhirbug'
copyright = '2018, Vangelis Kostalas'
author = 'Vangelis Kostalas'
sys.path.append("..")

project = "fhirbug"
copyright = "2018, Vangelis Kostalas"
author = "Vangelis Kostalas"

# The short X.Y version
version = ''
version = ""
# The full version, including alpha/beta/rc tags
release = ''
release = ""


# -- General configuration ---------------------------------------------------
Expand All @@ -41,23 +42,23 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.coverage",
"sphinx.ext.ifconfig",
"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"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -69,7 +70,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects 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 = None
Expand All @@ -92,7 +93,7 @@
# 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"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -108,7 +109,7 @@
# -- Options for HTMLHelp output ---------------------------------------------

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


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -117,15 +118,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 @@ -135,19 +133,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'fhirbug.tex', 'fhirbug Documentation',
'Vangelis Kostalas', 'manual'),
(master_doc, "fhirbug.tex", "fhirbug Documentation", "Vangelis Kostalas", "manual")
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'fhirbug', 'fhirbug Documentation',
[author], 1)
]
man_pages = [(master_doc, "fhirbug", "fhirbug Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -156,9 +150,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'fhirbug', 'fhirbug Documentation',
author, 'fhirbug', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"fhirbug",
"fhirbug Documentation",
author,
"fhirbug",
"One line description of project.",
"Miscellaneous",
)
]


Expand All @@ -177,7 +177,7 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]


# -- Extension configuration -------------------------------------------------
30 changes: 18 additions & 12 deletions fhirbug/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,40 @@

settings = LazySettings()


def import_models():
"""
Dynamic import of the models module based on the backend selected in the configuration
"""
global settings
if not settings:
raise ConfigurationError('Fhirbug settings have not been initialized. Use fhirbug.config.configure before using fhirbug.')
raise ConfigurationError(
"Fhirbug settings have not been initialized. Use fhirbug.config.configure before using fhirbug."
)
try:
models_path = getattr(settings, 'MODELS_PATH')
models_path = getattr(settings, "MODELS_PATH")
except AttributeError:
raise ConfigurationError('settings.MODELS_PATH has not been defined.')
raise ConfigurationError("settings.MODELS_PATH has not been defined.")
return importlib.import_module(models_path)


def import_searches():
"""
Dynamic import of the searches module based on the backend selected in the configuration
"""
global settings
if not settings:
raise ConfigurationError('Fhirbug settings have not been initialized. Use fhirbug.config.configure before using fhirbug.')
raise ConfigurationError(
"Fhirbug settings have not been initialized. Use fhirbug.config.configure before using fhirbug."
)
try:
db_backend = getattr(settings, 'DB_BACKEND')
db_backend = getattr(settings, "DB_BACKEND")
except AttributeError:
raise ConfigurationError('settings.DB_BACKEND has not been defined.')
raise ConfigurationError("settings.DB_BACKEND has not been defined.")

if db_backend.lower() == 'sqlalchemy':
return importlib.import_module('fhirbug.db.backends.SQLAlchemy.searches')
elif db_backend.lower() == 'djangoorm':
return importlib.import_module('fhirbug.db.backends.DjangoORM.searches')
elif db_backend.lower() == 'pymodm':
return importlib.import_module('fhirbug.db.backends.pymodm.searches')
if db_backend.lower() == "sqlalchemy":
return importlib.import_module("fhirbug.db.backends.SQLAlchemy.searches")
elif db_backend.lower() == "djangoorm":
return importlib.import_module("fhirbug.db.backends.DjangoORM.searches")
elif db_backend.lower() == "pymodm":
return importlib.import_module("fhirbug.db.backends.pymodm.searches")
4 changes: 2 additions & 2 deletions fhirbug/config/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
MAX_BUNDLE_SIZE = 100

# Path to the models module
MODELS_PATH = 'models'
MODELS_PATH = "models"

# Which DB backend should be used
# SQLAlchemy | DjangoORM | PyMODM
DB_BACKEND = 'SQLAlchemy'
DB_BACKEND = "SQLAlchemy"
12 changes: 8 additions & 4 deletions fhirbug/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ def configure(self, config=None):
if config is None:
settings = self._configure_from_defaults()
self._wrapped = settings
print(('WARNING: Settings have been configured from the default values.'
' If this is not intended, you are probably not configuring '
'them before importing your mappings'))
print(
(
"WARNING: Settings have been configured from the default values."
" If this is not intended, you are probably not configuring "
"them before importing your mappings"
)
)
return settings
if isinstance(config, str):
return self._configure_from_path(config)
Expand All @@ -49,7 +53,7 @@ def __getattr__(self, name):
return getattr(self._wrapped, name)

def __setattr__(self, name, value):
if name == '_wrapped':
if name == "_wrapped":
# Assign to __dict__ to avoid infinite __setattr__ loops.
self.__dict__["_wrapped"] = value
return
Expand Down
4 changes: 2 additions & 2 deletions fhirbug/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'''
"""
This package wraps all db related modules.
'''
"""
70 changes: 35 additions & 35 deletions fhirbug/db/backends/DjangoORM/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@
from fhirbug.exceptions import DoesNotExistError



class AbstractBaseModel(models.Model, FhirAbstractBaseMixin):
"""
"""
The base class to provide functionality to
our models.
"""
class Meta:
abstract = True

@classmethod
def _get_orm_query(cls):
return cls.objects
class Meta:
abstract = True

@classmethod
def _get_orm_query(cls):
return cls.objects

@classmethod
def _get_item_from_pk(cls, pk):
try:
return cls.objects.get(pk=pk)
except cls.DoesNotExist:
raise DoesNotExistError(resource_type=cls.__name__, pk=pk)
@classmethod
def _get_item_from_pk(cls, pk):
try:
return cls.objects.get(pk=pk)
except cls.DoesNotExist:
raise DoesNotExistError(resource_type=cls.__name__, pk=pk)


class FhirBaseModel(AbstractBaseModel, FhirBaseModelMixin):
class Meta:
abstract = True

@classmethod
def paginate(cls, *args, **kwargs):
return paginate(*args, **kwargs)

@classmethod
def _after_create(cls, instance):
try:
instance.save()
except Exception as e:
raise e
return instance

@classmethod
def _after_update(cls, instance):
try:
instance.save()
except Exception as e:
raise e
return instance
class Meta:
abstract = True

@classmethod
def paginate(cls, *args, **kwargs):
return paginate(*args, **kwargs)

@classmethod
def _after_create(cls, instance):
try:
instance.save()
except Exception as e:
raise e
return instance

@classmethod
def _after_update(cls, instance):
try:
instance.save()
except Exception as e:
raise e
return instance
8 changes: 4 additions & 4 deletions fhirbug/db/backends/DjangoORM/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@


def paginate(query, page, page_size):
'''
"""
Implement pagination for Django ORM.
'''
"""
if page <= 0:
raise AttributeError('page needs to be >= 1')
raise AttributeError("page needs to be >= 1")
if page_size <= 0:
raise AttributeError('page_size needs to be >= 1')
raise AttributeError("page_size needs to be >= 1")
items = query.all()
paginator = Paginator(items, page_size)
items = paginator.get_page(page)
Expand Down

0 comments on commit 18e2d0f

Please sign in to comment.