Skip to content

Commit d5e3fb3

Browse files
authored
Merge pull request #135 from oslokommune/alignment
Align project files with our other packages
2 parents d9b42af + 5a9eeb4 commit d5e3fb3

File tree

8 files changed

+82
-51
lines changed

8 files changed

+82
-51
lines changed

.gitignore

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
.venv/
2-
.tox/
3-
*.egg
4-
*.egg-info
1+
.build_venv/
2+
.tox
3+
.venv
4+
*egg*
55
*.pyc
6-
*__pycache__*
6+
77
.idea/
88

9-
# Distribution
109
build/
11-
develop-eggs/
1210
dist/
13-
downloads/
14-
eggs/
15-
.eggs/
16-
lib/
17-
lib64/
18-
parts/
19-
sdist/
20-
var/
21-
wheels/
22-
pip-wheel-metadata/
23-
share/python-wheels/
24-
.installed.cfg
25-
MANIFEST
11+
*egg-info/
12+
__pycache__*

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## ?.?.? - Unreleased
2+
3+
* Fixed credentials cache handling.
4+
15
## 3.3.0 - 2025-06-20
26

37
* Added support for Python 3.13.

Makefile

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,55 @@
1-
.PHONY: all
2-
all: clean test bump-patch build publish-module
1+
GLOBAL_PY := python3
2+
BUILD_VENV ?= .build_venv
3+
BUILD_PY := $(BUILD_VENV)/bin/python
34

45
.PHONY: init
5-
init:
6-
python3 -m pip install tox black pip-tools wheel twine bumpversion
7-
python3 -m piptools compile
8-
python3 -m pip install -rrequirements.txt
6+
init: $(BUILD_VENV)
7+
8+
$(BUILD_VENV):
9+
$(GLOBAL_PY) -m venv $(BUILD_VENV)
10+
$(BUILD_PY) -m pip install -U pip
11+
12+
###
13+
# Development
14+
##
915

1016
.PHONY: format
11-
format:
12-
python3 -m black .
17+
format: $(BUILD_VENV)/bin/black
18+
$(BUILD_PY) -m black .
1319

