Skip to content

Commit

Permalink
Merge branch 'feature/fix-dependencies' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sdementen committed Oct 24, 2020
2 parents e3612ce + dcfadf1 commit 246bfc4
Show file tree
Hide file tree
Showing 7 changed files with 902 additions and 448 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,13 @@
What's new
==========

Version 1.1.2 (2020-10-24)
~~~~~~~~~~~~~~~~~~~~~~~~~~

- import requests from functions using it to avoid making it a required dependency (fix #90)
- adapt setup.py to avoid depending on SQLAlchemy-Utils 0.36.8 (fix #91)
- updated gnucash projects page: https://piecash.readthedocs.io/en/latest/doc/github_links.html


Version 1.1.1 (2020-10-21)
~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/source/doc/doc.rst
Expand Up @@ -56,7 +56,7 @@ or to upgrade if piecash is already installed::

piecash comes with 6 extra options (each option depends on extra packages that will be installed only if the option is chosen):
- pandas: install also pandas to use :meth:`piecash.core.book.Book.splits_df` and :meth:`piecash.core.book.Book.prices_df`
- finance-quote: to retrieve quotes/prices
- yahoo: to retrieve quotes/prices
- postgres: to support connecting to a book saved on a postgresql database
- mysql: to support connecting to a book saved on a mysql database
- qif: to support export to QIF
Expand Down
1,204 changes: 816 additions & 388 deletions docs/source/doc/github_links.rst

Large diffs are not rendered by default.

121 changes: 67 additions & 54 deletions github_gnucash_projects.py
@@ -1,40 +1,30 @@
from getpass import getpass
import json
import datetime
import os

import requests
import requests_cache
from github import Github

client_id = "sdementen"

if __name__ == '__main__':
requests_cache.install_cache()
if __name__ == "__main__":
languages = {}
client_secret = input("Enter password for user '{}' :".format(client_id))
i = 0
for pg in range(100):
print(pg)
url = "https://api.github.com/search/repositories?q=gnucash&sort=stars&order=desc&page={}&per_page=100?client_id={}&client_secret={}".format(
pg + 1, client_id, client_secret)
response = requests.get(url)
response.raise_for_status()
res = json.loads(response.text)
try:
projects = res["items"]
except KeyError:
break
if not res["items"]:
break

for project in projects:
if (project["name"].lower() == "gnucash") or ("mirror" in (project["description"] or "").lower()):
continue
i += 1
languages.setdefault(project["language"], []).append(project)
try:
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
except KeyError:
raise ValueError(
"You should have a valid Github token in your GITHUB_TOKEN environment variable"
)

g = Github(GITHUB_TOKEN)
for project in g.search_repositories(query="gnucash", sort="stars", order="desc"):
print(project)
if (project.name.lower() == "gnucash") or ("mirror" in (project.description or "").lower()):
continue
languages.setdefault(project.language, []).append(project)

with open("docs/source/doc/github_links.rst", "w", encoding="UTF-8") as fo:
list_of_projects = sorted([(k or "", v) for k, v in languages.items()],
key=lambda v: ("AAA" if v[0] == "Python" else v[0] or "zzz"))
list_of_projects = sorted(
[(k or "", v) for k, v in languages.items()],
key=lambda v: ("AAA" if v[0] == "Python" else v[0] or "zzz"),
)

width = 50
sep_row = "+" + "-" * width
Expand All @@ -44,25 +34,41 @@
print("Projects per language", file=fo)
print("=====================", file=fo)
print(file=fo)
print("This page lists all projects found by searching 'gnucash' on github (generated on {}) "
"excluding mirrors of the gnucash repository. Projects with a '\*' are projects"
"that have not been updated since 12 months.".format(datetime.datetime.today().replace(microsecond=0)),
file=fo)
print(
"This page lists all projects found by searching 'gnucash' on github (generated on {}) "
"excluding mirrors of the gnucash repository. Projects with a '\*' are projects"
"that have not been updated since 12 months.".format(
datetime.datetime.today().replace(microsecond=0)
),
file=fo,
)
print(file=fo)
print(sep_row + sep_row + sep_row + "+", file=fo)
print("|{:^50}|{:^50}|{:^50}|".format("Language", "# of projects", "# of projects updated in last 12 months"),
file=fo)
print(
"|{:^50}|{:^50}|{:^50}|".format(
"Language", "# of projects", "# of projects updated in last 12 months"
),
file=fo,
)
print(head_row + head_row + head_row + "+", file=fo)

last12month = datetime.datetime.today() - datetime.timedelta(days=365)
list_of_projects = [(lang or "Unknown",
projects,
{pr["html_url"] for pr in projects if pr["updated_at"] >= last12month.strftime("%Y-%m-%d")})
for (lang, projects) in list_of_projects]
list_of_projects = [
(
lang or "Unknown",
projects,
{pr.html_url for pr in projects if pr.updated_at >= last12month},
)
for (lang, projects) in list_of_projects
]

for lang, projects, recent_projects in sorted(list_of_projects, key=lambda k:-len(k[2])):
print("|{:^50}|{:^50}|{:^50}|".format(":ref:`{}`".format(lang), len(projects),
len(recent_projects)), file=fo)
for lang, projects, recent_projects in sorted(list_of_projects, key=lambda k: -len(k[2])):
print(
"|{:^50}|{:^50}|{:^50}|".format(
":ref:`{}`".format(lang), len(projects), len(recent_projects)
),
file=fo,
)
print(sep_row + sep_row + sep_row + "+", file=fo)

print(file=fo)
Expand All @@ -74,15 +80,22 @@
print(lang or "Unknown", file=fo)
print("-" * len(lang or "Unknown"), file=fo)
print(file=fo)
for project in sorted(projects, key=lambda pr: pr["name"].lower()):
updated_at = project["updated_at"][:10]
user = project["owner"]["login"]
description = project["description"] or "(No description available)"
name = project["name"]
html_url = project["html_url"]
print("{}`{name} <{html_url}>`__ by {user} (last updated on {updated_at:<10})\n"
"\t{description}".format("" if project["html_url"] in recent_projects else "\* ",
user=user, updated_at=updated_at, description=description,
name=name, html_url=html_url),
file=fo)
for project in sorted(projects, key=lambda pr: pr.name.lower()):
updated_at = project.updated_at
user = project.owner.login
description = project.description or "(No description available)"
name = project.name
html_url = project.html_url
print(
"{}`{name} <{html_url}>`__ by {user} (last updated on {updated_at:<10})\n"
"\t{description}".format(
"" if project.html_url in recent_projects else "\* ",
user=user,
updated_at=updated_at,
description=description,
name=name,
html_url=html_url,
),
file=fo,
)
print(file=fo)
2 changes: 1 addition & 1 deletion piecash/metadata.py
Expand Up @@ -8,7 +8,7 @@
package = 'piecash'
project = "Python interface to GnuCash documents"
project_no_spaces = project.replace(' ', '')
version = '1.1.1'
version = '1.1.2'
description = 'A pythonic interface to GnuCash SQL documents.'
authors = ['sdementen']
authors_string = ', '.join(authors)
Expand Down
8 changes: 7 additions & 1 deletion piecash/yahoo_client.py
Expand Up @@ -12,7 +12,7 @@
from time import sleep

import pytz
import requests


MAX_ATTEMPT = 5

Expand All @@ -23,6 +23,8 @@


def get_latest_quote(symbol):
import requests

resp = requests.get("{}/quote".format(YAHOO_BASE_URL), params={"symbols": symbol})
resp.raise_for_status()

Expand Down Expand Up @@ -52,6 +54,8 @@ def get_latest_quote(symbol):


def get_crumble_and_cookie(symbol):
import requests

link = crumble_link.format(symbol)
response = requests.get(link)
cookie_str = response.headers["set-cookie"]
Expand All @@ -62,6 +66,8 @@ def get_crumble_and_cookie(symbol):


def download_quote(symbol, date_from, date_to, tz=None):
import requests

def normalize(d):
if isinstance(d, datetime.datetime):
pass
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Expand Up @@ -199,20 +199,20 @@ def _lint():


## package dependencies
install_requires = ["SQLAlchemy>=1.0", "SQLAlchemy-Utils>=0.31", "pytz", "tzlocal", "click"]
install_requires = ["SQLAlchemy>=1.0", "SQLAlchemy-Utils!=0.36.8", "pytz", "tzlocal", "click"]
extras_require = {
"postgres": ["psycopg2"],
"mysql": ["PyMySQL"],
"ledger": ["money", "babel"],
"pandas": ["pandas"],
"qif": ["qifparse"],
"finance-quote": ["requests"],
"yahoo": ["requests"],
"test": ["pytest", "pytest-cov", "tox"],
"doc": ["sphinx", "sphinxcontrib-napoleon", "sphinxcontrib-programoutput", "sphinx-rtd-theme", "ipython"],
}
# build an 'all' option covering all options
extras_require["all"] = deps_all = sum(
(extras_require[k] for k in ["postgres", "mysql", "pandas", "finance-quote", "ledger"]), []
(extras_require[k] for k in ["postgres", "mysql", "pandas", "yahoo", "ledger"]), []
)
# add 'all' for both doc and test
extras_require["test"].extend(deps_all)
Expand Down

0 comments on commit 246bfc4

Please sign in to comment.