Skip to content

Commit e4779f7

Browse files
authored
Support for unpfs (rust-9p) server and 9P2000.L (#3)
* Initial 9P2000.L support * Implement info() for 9P2000.L * Implement rmdir for 9P2000.L * Implement ls for 9P2000.L * Implement read for 9P2000.L * Implement write for 9P2000.L * Test for unpfs * Checkout rust-9p in test workflow * Add ls to investigate directory structure * Add ls to investigate directory structure * Build unpfs * Install unpfs to ~/.local/bin * Install unpfs to ~/.local/bin * Release 0.0.2
1 parent 518da1c commit e4779f7

File tree

10 files changed

+506
-93
lines changed

10 files changed

+506
-93
lines changed

.github/workflows/test.yaml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Test
22

3-
on: [pull_request]
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
48

59
jobs:
610
run-tests:
@@ -15,8 +19,21 @@ jobs:
1519
- "3.11"
1620
fail-fast: false
1721
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v3
22+
- name: Checkout p9fs
23+
uses: actions/checkout@v4
24+
25+
- name: Checkout rust-9p
26+
uses: actions/checkout@v4
27+
with:
28+
repository: pfpacket/rust-9p
29+
path: rust-9p
30+
31+
- name: Build unpfs
32+
run: |
33+
cd rust-9p/example/unpfs/
34+
cargo build --release
35+
mkdir -p ~/.local/bin
36+
ln -s $PWD/target/release/unpfs ~/.local/bin
2037
2138
- name: Set up Python ${{ matrix.python-version }}
2239
uses: actions/setup-python@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea/
22
**/.pytest_cache/
3+
**/__pycache__/
34
build/
45
**/*.egg-info/
56
dist/

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,35 @@
22

33
9P implementation of Python fsspec.
44

5+
Supported protocols:
6+
7+
* [9P2000](https://ericvh.github.io/9p-rfc/rfc9p2000.html)
8+
* [9P2000.u](https://ericvh.github.io/9p-rfc/rfc9p2000.u.html)
9+
* [9P2000.L](https://github.com/chaos/diod/blob/master/protocol.md)
10+
11+
Supported servers:
12+
13+
* [py9p](https://github.com/pbchekin/p9fs-py/blob/main/src/py9p/__main__.py)
14+
* [unpfs](https://github.com/pfpacket/rust-9p/blob/master/README.md#unpfs)
15+
16+
## Examples
17+
18+
```python
19+
import p9fs
20+
21+
fs = p9fs.P9FileSystem(
22+
host='127.0.0.1',
23+
port=564,
24+
username='nobody',
25+
)
26+
27+
print(fs.ls('.'))
28+
```
29+
30+
## TODO
31+
32+
* `auth`
33+
* `atime`, `mtime`, `ctime`
34+
535
This package contains a fork of py9p (https://github.com/svinota/py9p), which seems no longer maintained.
36+
Minimal support for 9P2000.L has been added to the client code.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "p9fs"
3-
version = "0.0.1"
3+
version = "0.0.2"
44
description = "9P implementation of Python fsspec"
55
license = {file = "LICENSE"}
66
readme = "README.md"
@@ -36,3 +36,5 @@ build-backend = "setuptools.build_meta"
3636
where = ["src"]
3737
include = ["p9fs*", "py9p*"]
3838
namespaces = false
39+
40+
[tool.pytest.ini_options]

scripts/test.sh

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,84 @@ set -e
66

77
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
88
TMP_DIRS_FILE=/tmp/p9fs-dirs
9-
PY9S_SERVER_PID=/tmp/p9fs.pid
10-
PY9S_SERVER_LOG=/tmp/p9fs.log
9+
10+
PY9P_PID=/tmp/py9p.pid
11+
PY9P_LOG=/tmp/py9p.log
12+
13+
UNPFS_PID=/tmp/unpfs.pid
14+
UNPFS_LOG=/tmp/unpfs.log
15+
16+
export PYTHONUNBUFFERED=1
1117

1218
function mymktempdir {
1319
local tmpdir="$(mktemp -d)"
1420
echo "$tmpdir" | tee -a $TMP_DIRS_FILE
1521
}
1622

17-
function run_py9s_server {
18-
local exported_dir="$1"
19-
cd "$PROJECT_ROOT/src"
20-
python -m py9p -p 1234 -w -d -r "$exported_dir" &> $PY9S_SERVER_LOG &
21-
echo $! > $PY9S_SERVER_PID
22-
23+
function wait_for_server {
2324
echo Waiting for 9p server ...
2425
SERVER_READY=""
2526
for i in $(seq 1 5); do
27+
sleep 1
2628
if nc -d -w 1 -z 127.0.0.1 1234; then
2729
SERVER_READY="true"
2830
break
2931
fi
30-
sleep 1
3132
done
3233
if [[ ! $SERVER_READY ]]; then
3334
echo 9p server failed to start
3435
exit 1
3536
fi
3637
}
3738

38-
function user_tests {
39+
function run_py9p {
3940
local exported_dir="$1"
41+
local protocol="$2"
42+
43+
args=(
44+
-p 1234
45+
-w
46+
-d
47+
-r "$exported_dir"
48+
)
49+
50+
if [[ $protocol == "9P2000.u" ]]; then
51+
args+=( -D )
52+
fi
53+
4054
cd "$PROJECT_ROOT/src"
41-
python -m pytest -v -rA ../tests/user --exported "$exported_dir"
55+
python -m py9p "${args[@]}" &> $PY9P_LOG &
56+
echo $! > $PY9P_PID
57+
wait_for_server
4258
}
4359

44-
function cleanup {
45-
if [[ -f $PY9S_SERVER_PID ]]; then
46-
kill "$(<$PY9S_SERVER_PID)" || true
47-
rm -f "$PY9S_SERVER_PID"
60+
function stop_py9p {
61+
if [[ -f $PY9P_PID ]]; then
62+
kill "$(<$PY9P_PID)" || true
63+
rm -f "$PY9P_PID"
64+
fi
65+
}
66+
67+
function run_unpfs {
68+
local exported_dir="$1"
69+
${UNPFS:-unpfs} 'tcp!0.0.0.0!1234' "$exported_dir" &> $UNPFS_LOG &
70+
echo $! > $UNPFS_PID
71+
wait_for_server
72+
}
73+
74+
function stop_unpfs {
75+
if [[ -f $UNPFS_PID ]]; then
76+
kill "$(<$UNPFS_PID)" || true
77+
rm -f "$UNPFS_PID"
4878
fi
79+
}
80+
81+
function user_tests {
82+
cd "$PROJECT_ROOT/src"
83+
python -m pytest -v -rA ../tests/user "$@"
84+
}
85+
86+
function cleanup {
4987
if [[ -f $TMP_DIRS_FILE ]]; then
5088
xargs -n1 -r rm -rf < $TMP_DIRS_FILE
5189
rm -f $TMP_DIRS_FILE
@@ -56,6 +94,22 @@ trap cleanup EXIT
5694

5795
rm -f "$TMP_DIRS_FILE"
5896

97+
echo "PROJECT_ROOT: $PROJECT_ROOT"
98+
99+
echo "Testing py9p server with 9P2000"
100+
EXPORTED_DIR=""$(mymktempdir)""
101+
run_py9p "$EXPORTED_DIR" 9P2000
102+
user_tests --exported "$EXPORTED_DIR" --9p 9P2000
103+
stop_py9p
104+
105+
echo "Testing py9p server with 9P2000.u"
106+
EXPORTED_DIR=""$(mymktempdir)""
107+
run_py9p "$EXPORTED_DIR" 9P2000.u
108+
user_tests --exported "$EXPORTED_DIR" --9p 9P2000.u
109+
stop_py9p
110+
111+
echo "Testing unpfs server with 9P2000.L"
59112
EXPORTED_DIR=""$(mymktempdir)""
60-
run_py9s_server "$EXPORTED_DIR"
61-
user_tests "$EXPORTED_DIR"
113+
run_unpfs "$EXPORTED_DIR"
114+
user_tests --exported "$EXPORTED_DIR" --9p 9P2000.L
115+
stop_unpfs

0 commit comments

Comments
 (0)