Skip to content

Commit

Permalink
Merge pull request #6 from sdss/codehealth
Browse files Browse the repository at this point in the history
code health and pypi release
  • Loading branch information
havok2063 authored Oct 1, 2020
2 parents 0e578cc + dd9b682 commit 1ff5d5c
Show file tree
Hide file tree
Showing 19 changed files with 321 additions and 503 deletions.
4 changes: 2 additions & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.5dev
current_version = 0.2.0
commit = True
tag = False
tag_name = {new_version}
Expand All @@ -14,5 +14,5 @@ values =
dev
alpha

[bumpversion:file:python/brain/__init__.py]
[bumpversion:file:setup.cfg]

110 changes: 110 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

*.DS_Store

# C extensions
*.so
*.o
*.a

# Distribution / packaging
.Python
env/
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*
.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/
docs/sphinx/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.vscode

.pytest_cache
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Marvin's Brain Change Log
=========================

[0.2.0] - 2020/09/20
--------------------
- refactoring for code health
- added setup.py and cfg
- moved to sdsstools for logging and config
- moved tests to top level

[0.1.4] - 2020/08/31
--------------------
- Syntax change to accommodate networkx 2.4.x deprecations
Expand Down
31 changes: 31 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
BSD 3-Clause License

Copyright (c) 2020, SDSS
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
This repository has moved to https://github.com/sdss/marvin_brain
This repository is mainly a dependency for https://github.com/sdss/marvin, containing some core
logic and functions pertaining to Flask API infrastructure for the Marvin API. It is not useable as a product or python package by itself. The original ideas behind ``marvin_brain`` has largely been expanded into [sdss_brain](https://github.com/sdss/sdss_brain) and [valis](https://github.com/sdss/valis).


Useful links
------------

- GitHub: https://github.com/sdss/marvin_brain
- Issues: https://github.com/sdss/marvin_brain/issues
28 changes: 14 additions & 14 deletions python/brain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@
import os
import netrc
import warnings
import yaml
from brain.core.exceptions import BrainError, BrainUserWarning
from brain.utils.general.general import merge, get_yaml_loader
from sdsstools import get_config, get_logger, get_package_version

NAME = 'marvin-brain'

# Loads config
curdir = os.path.dirname(os.path.abspath(__file__))
cfg_params = get_config('brain', config_file=os.path.join(curdir, 'data/brain.yml'))

# Inits the logging system. Only shell logging, and exception and warning catching.
# File logging can be started by calling log.start_file_logger(path).
log = get_logger(NAME)

# Set the Brain version
__version__ = '0.1.5dev'
__version__ = get_package_version(path=__file__, package_name=NAME)


class BrainConfig(object):
Expand Down Expand Up @@ -99,17 +108,8 @@ def has_netrc(self):
def _load_defaults(self):
''' Load the Brain config yaml file '''

config = yaml.load(open(os.path.join(os.path.dirname(__file__), 'data/brain.yml')), Loader=get_yaml_loader())
user_config_path = os.path.expanduser('~/.brain/brain.yml')
if os.path.exists(user_config_path):
config = merge(yaml.load(open(user_config_path), Loader=get_yaml_loader()), config)

# update any matching Config values
for key, value in config.items():
if hasattr(self, key):
self.__setattr__(key, value)

self._custom_config = config
#self._custom_config = config
self._custom_config = cfg_params

def _check_paths(self):
''' Check the paths in the custom config '''
Expand Down
9 changes: 5 additions & 4 deletions python/brain/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self, route, params=None, request_type='post', auth='token',
self.statuscodes = {200: 'Ok', 401: 'Authentication Required', 404: 'URL Not Found',
500: 'Internal Server Error', 405: 'Method Not Allowed',
400: 'Bad Request', 502: 'Bad Gateway', 504: 'Gateway Timeout',
422: 'Unprocessable Entity', 429: 'Rate Limit Exceeded'}
422: 'Unprocessable Entity', 429: 'Rate Limit Exceeded',
409: 'Conflict'}
self.compression = self.params['compression'] if self.params and \
'compression' in self.params else bconfig.compression

Expand Down Expand Up @@ -225,10 +226,10 @@ def _checkResponse(self, response):
raise BrainError('Requests Http Status Error: {0}\nValidation Errors:\n{1}'.format(http, json_data))
else:
self._closeRequestSession()
if b'api_error' in json_data:
if str('api_error') in json_data:
apijson = json_data['api_error']
errmsg = '{0}\n{1}'.format(apijson['message'], apijson['traceback']) if 'message' in apijson else '{0}'.format(apijson['traceback'])
elif b'error' in json_data:
errmsg = '{0}'.format(apijson['message']) if 'message' in apijson else '{0}'.format(apijson['traceback'])
elif str('error') in json_data:
err = json_data['error']
errmsg = '{0}'.format(err)
raise BrainError('Requests Http Status Error: {0}\n{1}'.format(http, errmsg))
Expand Down
Loading

0 comments on commit 1ff5d5c

Please sign in to comment.