Skip to content

Commit

Permalink
Performance boostWe now use json instead of yaml.
Browse files Browse the repository at this point in the history
  • Loading branch information
SlashGordon committed Aug 8, 2019
1 parent ba17b3a commit fa335bc
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PYTHONPATH=src
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ report.xml
build/*
.pytest_cache/*
.vscode/*
src/pytickersymbols/data/stocks.json
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ wheel==0.33.4
pytest
pytest-cov
pandas==0.24.2
yfinance==0.1.44
yfinance==0.1.44
PyYAML==5.1.1
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file.
"""

from setuptools import setup, find_packages

EXCLUDE_FROM_PACKAGES = ['test', 'test.*', 'test*']
VERSION = '1.1.3'
VERSION = '1.1.4'

with open("README.md", "r") as fh:
long_description = fh.read()

INSTALL_REQUIRES = (
['PyYAML==5.1.1', 'wheel==0.33.4']
['wheel==0.33.4']
)

setup(
Expand All @@ -32,7 +31,7 @@
url="https://github.com/portfolioplus/pytickersymbols",
packages=find_packages('src', exclude=EXCLUDE_FROM_PACKAGES),
install_requires=INSTALL_REQUIRES,
package_data={'': ['data/*.yaml']},
package_data={'': ['data/*.json']},
include_package_data=True,
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down
10 changes: 5 additions & 5 deletions src/pytickersymbols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
can be found in the LICENSE file.
"""
import os
import yaml
import json


class PyTickerSymbols:

def __init__(self):
self.__stocks = None
yaml_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data", "stocks.yaml"
json_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data", "stocks.json"
)
with open(yaml_path) as stocks:
self.__stocks = yaml.safe_load(stocks)
with open(json_path) as stocks:
self.__stocks = json.load(stocks)

def get_all_indices(self):
"""
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ envlist = py36,
[testenv]
setenv =
PYTHONPATH = {toxinidir}/src
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-dev.txt
deps = -r{toxinidir}/requirements-dev.txt

basepython =
py36: python3.6
commands =
python yaml2json.py
pytest tests/ --cov src/pytickersymbols --cov-report term-missing
python setup.py bdist_wheel

Expand Down
15 changes: 15 additions & 0 deletions yaml2json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import yaml
import json
import os

# convert yaml file to json
input_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'stocks.yaml')
output_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'src', 'pytickersymbols', 'data', 'stocks.json')

os.makedirs(os.path.dirname(os.path.realpath(output_path)))

with open(output_path, 'w') as out_file:
with open(input_path, 'r') as in_file:
out_file.write(json.dumps(yaml.safe_load(in_file)))

0 comments on commit fa335bc

Please sign in to comment.