Skip to content

Commit f9391b5

Browse files
authored
Merge pull request #102 from machow/ci-py-versions-tests
ci: test across py 3.7 to 3.10
2 parents 7caec2a + 32bc80c commit f9391b5

File tree

6 files changed

+54
-32
lines changed

6 files changed

+54
-32
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18+
python: ["3.7", "3.8", "3.9", "3.10"]
19+
os: ["ubuntu-latest"]
20+
pytest_ops: [""]
1821
include:
1922
- os: "macos-latest"
23+
python: "3.10"
2024
# ignore doctests, as they involve calls to github, and all mac machines
2125
# use the same IP address
2226
pytest_opts: "-k pins/tests"
23-
- os: "ubuntu-latest"
24-
pytest_opts:
2527
steps:
2628
- uses: actions/checkout@v2
2729
- uses: actions/setup-python@v2
2830
with:
29-
python-version: 3.8
31+
python-version: ${{ matrix.python }}
3032
- name: Install dependencies
3133
run: |
3234
python -m pip install --upgrade pip
33-
python -m pip install -r requirements/dev.txt
34-
python -m pip install -e .
35+
python -m pip install -e .[test]
3536
- name: Run tests
3637
run: |
3738
pytest pins -m 'not fs_rsc and not skip_on_github' $PYTEST_OPTS

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ docs-clean:
3232
requirements/dev.txt: setup.cfg
3333
@# allows you to do this...
3434
@# make requirements | tee > requirements/some_file.txt
35-
@pip-compile setup.cfg --rebuild --extra dev --output-file=- > $@
35+
@pip-compile setup.cfg --rebuild --extra doc --extra test --output-file=- > $@
3636

37-
binder/requirements.txt: setup.cfg
38-
@pip-compile setup.cfg --rebuild --extra dev --output-file=- > $@
37+
binder/requirements.txt: requirements/dev.txt
38+
cp $< $@

pins/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# flake8: noqa
22

33
# Set version ----
4-
from importlib.metadata import version as _v
4+
from importlib_metadata import version as _v
55

66
__version__ = _v("pins")
77

pins/boards.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
import re
66

77
from io import IOBase
8-
from functools import cached_property
98
from pathlib import Path
109
from importlib_resources import files
1110
from datetime import datetime, timedelta
1211

13-
from typing import Protocol, Sequence, Optional, Mapping
12+
from typing import Sequence, Optional, Mapping
1413

1514
from .versions import VersionRaw, guess_version
1615
from .meta import Meta, MetaRaw, MetaFactory
1716
from .errors import PinsError
1817
from .drivers import load_data, save_data, default_title
1918

2019

21-
class IFileSystem(Protocol):
20+
# Note that once we drop python 3.7, we can make this a Protocol
21+
class IFileSystem:
2222
def ls(self, path: str) -> Sequence[str]:
2323
...
2424

@@ -797,10 +797,18 @@ def path_to_deploy_version(self, name: str, version: str):
797797
# to fs.put to the <user>/<content_name>.
798798
return self.path_to_pin(name)
799799

800-
@cached_property
800+
@property
801801
def user_name(self):
802-
user = self.fs.api.get_user()
803-
return user["username"]
802+
# note that this is essentially the manual version of functools.cached_property
803+
# since we support python 3.7
804+
name = getattr(self, "_user_name", None)
805+
if name is not None:
806+
return name
807+
else:
808+
user = self.fs.api.get_user()
809+
self._user_name = user["username"]
810+
811+
return self._user_name
804812

805813
def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwargs):
806814

@@ -824,7 +832,8 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
824832
)
825833

826834
# recursively copy all assets into prepped pin version dir
827-
shutil.copytree(self.html_assets_dir, pin_dir_path, dirs_exist_ok=True)
835+
# shutil.copytree(self.html_assets_dir, pin_dir_path, dirs_exist_ok=True)
836+
_copytree(self.html_assets_dir, pin_dir_path)
828837

829838
# render index.html ------------------------------------------------
830839

@@ -870,3 +879,17 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
870879
(Path(pin_dir_path) / "index.html").write_text(rendered)
871880

872881
return meta
882+
883+
884+
# TODO: replace with shutil.copytree once py3.7 is dropped
885+
# copied from https://stackoverflow.com/a/12514470/1144523
886+
def _copytree(src, dst, symlinks=False, ignore=None):
887+
import os
888+
889+
for item in os.listdir(src):
890+
s = os.path.join(src, item)
891+
d = os.path.join(dst, item)
892+
if os.path.isdir(s):
893+
shutil.copytree(s, d, symlinks, ignore)
894+
else:
895+
shutil.copy2(s, d)

pins/tests/test_cache.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
import shutil
32

43
import pytest
54
from pins.cache import (
@@ -72,7 +71,7 @@ def test_pins_cache_open():
7271

7372
@pytest.fixture
7473
def a_cache(tmp_dir2):
75-
return tmp_dir2
74+
return tmp_dir2 / "board_cache"
7675

7776

7877
def create_metadata(p, access_time):
@@ -141,12 +140,10 @@ def test_cache_pruner_old_versions_multi_pins(a_cache, pin1_v2, pin2_v3):
141140
assert set(old) == {pin1_v2, pin2_v3}
142141

143142

144-
def test_cache_prune_prompt(tmp_dir2, a_cache, pin1_v1, pin2_v3, monkeypatch):
145-
p_board = tmp_dir2 / "a_board"
146-
shutil.copytree(a_cache, p_board)
147-
cache_prune(days=1, cache_root=tmp_dir2, prompt=False)
143+
def test_cache_prune_prompt(a_cache, pin1_v1, pin2_v3, monkeypatch):
144+
cache_prune(days=1, cache_root=a_cache.parent, prompt=False)
148145

149-
versions = list(p_board.glob("*/*"))
146+
versions = list(a_cache.glob("*/*"))
150147

151148
# pin2_v3 deleted
152149
assert len(versions) == 1

setup.cfg

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ author_email = [email protected]
1010
license = MIT
1111
keywords = data, tidyverse
1212
classifiers =
13+
Programming Language :: Python :: 3.7
1314
Programming Language :: Python :: 3.8
1415
Programming Language :: Python :: 3.9
1516
Programming Language :: Python :: 3.10
@@ -20,17 +21,17 @@ packages = find:
2021
include_package_data = True
2122
zipsafe = False
2223

23-
python_requires = >3.8
24+
python_requires = >=3.7
2425
install_requires =
2526
fsspec
2627
pyyaml
2728
xxhash
2829
pandas
2930
jinja2
3031
joblib
32+
importlib-metadata
3133
importlib-resources
3234
appdirs
33-
siuba
3435
humanize
3536

3637

@@ -40,18 +41,18 @@ aws =
4041
azure =
4142
adlfs
4243

43-
dev =
44+
doc =
45+
sphinx
46+
jupytext
47+
jupyter-book
48+
49+
test =
4450
pip-tools
45-
pydata-sphinx-theme
4651
pytest
4752
pytest-cases
4853
pytest-dotenv
49-
sphinx
5054
s3fs
51-
jupytext
52-
jupyter-book
53-
nbsphinx
54-
ipykernel
55+
adlfs
5556

5657

5758
[bdist_wheel]

0 commit comments

Comments
 (0)