Skip to content

Commit

Permalink
Created pyproject.toml to create PyPI release.
Browse files Browse the repository at this point in the history
  • Loading branch information
blais committed Jun 16, 2024
1 parent 41576e2 commit 5f0f33b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 12 deletions.
2 changes: 0 additions & 2 deletions beanprice/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,6 @@ def get_price_jobs_up_to_date(entries,
# Look at both latest prices and start dates.
lifetimes_map = lifetimes.get_commodity_lifetimes(entries)
commodity_map = getters.get_commodity_directives(entries)
price_start_dates = {}
stale_currencies = set()

if inactive:
for base_quote in currencies:
Expand Down
2 changes: 1 addition & 1 deletion beanprice/sources/coincap.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_historical_price(self, ticker: str,
time +
datetime.timedelta(days=-1),
time + datetime.timedelta(days=1)):
if not datapoint.time is None and datapoint.time.date() == time.date():
if datapoint.time is not None and datapoint.time.date() == time.date():
return datapoint
return None

Expand Down
4 changes: 2 additions & 2 deletions beanprice/sources/ratesapi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def response(contents, status_code=requests.codes.ok):
class RatesapiPriceFetcher(unittest.TestCase):

def test_error_invalid_ticker(self):
with self.assertRaises(ValueError) as exc:
with self.assertRaises(ValueError):
ratesapi.Source().get_latest_price('INVALID')

def test_error_network(self):
with response('Foobar', 404):
with self.assertRaises(ValueError) as exc:
with self.assertRaises(ValueError):
ratesapi.Source().get_latest_price('EUR-CHF')

def test_valid_response(self):
Expand Down
6 changes: 3 additions & 3 deletions beanprice/sources/tsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
csv.register_dialect('tsp',
delimiter=',',
quoting=csv.QUOTE_NONE,
quotechar='',
# NOTE(blais): This fails to import in 3.12 (and perhaps before).
# quotechar='',
lineterminator='\n')

class TSPError(ValueError):
Expand Down Expand Up @@ -120,7 +121,6 @@ def get_historical_price(self, fund, time):
"\n\t".join(TSP_FUND_NAMES)))

url = "https://secure.tsp.gov/components/CORS/getSharePricesRaw.html"
fields = ['startdate', 'enddate', 'download', 'Lfunds', 'InvFunds']
payload = {
# Grabbing the last fourteen days of data in event the markets were closed.
'startdate' : (time - datetime.timedelta(days=14)).strftime("%Y%m%d"),
Expand All @@ -132,7 +132,7 @@ def get_historical_price(self, fund, time):

response = requests.get(url, params=payload)
result = parse_response(response)
trade_day = list(result.items())[0]
trade_day = next(iter(result.items()))
prices = trade_day[1]

try:
Expand Down
8 changes: 6 additions & 2 deletions beanprice/sources/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ def get_latest_price(self, ticker: str) -> Optional[source.SourcePrice]:
"""See contract in beanprice.source.Source."""

session = requests.Session()
session.headers.update({'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0'})
session.get('https://fc.yahoo.com') # This populates the correct cookies in the session
session.headers.update({
'User-Agent':
'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0'
})
# This populates the correct cookies in the session
session.get('https://fc.yahoo.com')
crumb = session.get('https://query1.finance.yahoo.com/v1/test/getcrumb').text

url = "https://query1.finance.yahoo.com/v7/finance/quote"
Expand Down
4 changes: 2 additions & 2 deletions beanprice/sources/yahoo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_parse_response_no_timestamp(self):
"""))
with self.assertRaises(yahoo.YahooError):
with mock.patch('requests.get', return_value=response):
srcprice = yahoo.Source().get_historical_price(
_ = yahoo.Source().get_historical_price(
'XSP.TO', datetime.datetime(2017, 11, 1, 16, 0, 0, tzinfo=tz.tzutc()))


Expand Down Expand Up @@ -230,7 +230,7 @@ def test_parse_null_prices_in_series(self):

with mock.patch('requests.get', return_value=response):
srcprice = yahoo.Source().get_historical_price(
'XSP.TO', datetime.datetime(2022, 2, 28, 16, 0, 0, tzinfo=tz.tzutc()))
'XSP.TO', datetime.datetime(2022, 2, 28, 16, 0, 0, tzinfo=tz.tzutc()))
self.assertTrue(isinstance(srcprice.price, Decimal))
self.assertEqual(Decimal('9.6899995803833'), srcprice.price)
timezone = datetime.timezone(datetime.timedelta(hours=-5), 'America/New_York')
Expand Down
85 changes: 85 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[build-system]
requires = ['setuptools']
build-backend = 'setuptools.build_meta'

[project]
name = 'beanprice'
version = '1.2.0'
description = 'Price quotes fetcher for Beancount'
license = { file = 'COPYING' }
readme = 'README.md'
authors = [
{ name = 'Martin Blais', email = '[email protected]' },
]
maintainers = [
{ name = 'Martin Blais', email = '[email protected]' },
]
keywords = [
'accounting', 'ledger', 'beancount', 'price'
]
classifiers = [
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: SQL',
'Topic :: Office/Business :: Financial :: Accounting',
]
requires-python = '>= 3.8'
dependencies = [
'beancount >= 2.3.4',
'python-dateutil >= 2.6.0',
'requests >= 2.0',
]

[project.scripts]
bean-query = 'beanprice.price:main'

[project.urls]
homepage = 'https://github.com/beancount/beanprice'
issues = 'https://github.com/beancount/beanprice/issues'

[tool.setuptools.packages]
find = {}

[tool.coverage.run]
branch = true

[tool.coverage.report]
exclude_also = [
'if typing.TYPE_CHECKING:',
]

[tool.ruff]
line-length = 92
target-version = 'py38'

[tool.ruff.lint]
select = ['E', 'F', 'W', 'UP', 'B', 'C4', 'PL', 'RUF']

# TODO(blais): Review these ignores.
ignore = [
'RUF013',
'RUF005',
'PLW0603',
'UP014',
'UP031',
'B007',
'B905',
'C408',
'E731',
'PLR0911',
'PLR0912',
'PLR0913',
'PLR0915',
'PLR1714',
'PLR2004',
'PLW2901',
'RUF012',
'UP007',
'UP032',
]

0 comments on commit 5f0f33b

Please sign in to comment.