Skip to content

Commit bf3510f

Browse files
bgilbertNikratio
authored andcommittedDec 14, 2023
Move modules into pyfuse3 package
If we want to export our type information, we're required to wrap our modules in a package. Do so, but leave compatbility wrappers in the old locations.
1 parent d440eb4 commit bf3510f

17 files changed

+79
-36
lines changed
 

‎.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ build/
33
dist/
44
doc/html/
55
doc/doctrees/
6-
src/pyfuse3/pyfuse3.c
7-
src/pyfuse3/pyfuse3*.so
6+
src/pyfuse3/__init__.c
7+
src/pyfuse3/__init__*.so
88
test/.cache/
99
__pycache__
1010
test/.pytest_cache/

‎Changes.rst

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
.. currentmodule:: pyfuse3
66

7+
Unreleased Changes
8+
==================
9+
10+
* Move ``_pyfuse3`` to ``pyfuse3._pyfuse3`` and add a compatibility wrapper
11+
for the old name.
12+
13+
* Move ``pyfuse3_asyncio`` to ``pyfuse3.asyncio`` and add a compatibility
14+
wrapper for the old name.
15+
16+
717
Release 3.3.0 (2023-08-06)
818
==========================
919

‎examples/hello.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
# to load the module from there first.
3030
basedir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
3131
if (os.path.exists(os.path.join(basedir, 'setup.py')) and
32-
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', 'pyfuse3.pyx'))):
33-
sys.path.insert(0, os.path.join(basedir, 'src', 'pyfuse3'))
32+
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', '__init__.pyx'))):
33+
sys.path.insert(0, os.path.join(basedir, 'src'))
3434

3535
from argparse import ArgumentParser
3636
import stat

‎examples/hello_asyncio.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
# to load the module from there first.
3030
basedir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
3131
if (os.path.exists(os.path.join(basedir, 'setup.py')) and
32-
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', 'pyfuse3.pyx'))):
33-
sys.path.insert(0, os.path.join(basedir, 'src', 'pyfuse3'))
32+
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', '__init__.pyx'))):
33+
sys.path.insert(0, os.path.join(basedir, 'src'))
3434

3535
from argparse import ArgumentParser
3636
import asyncio
3737
import stat
3838
import logging
3939
import errno
4040
import pyfuse3
41-
import pyfuse3_asyncio
41+
import pyfuse3.asyncio
4242

4343
try:
4444
import faulthandler
@@ -48,7 +48,7 @@
4848
faulthandler.enable()
4949

5050
log = logging.getLogger(__name__)
51-
pyfuse3_asyncio.enable()
51+
pyfuse3.asyncio.enable()
5252

5353
class TestFs(pyfuse3.Operations):
5454
def __init__(self):

‎examples/passthroughfs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
# to load the module from there first.
4747
basedir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
4848
if (os.path.exists(os.path.join(basedir, 'setup.py')) and
49-
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', 'pyfuse3.pyx'))):
50-
sys.path.insert(0, os.path.join(basedir, 'src', 'pyfuse3'))
49+
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', '__init__.pyx'))):
50+
sys.path.insert(0, os.path.join(basedir, 'src'))
5151

5252
import pyfuse3
5353
from argparse import ArgumentParser

‎examples/tmpfs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
# to load the module from there first.
2929
basedir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
3030
if (os.path.exists(os.path.join(basedir, 'setup.py')) and
31-
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', 'pyfuse3.pyx'))):
32-
sys.path.insert(0, os.path.join(basedir, 'src', 'pyfuse3'))
31+
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', '__init__.pyx'))):
32+
sys.path.insert(0, os.path.join(basedir, 'src'))
3333

3434
import pyfuse3
3535
import errno

‎rst/asyncio.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
By default, pyfuse3 uses asynchronous I/O using Trio_ (and most of the
88
documentation assumes that you are using Trio). If you'd rather use
9-
asyncio, import the *pyfuse3_asyncio* module and call its
10-
*enable()* function before using *pyfuse3*. For example::
9+
asyncio, import the *pyfuse3.asyncio* module (*pyfuse3_asyncio* in 3.3.0 and
10+
earlier) and call its *enable()* function before using *pyfuse3*.
11+
For example::
1112

1213
import pyfuse3
13-
import pyfuse3_asyncio
14+
import pyfuse3.asyncio
1415

15-
pyfuse3_asyncio.enable()
16+
pyfuse3.asyncio.enable()
1617

1718
# Use pyfuse3 as usual from here on.
1819

‎rst/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# we need util/ so the sphinx_cython extension is found:
2020
sys.path.insert(0, os.path.join(basedir, 'util'))
2121
# we need src/ also, it is needed so llfuse can be imported to generate api docs:
22-
sys.path.insert(0, os.path.join(basedir, 'src', 'pyfuse3'))
22+
sys.path.insert(0, os.path.join(basedir, 'src'))
2323

2424
#pylint: disable-all
2525
#@PydevCodeAnalysisIgnore

‎setup.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def main():
8989

9090
link_args = pkg_config('fuse3', cflags=False, ldflags=True, min_ver='3.2.0')
9191
link_args.append('-lpthread')
92-
c_sources = ['src/pyfuse3/pyfuse3.c']
92+
c_sources = ['src/pyfuse3/__init__.c']
9393

9494
if os.uname()[0] in ('Linux', 'GNU/kFreeBSD'):
9595
link_args.append('-lrt')
@@ -127,10 +127,11 @@ def main():
127127
install_requires=['trio >= 0.15'],
128128
tests_require=['pytest >= 3.4.0', 'pytest-trio'],
129129
python_requires='>=3.8',
130-
package_dir={'': 'src/pyfuse3'},
130+
package_dir={'': 'src'},
131+
packages=['pyfuse3'],
131132
py_modules=['_pyfuse3', 'pyfuse3_asyncio'],
132133
provides=['pyfuse3'],
133-
ext_modules=[Extension('pyfuse3', c_sources,
134+
ext_modules=[Extension('pyfuse3.__init__', c_sources,
134135
extra_compile_args=compile_args,
135136
extra_link_args=link_args)],
136137
cmdclass={'build_cython': build_cython},

‎src/_pyfuse3.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
_pyfuse3.py
3+
4+
Compatibility redirect: Pure-Python components of pyfuse3.
5+
6+
Copyright © 2018 Nikolaus Rath <Nikolaus.org>
7+
8+
This file is part of pyfuse3. This work may be distributed under
9+
the terms of the GNU LGPL.
10+
'''
11+
12+
from pyfuse3 import _pyfuse3
13+
import sys
14+
15+
sys.modules['_pyfuse3'] = _pyfuse3

‎src/pyfuse3/pyfuse3.pyi ‎src/pyfuse3/__init__.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'''
2-
pyfuse3.pyi
2+
__init__.pyi
33
4-
Type annotation stubs for the external API in pyfuse3.pyx.
4+
Type annotation stubs for the external API in __init__.pyx.
55
66
Copyright © 2021 Oliver Galvin
77
88
This file is part of pyfuse3. This work may be distributed under
99
the terms of the GNU LGPL.
1010
'''
1111

12-
from _pyfuse3 import Operations, async_wrapper, FileHandleT, FileNameT, FlagT, InodeT, ModeT
12+
from ._pyfuse3 import Operations, async_wrapper, FileHandleT, FileNameT, FlagT, InodeT, ModeT
1313
from typing import List, Literal, Mapping
1414

1515
NamespaceT = Literal["system", "user"]

‎src/pyfuse3/pyfuse3.pyx ‎src/pyfuse3/__init__.pyx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
pyfuse3.pyx
2+
__init__.pyx
33
44
Copyright © 2013 Nikolaus Rath <Nikolaus.org>
55
@@ -19,7 +19,7 @@ cdef extern from "pyfuse3.h":
1919
###########
2020

2121
from fuse_lowlevel cimport *
22-
from macros cimport *
22+
from .macros cimport *
2323
from posix.stat cimport struct_stat, S_IFMT, S_IFDIR, S_IFREG
2424
from posix.types cimport mode_t, dev_t, off_t
2525
from libc.stdint cimport uint32_t
@@ -69,13 +69,13 @@ import trio
6969
import threading
7070
import typing
7171

72-
import _pyfuse3
72+
from . import _pyfuse3
7373
_pyfuse3.FUSEError = FUSEError
7474

75-
from _pyfuse3 import Operations, async_wrapper
75+
from ._pyfuse3 import Operations, async_wrapper
7676

7777
if typing.TYPE_CHECKING:
78-
from _pyfuse3 import FileHandleT, FileNameT, FlagT, InodeT, ModeT
78+
from ._pyfuse3 import FileHandleT, FileNameT, FlagT, InodeT, ModeT
7979

8080

8181
##################

‎src/pyfuse3/pyfuse3_asyncio.py ‎src/pyfuse3/asyncio.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
pyfuse3_asyncio.py
2+
asyncio.py
33
44
asyncio compatibility layer for pyfuse3
55
@@ -16,15 +16,15 @@
1616
from typing import Any, Callable, Iterable, Optional, Type
1717

1818
import pyfuse3
19-
from _pyfuse3 import FileHandleT
19+
from ._pyfuse3 import FileHandleT
2020

2121
Lock = asyncio.Lock
2222

2323

2424
def enable() -> None:
2525
'''Switch pyfuse3 to asyncio mode.'''
2626

27-
fake_trio = sys.modules['pyfuse3_asyncio']
27+
fake_trio = sys.modules['pyfuse3.asyncio']
2828
fake_trio.lowlevel = fake_trio # type: ignore
2929
fake_trio.from_thread = fake_trio # type: ignore
3030
pyfuse3.trio = fake_trio # type: ignore

‎src/pyfuse3/handlers.pxi

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
handlers.pxi
33
44
This file defines the FUSE request handlers. It is included
5-
by pyfuse3.pyx.
5+
by __init__.pyx.
66
77
Copyright © 2013 Nikolaus Rath <Nikolaus.org>
88

‎src/pyfuse3/internal.pxi

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
internal.pxi
33
44
This file defines functions and data structures that are used internally by
5-
pyfuse3. It is included by pyfuse3.pyx.
5+
pyfuse3. It is included by __init__.pyx.
66
77
Copyright © 2013 Nikolaus Rath <Nikolaus.org>
88
@@ -194,7 +194,7 @@ cdef class _WorkerData:
194194
self.task_serial += 1
195195
return 'pyfuse-%02d' % self.task_serial
196196

197-
# Delay initialization so that pyfuse3_asyncio can replace
197+
# Delay initialization so that pyfuse3.asyncio can replace
198198
# the trio module.
199199
cdef _WorkerData worker_data
200200

‎src/pyfuse3_asyncio.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
asyncio.py
3+
4+
Compatibility redirect: asyncio compatibility layer for pyfuse3
5+
6+
Copyright © 2018 Nikolaus Rath <Nikolaus.org>
7+
Copyright © 2018 JustAnotherArchivist
8+
9+
This file is part of pyfuse3. This work may be distributed under
10+
the terms of the GNU LGPL.
11+
'''
12+
13+
from pyfuse3 import asyncio
14+
import sys
15+
16+
sys.modules['pyfuse3_asyncio'] = asyncio

‎test/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def pytest_configure(config):
5050
# modules from here
5151
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
5252
if not config.getoption('installed'):
53-
pyfuse3_path = os.path.join(basedir, 'src', 'pyfuse3')
53+
pyfuse3_path = os.path.join(basedir, 'src')
5454
if (os.path.exists(os.path.join(basedir, 'setup.py')) and
55-
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', 'pyfuse3.pyx'))):
55+
os.path.exists(os.path.join(basedir, 'src', 'pyfuse3', '__init__.pyx'))):
5656
sys.path.insert(0, pyfuse3_path)
5757

5858
# Make sure that called processes use the same path

0 commit comments

Comments
 (0)
Please sign in to comment.