Skip to content

Commit

Permalink
chore(python): Use src/ layout for python package (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored Jun 16, 2023
1 parent 7916c81 commit f92eb6a
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ jobs:
pushd python
# Build with Cython + gcc coverage options
pip install -e .
NANOARROW_PYTHON_COVERAGE=1 python setup.py build_ext --inplace
# Run tests + coverage.py (generates .coverage + coverage.xml files)
python -m pytest --cov ./nanoarrow
python -m pytest --cov ./src/nanoarrow
python -m coverage xml
- name: Upload coverage to codecov
Expand Down
8 changes: 4 additions & 4 deletions python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# specific language governing permissions and limitations
# under the License.

nanoarrow/nanoarrow.c
nanoarrow/nanoarrow.h
nanoarrow/nanoarrow_c.pxd
nanoarrow/*.c
src/nanoarrow/nanoarrow.c
src/nanoarrow/nanoarrow.h
src/nanoarrow/nanoarrow_c.pxd
src/nanoarrow/*.c

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
6 changes: 3 additions & 3 deletions python/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
# under the License.

exclude bootstrap.py
include nanoarrow/nanoarrow.c
include nanoarrow/nanoarrow.h
include nanoarrow/nanoarrow_c.pxd
include src/nanoarrow/nanoarrow.c
include src/nanoarrow/nanoarrow.h
include src/nanoarrow/nanoarrow_c.pxd
14 changes: 7 additions & 7 deletions python/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def copy_or_generate_nanoarrow_c():
this_dir = os.path.abspath(os.path.dirname(__file__))
source_dir = os.path.dirname(this_dir)

maybe_nanoarrow_h = os.path.join(this_dir, 'nanoarrow/nanoarrow.h')
maybe_nanoarrow_c = os.path.join(this_dir, 'nanoarrow/nanoarrow.c')
maybe_nanoarrow_h = os.path.join(this_dir, 'src/nanoarrow/nanoarrow.h')
maybe_nanoarrow_c = os.path.join(this_dir, 'src/nanoarrow/nanoarrow.c')
for f in (maybe_nanoarrow_c, maybe_nanoarrow_h):
if os.path.exists(f):
os.unlink(f)
Expand All @@ -161,7 +161,7 @@ def copy_or_generate_nanoarrow_c():
os.mkdir(build_dir)
os.chdir(build_dir)
os.system(f'cmake ../.. -DNANOARROW_BUNDLE=ON -DNANOARROW_NAMESPACE=PythonPkg')
os.system(f'cmake --install . --prefix=../nanoarrow')
os.system(f'cmake --install . --prefix=../src/nanoarrow')
finally:
if os.path.exists(build_dir):
# Can fail on Windows with permission issues
Expand All @@ -176,18 +176,18 @@ def copy_or_generate_nanoarrow_c():
else:
raise ValueError('Attempt to build source distribution outside the nanoarrow repo')

if not os.path.exists(os.path.join(this_dir, 'nanoarrow/nanoarrow.h')):
if not os.path.exists(os.path.join(this_dir, 'src/nanoarrow/nanoarrow.h')):
raise ValueError('Attempt to vendor nanoarrow.c/h failed')

maybe_nanoarrow_hpp = os.path.join(this_dir, 'nanoarrow/nanoarrow.hpp')
maybe_nanoarrow_hpp = os.path.join(this_dir, 'src/nanoarrow/nanoarrow.hpp')
if os.path.exists(maybe_nanoarrow_hpp):
os.unlink(maybe_nanoarrow_hpp)

# Runs the pxd generator with some information about the file name
def generate_nanoarrow_pxd():
this_dir = os.path.abspath(os.path.dirname(__file__))
maybe_nanoarrow_h = os.path.join(this_dir, 'nanoarrow/nanoarrow.h')
maybe_nanoarrow_pxd = os.path.join(this_dir, 'nanoarrow/nanoarrow_c.pxd')
maybe_nanoarrow_h = os.path.join(this_dir, 'src/nanoarrow/nanoarrow.h')
maybe_nanoarrow_pxd = os.path.join(this_dir, 'src/nanoarrow/nanoarrow_c.pxd')

NanoarrowPxdGenerator().generate_nanoarrow_pxd(
maybe_nanoarrow_h,
Expand Down
6 changes: 3 additions & 3 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
ext_modules=[
Extension(
name="nanoarrow._lib",
include_dirs=["nanoarrow"],
include_dirs=["src/nanoarrow"],
language="c",
sources=[
"nanoarrow/_lib.pyx",
"nanoarrow/nanoarrow.c",
"src/nanoarrow/_lib.pyx",
"src/nanoarrow/nanoarrow.c",
],
extra_compile_args=coverage_compile_args,
extra_link_args=coverage_link_args,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f92eb6a

Please sign in to comment.