Skip to content

Commit

Permalink
make c extensions optional for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Oct 16, 2023
1 parent 9a335cc commit 43d25ee
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 55 deletions.
26 changes: 8 additions & 18 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: '**/setup.cfg'
cache-dependency-path: '**/pyproject.toml'
- name: Set up env
run: |
echo "LIBBSON_INSTALL_DIR=$PWD/libbson" >> $GITHUB_ENV
Expand Down Expand Up @@ -98,31 +98,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache conda
uses: actions/cache@v3
env:
# Increase this value to reset cache if environment.yml has not changed
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{
hashFiles('bindings/python/docs/environment.yml') }}
- uses: conda-incubator/setup-miniconda@v2
- name: Setup Python
uses: actions/setup-python@v4
with:
auto-update-conda: true
activate-environment: mongo_arrow_documentation
environment-file: bindings/python/docs/environment.yml
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
python-version: 3.9
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
- name: Install lib
shell: bash -l {0}
run: |
pip install .
NO_EXT=1 pip install .
- name: Build docs with warnings
shell: bash -l {0}
run: |
pushd docs
make html SPHINXOPTS="-W"
NO_EXT=1 make html SPHINXOPTS="-W"
- name: Run linkcheck
shell: bash -l {0}
run: |
Expand Down
13 changes: 4 additions & 9 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
version: 2
build:
os: "ubuntu-22.04"
os: ubuntu-22.04
tools:
python: "mambaforge-22.9"
python: "3.9"
commands:
- NO_EXT=1 pip install ./bindings/python[docs]
sphinx:
configuration: ./bindings/python/docs/source/conf.py
conda:
environment: ./bindings/python/docs/environment.yml
python:
install:
# install the package itself
- method: pip
path: ./bindings/python
11 changes: 0 additions & 11 deletions bindings/python/docs/environment.yml

This file was deleted.

32 changes: 17 additions & 15 deletions bindings/python/pymongoarrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import traceback
import warnings

Expand All @@ -28,19 +29,20 @@ def _parse_version(version):
return _LooseVersion(version)


try:
from pymongoarrow.lib import libbson_version
except ImportError:
warnings.warn(
"Could not find compiled pymongoarrow.lib extension, please install "
"from source or report the following traceback on the issue tracker:\n"
f"{traceback.format_exc()}"
)
libbson_version = None

if libbson_version is not None:
if _parse_version(libbson_version) < _parse_version(_MIN_LIBBSON_VERSION):
raise ImportError(
f"Expected libbson version {_MIN_LIBBSON_VERSION} or greater, "
f"found {libbson_version}"
if not os.environ.get("NO_EXT"):
try:
from pymongoarrow.lib import libbson_version
except ImportError:
warnings.warn(
"Could not find compiled pymongoarrow.lib extension, please install "
"from source or report the following traceback on the issue tracker:\n"
f"{traceback.format_exc()}"
)
libbson_version = None

if libbson_version is not None:
if _parse_version(libbson_version) < _parse_version(_MIN_LIBBSON_VERSION):
raise ImportError(
f"Expected libbson version {_MIN_LIBBSON_VERSION} or greater, "
f"found {libbson_version}"
)
6 changes: 5 additions & 1 deletion bindings/python/pymongoarrow/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import warnings

import numpy as np
Expand All @@ -26,11 +27,14 @@
from pymongo.common import MAX_WRITE_BATCH_SIZE
from pymongoarrow.context import PyMongoArrowContext
from pymongoarrow.errors import ArrowWriteError
from pymongoarrow.lib import process_bson_stream
from pymongoarrow.result import ArrowWriteResult
from pymongoarrow.schema import Schema
from pymongoarrow.types import _validate_schema, get_numpy_type

if not os.environ.get("NO_EXT"):
from pymongoarrow.lib import process_bson_stream


__all__ = [
"aggregate_arrow_all",
"find_arrow_all",
Expand Down
1 change: 1 addition & 0 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ content-type = "text/x-rst"
Homepage = "https://github.com/mongodb-labs/mongo-arrow/tree/main/bindings/python"

[project.optional-dependencies]
docs = ["sphinx"]
test = ["pytz", "pytest"]

[tool.setuptools]
Expand Down
7 changes: 6 additions & 1 deletion bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,9 @@ def get_extension_modules():
return modules


setup(ext_modules=get_extension_modules())
if os.environ.get("NO_EXT"):
ext_modules = []
else:
ext_modules = get_extension_modules()

setup(ext_modules=ext_modules)

0 comments on commit 43d25ee

Please sign in to comment.