Skip to content

Commit d847dd9

Browse files
authored
Fix handling of nested resource files (#308)
1 parent 345b7df commit d847dd9

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
fail-fast: false
4646
matrix:
4747
os: [ubuntu-latest, windows-latest, macos-latest]
48-
python-version: ["3.7", "3.10"]
48+
python-version: ["3.8", "3.10"]
4949
steps:
5050
- name: Checkout
5151
uses: actions/checkout@v2

docs/source/how_to_guides/write_config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ package
9393

9494
```toml
9595
[tool.jupyter-releaser.options]
96-
pydist_resource_paths = ["my-package/img1.png", "my-package/foo.json"]
96+
pydist_resource_paths = ["my-package/img1.png", "my-package/foo/bar.json"]
9797
```

jupyter_releaser/python.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ def check_dist(
8282
)
8383
raise e
8484
for resource_path in resource_paths:
85-
name, _, rest = resource_path.partition("/")
85+
name, _, _ = resource_path.partition("/")
8686
test_file = Path(td) / "test_path.py"
8787
test_text = f"""
88-
import importlib.resources
89-
with importlib.resources.path('{name}','{rest}') as resource_path:
90-
assert resource_path.exists()
88+
from importlib.metadata import PackagePath, files
89+
assert PackagePath('{resource_path}') in files('{name}')
9190
"""
9291
test_file.write_text(test_text, encoding="utf-8")
9392
test_file = util.normalize_path(test_file)
@@ -124,12 +123,12 @@ def get_pypi_token(release_url, python_package):
124123
def start_local_pypi():
125124
"""Start a local PyPI server"""
126125
temp_dir = TemporaryDirectory()
127-
cmd = f"pypi-server -p 8081 -P . -a . -o -v {temp_dir.name}"
128-
proc = Popen(shlex.split(cmd), stderr=PIPE)
126+
cmd = f"pypi-server run -p 8081 -P . -a . -o -v {temp_dir.name}"
127+
proc = Popen(shlex.split(cmd), stdout=PIPE)
129128
# Wait for the server to start
130129
while True:
131-
assert proc.stderr is not None
132-
line = proc.stderr.readline().decode("utf-8").strip()
130+
assert proc.stdout is not None
131+
line = proc.stdout.readline().decode("utf-8").strip()
133132
util.log(line)
134133
if "Listening on" in line:
135134
break

jupyter_releaser/tests/test_cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,21 @@ def test_check_python_different_names(
441441

442442

443443
def test_check_python_resource_path(monkeypatch, py_package, runner, build_mock, git_prep):
444-
monkeypatch.setenv("RH_PYDIST_RESOURCE_PATHS", "foo/baz.txt")
444+
monkeypatch.setenv("RH_PYDIST_RESOURCE_PATHS", "foo/bar/baz.txt")
445445

446446
# Convert the package to use a package dir.
447447
foo_dir = Path(util.CHECKOUT_NAME) / "foo"
448448
foo_dir.mkdir()
449449
shutil.move(Path(util.CHECKOUT_NAME) / "foo.py", foo_dir / "__init__.py")
450450

451-
path = foo_dir / "baz.txt"
451+
bar_dir = foo_dir / "bar"
452+
bar_dir.mkdir()
453+
path = bar_dir / "baz.txt"
452454
path.write_text("hello", encoding="utf-8")
453455

454456
manifest = Path(util.CHECKOUT_NAME) / "MANIFEST.in"
455457
manifest_text = manifest.read_text(encoding="utf-8")
456-
manifest_text += "\ninclude foo/baz.txt\n"
458+
manifest_text += "\ninclude foo/bar/baz.txt\n"
457459
manifest.write_text(manifest_text, encoding="utf-8")
458460

459461
setup_cfg_path = Path(util.CHECKOUT_NAME) / "setup.cfg"

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ include_package_data = True
2727
packages = find:
2828
package_dir =
2929
"" = "jupyter_releaser"
30-
python_requires = >=3.7
30+
python_requires = >=3.8
3131
install_requires =
3232
build
3333
check-manifest

0 commit comments

Comments
 (0)