Skip to content

Commit 476aead

Browse files
committed
fix: Remove copy of s5cmd from source tree and update install rule
Add test_executable based on https://github.com/scikit-build/cmake-python-distributions
1 parent e660cac commit 476aead

File tree

5 files changed

+76
-10
lines changed

5 files changed

+76
-10
lines changed

.github/workflows/cd.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ jobs:
4848

4949
- name: Install dependencies
5050
run: |
51-
pip install pytest pytest-cov
51+
# Waiting pip supports `--only-deps=test`, explicitly extract the test dependencies
52+
# See https://github.com/pypa/pip/issues/11440
53+
pip install yq
54+
tomlq -r '.project."optional-dependencies".test[]' pyproject.toml | xargs -d '\n' pip install
5255
5356
- uses: actions/download-artifact@v4
5457
with:

CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,10 @@ file(ARCHIVE_EXTRACT
6464
VERBOSE
6565
)
6666

67-
set(s5cmd_package "src/s5cmd")
68-
69-
message(STATUS "Copying ${executable_name} to ${s5cmd_package}")
70-
file(COPY ${extract_dir}/${executable_name} DESTINATION ${PROJECT_SOURCE_DIR}/${s5cmd_package})
71-
7267
set(_permissions PERMISSIONS
7368
OWNER_READ OWNER_WRITE OWNER_EXECUTE
7469
GROUP_READ GROUP_EXECUTE
7570
WORLD_READ WORLD_EXECUTE
7671
)
7772

78-
message(STATUS "Changing ${executable_name} permissions to be executable")
79-
file(CHMOD ${PROJECT_SOURCE_DIR}/${s5cmd_package}/${executable_name} ${_permissions})
80-
81-
install(PROGRAMS ${extract_dir}/${executable_name} DESTINATION "${s5cmd_package}" ${_permissions})
73+
install(PROGRAMS ${extract_dir}/${executable_name} DESTINATION "s5cmd" ${_permissions})

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dependencies = []
3434

3535
[project.optional-dependencies]
3636
test = [
37+
"importlib_metadata>=2.0; python_version<'3.10'",
3738
"pytest >=6",
3839
"pytest-cov >=3",
3940
]
@@ -113,6 +114,9 @@ module = "s5cmd.*"
113114
disallow_untyped_defs = true
114115
disallow_incomplete_defs = true
115116

117+
[[tool.mypy.overrides]]
118+
module = "tests.*"
119+
ignore_errors = true
116120

117121
[tool.ruff]
118122
src = ["src"]

tests/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from contextlib import contextmanager
5+
6+
7+
@contextmanager
8+
def push_argv(argv):
9+
old_argv = sys.argv
10+
sys.argv = argv
11+
yield
12+
sys.argv = old_argv

tests/test_executable.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from __future__ import annotations
2+
3+
import subprocess
4+
import sys
5+
import sysconfig
6+
from pathlib import Path
7+
8+
import pytest
9+
10+
if sys.version_info < (3, 10):
11+
from importlib_metadata import distribution
12+
else:
13+
from importlib.metadata import distribution
14+
15+
import s5cmd
16+
17+
from . import push_argv
18+
19+
all_tools = pytest.mark.parametrize("tool", ["s5cmd"])
20+
21+
22+
def _run(program, args):
23+
func = getattr(s5cmd, program)
24+
args = [f"{program}.py", *args]
25+
with push_argv(args), pytest.raises(SystemExit) as excinfo:
26+
func()
27+
assert excinfo.value.code == 0
28+
29+
30+
@all_tools
31+
def test_module(tool):
32+
_run(tool, ["version"])
33+
34+
35+
def _get_scripts():
36+
dist = distribution("s5cmd")
37+
scripts_paths = [
38+
Path(sysconfig.get_path("scripts", scheme)).resolve()
39+
for scheme in sysconfig.get_scheme_names()
40+
]
41+
scripts = []
42+
for file in dist.files:
43+
if file.locate().parent.resolve(strict=True) in scripts_paths:
44+
scripts.append(file.locate().resolve(strict=True))
45+
return scripts
46+
47+
48+
@all_tools
49+
def test_package_script(tool):
50+
expected_version = "2.2.2"
51+
scripts = [script for script in _get_scripts() if script.stem == tool]
52+
assert len(scripts) == 1
53+
output = subprocess.check_output([str(scripts[0]), "version"]).decode("ascii")
54+
# Output of the form "vX.Y.Z-SHA{N}"
55+
assert output.splitlines()[0].split("-")[0] == f"v{expected_version}"

0 commit comments

Comments
 (0)