Skip to content

Commit

Permalink
Merge pull request #68 from amangupta17/feat-macos-support
Browse files Browse the repository at this point in the history
Feat: macos support
  • Loading branch information
dancergraham authored Aug 10, 2024
2 parents 7b6da93 + 2069d6e commit dbe04bb
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 21 deletions.
107 changes: 103 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,89 @@ jobs:
shell: pwsh
run: python -m pytest tests

build-and-test-macos:
name: macOS (python ${{ matrix.python-version }})
runs-on: macos-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install build dependencies
working-directory: ./scripts
run: |
bash install_xerces_c.sh
- name: Install package
run: pip install .

- name: Install pytest
run: pip install pytest

- name: Run tests
run: python -m pytest tests

build_wheels:
name: Build wheels
runs-on: ${{ matrix.os }}
needs:
- build-and-test-ubuntu
- build-and-test-windows
if: startsWith(github.ref, 'refs/tags/v')
- build-and-test-macos
strategy:
matrix:
os: ["ubuntu-latest", "windows-2019"]
os: ["ubuntu-latest", "windows-2019", "macos-latest"]

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.12"

- name: Install cibuildwheel
run: python -m pip install cibuildwheel
run: |
python -m pip install -U pip
python -m pip install cibuildwheel
- name: Build wheels (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
python -m cibuildwheel --platform linux --output-dir wheelhouse
env:
CIBW_BEFORE_ALL_LINUX: "bash scripts/install_xerces_c.sh"
CIBW_BUILD: "cp*-manylinux_x86_64"
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8, <3.13"

- name: Build wheels (Windows)
if: matrix.os == 'windows-2019'
run: |
python -m cibuildwheel --platform windows --output-dir wheelhouse
env:
CIBW_BEFORE_ALL_WINDOWS: "powershell scripts/install_xerces_c.ps1"
CIBW_BUILD: "cp*-win_amd64*"
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8, <3.13"

- name: Build wheels (macOS)
if: matrix.os == 'macos-latest'
run: |
python -m cibuildwheel --platform macos --output-dir wheelhouse
env:
CIBW_BEFORE_ALL_MACOS: "bash scripts/install_xerces_c.sh"
CIBW_BUILD: "cp*-macosx*"
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8, <3.13"

- uses: actions/upload-artifact@v2
with:
Expand All @@ -116,10 +167,10 @@ jobs:
make_sdist:
name: Make sdist
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs:
- build-and-test-ubuntu
- build-and-test-windows
- build-and-test-macos
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -133,6 +184,49 @@ jobs:
name: sdist
path: dist/*.tar.gz

test_built_wheels:
name: Test Built Wheels
runs-on: ${{ matrix.os }}
needs: build_wheels
strategy:
matrix:
os: [ "ubuntu-latest", "windows-2019", "macos-latest" ]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- uses: actions/download-artifact@v2
with:
name: wheels-${{ matrix.os }}
path: dist

- name: Install wheel
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: |
python_version=$(python -c "import sys; print('cp{}{}'.format(sys.version_info.major, sys.version_info.minor))")
wheel_file=$(ls dist/*$python_version*.whl)
pip install $wheel_file
- name: Install wheel(Windows)
if: matrix.os == 'windows-2019'
shell: pwsh
run: |
$python_version = (python -c "import sys; print('cp{}{}'.format(sys.version_info.major, sys.version_info.minor))").Trim()
$wheel_file = Get-ChildItem -Path dist -Filter "*$python_version*.whl" | Select-Object -First 1
python -m pip install $wheel_file.FullName
- name: Verify installation
run: |
pip install pytest
python -m pytest tests
upload_all:
name: Upload to pypi
needs: [build_wheels, make_sdist]
Expand All @@ -149,6 +243,11 @@ jobs:
name: wheels-windows-2019
path: dist

- uses: actions/download-artifact@v2
with:
name: wheels-macos-latest
path: dist

- uses: actions/download-artifact@v2
with:
name: sdist
Expand Down
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ translation_x = scan_0["pose"]["translation"]["x"]

## Installation

If you're on linux or Windows, a wheel should be available.
On linux, Windows or Apple Silicon:

`python -m pip install pye57`

## Building from source
On macOS with Intel CPU you can try to build from source (advanced users):

### Cloning the repository and required submodules
## Building from source (for developers)

Clone a new repository along with the required submodules
### Cloning the repository with required submodule

Clone a new repository along with the libe57Format submodule

`git clone https://github.com/davidcaron/pye57.git --recursive`

If the repository has already been previously cloned, but without the --recursive flag

```
```Bash
cd pye57 # go to the cloned repository
git submodule init # this will initialise the submodules in the repository
git submodule update # this will update the submodules in the repository
Expand All @@ -100,9 +102,15 @@ To get xerces-c, you can either build from source or if you're using conda:

`conda install -y xerces-c`

### Dependencies on MacOS

To get xerces-c, run:

`bash ./scripts/install_xerces_c.sh`

### Run `pip install` from the repo source

```
```Bash
cd pye57
python -m pip install .
```
Expand All @@ -111,6 +119,6 @@ python -m pip install .

Use pip again

```
```Bash
python -m pip uninstall pye57
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ build-backend = "setuptools.build_meta"
# before-all = "bash scripts/install_xerces_c.sh"
# before-all = "powershell scripts/install_xerces_c.ps1"
test-requires = "pytest"
build = "cp*-manylinux_x86_64 cp*-win_amd64*"
build = "cp*-manylinux_x86_64 cp*-win_amd64* cp*-macosx*"
test-command = "python -m pytest {project}/tests"
35 changes: 27 additions & 8 deletions scripts/install_xerces_c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,34 @@ echo "Download Xerces-C..."
curl -L https://github.com/apache/xerces-c/archive/v${XERCES_VERSION}.tar.gz --output xerces-c-${XERCES_VERSION}.tar.gz
echo "Extract Xerces-C..."
tar xzf xerces-c-${XERCES_VERSION}.tar.gz
cd xerces-c-${XERCES_VERSION}
echo "Configure Xerces-C..."
./reconf
./configure
echo "Build Xerces-C..."
make
echo "Install Xerces-C..."
make install
cd xerces-c-${XERCES_VERSION}

# Check the operating system and install dependencies accordingly
if [[ "$(uname)" == "Darwin" ]]; then
echo "Installing dependencies on macOS..."
brew install autoconf automake libtool
echo "Generate configure script using autoreconf..."
autoreconf -i
echo "Configure Xerces-C for macOS..."
./configure --prefix=/usr/local --enable-static
echo "Build Xerces-C..."
make
echo "Install Xerces-C..."
sudo make install
else
echo "Installing dependencies on Linux..."
./reconf
./configure
echo "Build Xerces-C..."
make
echo "Install Xerces-C..."
make install
fi

echo "Clean up Xerces-C..."
cd /
rm -rf ${XSD_BUILD_AREA}

echo "Xerces-C installed successfully."


17 changes: 16 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"libE57Format/extern/CRCpp/inc",
]
package_data = []
extra_link_args = []

if platform.system() == "Windows":
libraries.append("xerces-c_3")
Expand All @@ -43,7 +44,20 @@
# include xerces-c dll in the package
shutil.copy2(xerces_dir / "bin" / "xerces-c_3_2.dll", HERE / "src" / "pye57")
package_data.append("xerces-c_3_2.dll")

elif platform.system() == "Darwin":
xerces_dir = Path("/usr/local/")
if xerces_dir.exists():
# include xerces-c dylib in the package
shutil.copy2(xerces_dir / "lib" / "libxerces-c-3.2.dylib", HERE / "src" / "pye57")
library_dirs.append(str(xerces_dir / "lib"))
include_dirs.append(str(xerces_dir / "include"))
package_data.append("libxerces-c-3.2.dylib")
libraries.append("xerces-c")
extra_link_args = [
f"-Wl,-rpath,@loader_path",
f"-L{str(HERE / 'src' / 'pye57')}",
"-lxerces-c",
]
else:
libraries.append("xerces-c")

Expand All @@ -56,6 +70,7 @@
libraries=libraries,
library_dirs=library_dirs,
language="c++",
extra_link_args=extra_link_args,
),
]

Expand Down

0 comments on commit dbe04bb

Please sign in to comment.