Skip to content

Commit b2a0fa9

Browse files
authored
Add ci pytest (#2)
* CI: add mac test * 1 * just test * test * test * test * CI: widows test * test temp add rclone * win fix * mac linux permissions * test * 2 * 3 * 4 * 5 * 6 * 7 * 8 * finish all ci test
1 parent 1dc861f commit b2a0fa9

6 files changed

Lines changed: 91 additions & 10 deletions

File tree

.github/workflows/_linux_test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ jobs:
1313
uses: actions/setup-python@v3
1414
with:
1515
python-version: '3.10'
16+
- name: package install
17+
run: |
18+
mv linux/rclone pyrclone/rclone
1619
- name: Install dependencies
1720
run: |
1821
pip install . -v
1922
pip install pytest
2023
- name: Update permissions
2124
run: |
22-
sudo chmod 755 /opt/hostedtoolcache/Python/3.10.12/x64/pyrclone/rclone
25+
sudo chmod 755 /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/pyrclone/rclone
2326
- name: Test with pytest
2427
run: |
2528
make test

.github/workflows/_mac_test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: mac-test
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
pytest:
9+
runs-on: macos-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python 3.10
13+
uses: actions/setup-python@v3
14+
with:
15+
python-version: '3.10'
16+
- name: package install
17+
run: |
18+
mv mac/rclone pyrclone/rclone
19+
- name: Install dependencies
20+
run: |
21+
pip install . -v
22+
pip install pytest
23+
- name: Update permissions
24+
run: |
25+
sudo chmod 755 /Users/runner/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/pyrclone/rclone
26+
- name: Test with pytest
27+
run: |
28+
make test

.github/workflows/_win_test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: windows-test
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
pytest:
9+
runs-on: windows-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python 3.10
13+
uses: actions/setup-python@v3
14+
with:
15+
python-version: '3.10'
16+
- name: package install
17+
run: |
18+
move ./win/rclone.exe ./pyrclone/rclone.exe
19+
- name: Install dependencies
20+
run: |
21+
pip install . -v
22+
pip install pytest
23+
- name: Test with pytest
24+
run: |
25+
make test

pyrclone/rclone_wrapper.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
import os
44
import sys
55

6+
import pkg_resources
7+
68

79
class RCloneWrapper:
810
"""
911
Wrapper class for rclone.
1012
"""
13+
1114
def __init__(self, cfg):
1215
self.cfg = '\n'.join(f'[{name}]\n' + '\n'.join(f'{k} = {v}' for k,
1316
v in settings.items()) for name, settings in cfg.items())
1417
self.log = logging.getLogger("RClone")
15-
wrapper_dir = os.path.dirname(os.path.realpath(__file__))
16-
self.config_path = os.path.join(wrapper_dir, "rclone.conf")
17-
self.rclone_path = os.path.join(sys.prefix, "pyrclone", "rclone")
18+
19+
self.config_path = pkg_resources.resource_filename(
20+
"pyrclone", "rclone.conf")
21+
self.rclone_path = pkg_resources.resource_filename(
22+
"pyrclone", "rclone")
1823

1924
def _execute(self, command_with_args):
2025
# print(command_with_args)
@@ -115,4 +120,3 @@ def lsjson(self, dest, flags=[]):
115120

116121
def delete(self, dest, flags=[]):
117122
return self.run_cmd(command="delete", extra_args=[dest] + flags)
118-

setup.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,31 @@
22
import os
33

44

5+
# PROJECT_NAME = 'pyrclone'
6+
# if os.name == 'nt': # Windows
7+
# rclone_binary = (f'{PROJECT_NAME}', ['win/rclone.exe'])
8+
# elif os.name == 'posix': # Unix-like
9+
# if os.uname().sysname == 'Linux':
10+
# rclone_binary = (f'{PROJECT_NAME}', ['linux/rclone'])
11+
# elif os.uname().sysname == 'Darwin':
12+
# rclone_binary = (f'{PROJECT_NAME}', ['mac/rclone'])
13+
# else:
14+
# raise NotImplementedError('Unsupported OS')
15+
16+
517
PROJECT_NAME = 'pyrclone'
618
if os.name == 'nt': # Windows
7-
rclone_binary = (f'{PROJECT_NAME}', ['win/rclone.exe'])
19+
rclone_binary = ['rclone.exe']
820
elif os.name == 'posix': # Unix-like
921
if os.uname().sysname == 'Linux':
10-
rclone_binary = (f'{PROJECT_NAME}', ['linux/rclone'])
22+
rclone_binary = ['rclone']
1123
elif os.uname().sysname == 'Darwin':
12-
rclone_binary = (f'{PROJECT_NAME}', ['mac/rclone'])
24+
rclone_binary = ['rclone']
1325
else:
1426
raise NotImplementedError('Unsupported OS')
1527

1628
setuptools.setup(
17-
name="PyRCloneTest",
29+
name="pyrclone",
1830
version="0.0.1",
1931
author="Yuangang Li",
2032
author_email="yuangangli@outlook.com",
@@ -23,7 +35,11 @@
2335
long_description_content_type="text/markdown",
2436
url="https://github.com/MrLYG/python-rclone.git",
2537
packages=setuptools.find_packages(),
26-
data_files=[(rclone_binary)],
38+
include_package_data=True,
39+
package_data={
40+
# If any package contains *.bin files, include them:
41+
'pyrclone': rclone_binary,
42+
},
2743
classifiers=[
2844
"Programming Language :: Python :: 3",
2945
"License :: OSI Approved :: MIT License",

tests/wrapper_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
import logging
66
import json
7+
8+
import pkg_resources
79
from pyrclone.rclone_wrapper import RCloneWrapper
810
import shutil
911

@@ -107,6 +109,9 @@ def test_rclone_sync(tmp_path: Path):
107109

108110

109111
if __name__ == "__main__":
112+
data_path = pkg_resources.resource_filename('pyrclone', '*/rlcone.exe')
113+
print(data_path)
114+
print(data_path)
110115
tmp_path = Path("C:\\tmp\\rclone_test")
111116
# test rclone sync on local
112117
shutil.rmtree(tmp_path, ignore_errors=True)

0 commit comments

Comments
 (0)