1420
.PHONY: test
15-
test:
16-
python3 -m tox -p auto
21+
test: $(BUILD_VENV)/bin/tox
22+
$(BUILD_PY) -m tox -p auto -o
23+
24+
.PHONY: upgrade-deps
25+
upgrade-deps: $(BUILD_VENV)/bin/pip-compile
26+
$(BUILD_VENV)/bin/pip-compile -U
27+
28+
###
29+
# Releases
30+
##
31+
32+
.PHONY: bump-version-patch
33+
bump-version-patch: $(BUILD_VENV)/bin/bump2version is-git-clean
34+
$(BUILD_VENV)/bin/bump2version patch
35+
36+
.PHONY: bump-version-minor
37+
bump-version-minor: $(BUILD_VENV)/bin/bump2version is-git-clean
38+
$(BUILD_VENV)/bin/bump2version minor
39+
40+
.PHONY: bump-version-major
41+
bump-version-major: $(BUILD_VENV)/bin/bump2version is-git-clean
42+
$(BUILD_VENV)/bin/bump2version major
43+
44+
.PHONY: build
45+
build: $(BUILD_VENV)/bin/setuptools $(BUILD_VENV)/bin/twine $(BUILD_VENV)/bin/wheel is-git-clean format test
46+
$(BUILD_PY) setup.py sdist bdist_wheel
47+
48+
.PHONY: publish
49+
publish: $(BUILD_VENV)/bin/twine
50+
username=$$(op read op://Dataspeilet/pypi-upload-token/username) &&\
51+
password=$$(op read op://Dataspeilet/pypi-upload-token/credential) &&\
52+
$(BUILD_PY) -m twine upload -u $$username -p $$password dist/*
1753

1854
.PHONY: is-git-clean
1955
is-git-clean:
@@ -31,16 +67,12 @@ clean:
3167
rm -rf *.egg-info
3268
rm -rf .tox
3369

34-
.PHONY: bump-patch
35-
bump-patch: is-git-clean
36-
bumpversion patch
70+
###
71+
# Python build dependencies
72+
##
3773

38-
.PHONY: build
39-
build:
40-
python3 setup.py sdist bdist_wheel
74+
$(BUILD_VENV)/bin/pip-compile: $(BUILD_VENV)
75+
$(BUILD_PY) -m pip install -U pip-tools
4176

42-
.PHONY: publish-module
43-
publish-module:
44-
username=$$(op read op://Dataspeilet/pypi-upload-token/username) &&\
45-
password=$$(op read op://Dataspeilet/pypi-upload-token/credential) &&\
46-
python -m twine upload -u $$username -p $$password dist/*
77+
$(BUILD_VENV)/bin/%: $(BUILD_VENV)
78+
$(BUILD_PY) -m pip install -U $*

okdata/sdk/auth/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def refresh_access_token(self):
9393
try:
9494
tokens = self.token_provider.refresh_token(self._refresh_token)
9595
except TokenRefreshError as e:
96-
log.warn(f"Error refreshing token: {e}")
96+
log.warning(f"Error refreshing token: {e}")
9797

9898
if not tokens:
9999
tokens = self.token_provider.new_token()
@@ -109,7 +109,7 @@ def refresh_access_token(self):
109109
)
110110

111111
self._access_token = tokens["access_token"]
112-
self.file_cache.write_credentials(credentials=self)
112+
self.file_cache.write_credentials(credentials=str(self))
113113

114114
def __repr__(self):
115115
return json.dumps(

okdata/sdk/file_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def __init__(self, config):
1111
self.credentials_cache_enabled = config.get("cacheCredentials")
1212
self.env = config.get("env")
1313

14-
def write_credentials(self, credentials):
14+
def write_credentials(self, credentials: str):
1515
if self.credentials_cache_enabled:
1616
filename = f"client_credentials-{self.env}.json"
1717
log.debug(f"Writing credentials to cache: {filename}")
18-
write_to_okdata_cache(content=str(credentials), filename=filename)
18+
write_to_okdata_cache(content=credentials, filename=filename)
1919
else:
2020
log.debug("Skipping write_credentials: cache is not enabled")
2121

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
[tool.black]
2-
target-version = ["py39", "py310", "py311", "py312"]
2+
target-version = ["py39", "py310", "py311", "py312", "py313"]
33
# Keep exclude in sync with flake8 config in tox.ini
44
exclude = '''
55
/(
66
\.git
77
| \.tox
88
| node_modules
99
| __pycache__
10+
| libs
11+
| \*\.pyc
12+
| \.cache
1013
| \.eggs
1114
| .*\.egg
1215
| .*\.egg-info
1316
| env
1417
| venv
15-
| \.venv
18+
| \..*venv
1619
| \.serverless
1720
)/
1821
'''

tests/file_cache_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
from okdata.sdk.file_cache import FileCache
24
from okdata.sdk.config import Config
35

@@ -8,14 +10,14 @@ def test_write_client_credentials():
810
fc = FileCache(config)
911
fc.credentials_cache_enabled = True
1012
cc = {"access_token": "yo", "refresh_token": "bro"}
11-
fc.write_credentials(cc)
12-
assert cc.__eq__(fc.read_credentials())
13+
fc.write_credentials(json.dumps(cc))
14+
assert cc == fc.read_credentials()
1315

1416

1517
def test_disable_cache():
1618
fc = FileCache(config)
1719
fc.credentials_cache_enabled = False
1820
cc = {"access_token": "yo-bro", "refresh_token": "zup-dawg"}
19-
fc.write_credentials(cc)
21+
fc.write_credentials(json.dumps(cc))
2022

2123
assert fc.read_credentials() is None

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ exclude =
5151
.tox,
5252
node_modules,
5353
__pycache__,
54+
libs,
55+
*.pyc,
56+
.cache,
5457
.eggs,
5558
*.egg,
5659
*.egg-info,
5760
env,
5861
venv,
59-
.venv,
62+
.*venv,
6063
.serverless

0 commit comments

Comments
 (0)