Skip to content

Commit cb8cf64

Browse files
authored
IT-1579: Refactor for use as submodule in IDPS repo (#63)
* Modify API to support being built as a part of the IDPS app, while still supporting standalone installation via pip * Remove use of conda for local development and replace with venv module in python * Update docs, removing recommendation for use with anaconda, and provide alternatives for using package on apple silicon * Added support for python3.13
1 parent a6f222f commit cb8cf64

File tree

13 files changed

+221
-123
lines changed

13 files changed

+221
-123
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# secrets
22
.ideas-github-token
33
apiTestResults.xml
4+
venv/
45

56
# IDE
67
*.sublime-workspace

Makefile

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,50 @@ ifndef THIRD_PARTY_DIR
2424
THIRD_PARTY_DIR=third_party
2525
endif
2626

27-
# Extract python version
28-
ifndef PYTHON_VERSION
29-
PYTHON_VERSION=$(shell python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
27+
# Virtual environment vars
28+
ifndef VENV_NAME
29+
VENV_NAME=venv
3030
endif
3131

3232
# Detect OS
3333
ifeq ($(OS), Windows_NT)
3434
DETECTED_OS = windows
35+
VENV_ACTIVATE = source ${VENV_NAME}/Scripts/activate
3536
else
37+
VENV_ACTIVATE = source ${VENV_NAME}/bin/activate
3638
UNAME_S = $(shell uname -s)
3739
ifeq ($(UNAME_S), Linux)
3840
DETECTED_OS = linux
3941
else ifeq ($(UNAME_S), Darwin)
4042
DETECTED_OS = mac
41-
43+
endif
44+
endif
45+
46+
ifndef PYTHON
47+
PYTHON=python
48+
endif
49+
50+
# Check if the directory exists using wildcard and conditional
51+
ifeq ($(wildcard $(VENV_NAME)/.),)
52+
# Directory does not exist
53+
PYTHON_VERSION=$(shell ${PYTHON} -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
54+
else
55+
# Directory exists
56+
PYTHON_VERSION=$(shell ${VENV_ACTIVATE} && ${PYTHON} -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
57+
endif
58+
4259
# Set the macOS deployment version based on python version
43-
ifeq ($(PYTHON_VERSION), 3.9)
44-
_MACOSX_DEPLOYMENT_TARGET=10.11
45-
else ifeq ($(PYTHON_VERSION), 3.10)
46-
_MACOSX_DEPLOYMENT_TARGET=10.11
47-
else ifeq ($(PYTHON_VERSION), 3.11)
48-
_MACOSX_DEPLOYMENT_TARGET=10.11
49-
else ifeq ($(PYTHON_VERSION), 3.12)
50-
_MACOSX_DEPLOYMENT_TARGET=10.15
51-
endif
60+
ifeq ($(DETECTED_OS), mac)
61+
ifeq ($(PYTHON_VERSION), 3.9)
62+
_MACOSX_DEPLOYMENT_TARGET=10.11
63+
else ifeq ($(PYTHON_VERSION), 3.10)
64+
_MACOSX_DEPLOYMENT_TARGET=10.11
65+
else ifeq ($(PYTHON_VERSION), 3.11)
66+
_MACOSX_DEPLOYMENT_TARGET=10.11
67+
else ifeq ($(PYTHON_VERSION), 3.12)
68+
_MACOSX_DEPLOYMENT_TARGET=10.15
69+
else ifeq ($(PYTHON_VERSION), 3.13)
70+
_MACOSX_DEPLOYMENT_TARGET=10.15
5271
endif
5372
endif
5473

@@ -82,22 +101,6 @@ else ifeq ($(DETECTED_OS), mac)
82101
CMAKE_GENERATOR = Xcode
83102
endif
84103

85-
# Virtual environment vars
86-
ifndef VENV_NAME
87-
VENV_NAME=pyisx
88-
endif
89-
90-
# Define cmake generator based on OS
91-
ifeq ($(DETECTED_OS), windows)
92-
VENV_ACTIVATE = source '$(shell conda info --base)/Scripts/activate'
93-
else
94-
VENV_ACTIVATE = source $(shell conda info --base)/bin/activate
95-
endif
96-
97-
ifndef BUILD_API
98-
BUILD_API=0
99-
endif
100-
101104
check_os:
102105
@echo "Verifying detected OS"
103106
ifndef DETECTED_OS
@@ -113,21 +116,19 @@ clean:
113116
@rm -rf build
114117
@rm -rf docs/build
115118
@rm -rf wheelhouse
119+
@rm -rf ${VENV_NAME}
116120

117121
setup:
118122
./scripts/setup -v --src ${REMOTE_DIR} --dst ${REMOTE_LOCAL_DIR} --remote-copy
119123

120-
ifeq ($(DETECTED_OS), mac)
124+
ifeq ($(DETECTED_OS), windows)
121125
env:
122-
CONDA_SUBDIR=osx-64 conda create -y -n $(VENV_NAME) python=$(PYTHON_VERSION) && \
123-
$(VENV_ACTIVATE) $(VENV_NAME) && \
124-
conda config --env --set subdir osx-64 && \
125-
python -m pip install build
126+
sh -c "${PYTHON} -m venv ${VENV_NAME}"
127+
$(VENV_ACTIVATE) && python -m pip install '.[build,test,docs,deploy]'
126128
else
127129
env:
128-
conda create -y -n $(VENV_NAME) python=$(PYTHON_VERSION) && \
129-
$(VENV_ACTIVATE) $(VENV_NAME) && \
130-
python -m pip install build
130+
${PYTHON} -m venv ${VENV_NAME}
131+
$(VENV_ACTIVATE) && python -m pip install '.[build,test,docs,deploy]'
131132
endif
132133

133134
ifeq ($(DETECTED_OS), mac)
@@ -147,27 +148,26 @@ else ifeq ($(DETECTED_OS), mac)
147148
cd $(BUILD_PATH) && \
148149
xcodebuild -alltargets -configuration $(BUILD_TYPE) -project isx.xcodeproj CODE_SIGN_IDENTITY=""
149150
endif
151+
$(VENV_ACTIVATE) && \
150152
cd $(BUILD_PATH_BIN) && \
151-
$(VENV_ACTIVATE) $(VENV_NAME) && \
152153
python -m build
153154

154155
rebuild: clean build
155-
156-
test:
157-
$(VENV_ACTIVATE) $(VENV_NAME) && \
158-
pip install --force-reinstall '$(shell ls $(BUILD_PATH_BIN)/dist/isx-*.whl)[test]' && \
156+
157+
install:
158+
$(VENV_ACTIVATE) && \
159+
pip install --force-reinstall --no-deps '$(shell ls $(BUILD_PATH_BIN)/dist/isx-*.whl)'
160+
161+
test: install
162+
$(VENV_ACTIVATE) && \
159163
cd build/Release && \
160164
ISX_TEST_DATA_PATH='$(shell realpath $(TEST_DATA_DIR))' python -m pytest --disable-warnings -v -s --junit-xml=$(API_TEST_RESULTS_PATH) test $(TEST_ARGS)
161165

162-
ifeq ($(BUILD_API), 1)
163-
docs: build
164-
$(VENV_ACTIVATE) $(VENV_NAME) && \
165-
pip install --force-reinstall '$(shell ls $(BUILD_PATH_BIN)/dist/isx-*.whl)[docs]'
166-
endif
167166
docs:
168-
$(VENV_ACTIVATE) $(VENV_NAME) && \
167+
$(VENV_ACTIVATE) && \
169168
sphinx-build docs docs/build
170169

170+
# Used for fixing linux wheel installs before deploying to pypi
171171
repair-linux:
172172
docker run \
173173
-v $(shell pwd):/io \
@@ -177,12 +177,10 @@ repair-linux:
177177

178178
ifeq ($(DETECTED_OS), linux)
179179
deploy: repair-linux
180-
$(VENV_ACTIVATE) $(VENV_NAME) && \
181-
pip install twine && \
180+
$(VENV_ACTIVATE) && \
182181
twine upload '$(shell ls wheelhouse/isx-*.whl)'
183182
else
184183
deploy:
185-
$(VENV_ACTIVATE) $(VENV_NAME) && \
186-
pip install twine && \
184+
$(VENV_ACTIVATE) && \
187185
twine upload '$(shell ls $(BUILD_PATH_BIN)/dist/isx-*.whl)'
188-
endif
186+
endif

README.md

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@ Pre-built binaries of this API can be installed from [PyPi](https://pypi.org/pro
2020
pip install isx
2121
```
2222

23-
> **Note:** For Apple Silicon (i.e., macOS arm64 architecture), the package is currently not natively supported. However, it's possible to use anaconda to configure an x86 environment and use the project.
24-
25-
```bash
26-
CONDA_SUBDIR=osx-64 conda create -n <name> python=<python>
27-
conda activate <name>
28-
conda config --env --set subdir osx-64
29-
pip install isx
30-
```
31-
32-
Replace `<name>` with a name for the conda environment, and `<python>` with the python version to use.
23+
> **Note**: Currently, pyisx is only supported for x86 architectures, which can be problematic, specifically on the newer Mac computers with Apple Silicon. For usage with Apple Silicon, the Rosetta software must be installed, and the Terminal app must be configured to use this software for automatic translation of x86 binaries to arm64. Read more [here](https://support.apple.com/en-us/102527) on how to configure Rosetta on Mac computers.
3324
3425
## Supported Platforms
3526

@@ -60,43 +51,40 @@ Follow the setup instructions for the C++ [isxcore](https://github.com/inscopix/
6051

6152
2. Setup python virtual environment
6253

63-
Create a python virtual environment, specifying the desired python version.
64-
This guide uses anaconda for demonstration, but other tools like virtualenv or poetry can also be used.
54+
Create a python virtual environment using venv, specifying the desired python version.
6555

6656
```bash
67-
conda create -n <name> python=<python>
68-
conda activate <name>
57+
make env PYTHON=python3.13
6958
```
7059

71-
Replace `<name>` with a name for the conda environment, and `<python>` with the python version to use.
72-
73-
> **Note**: On macOS systems with Apple Silicon, the conda environment is configured differently, since `isxcore` is currently only built for x86 architectures.
60+
> **Note**: Currently, pyisx is only supported for x86 architectures, which can be problematic, specifically on the newer Mac computers with Apple Silicon. For usage with Apple Silicon, the Rosetta software must be installed, and the Terminal app must be configured to use this software for automatic translation of x86 binaries to arm64. Read more [here](https://support.apple.com/en-us/102527) on how to configure Rosetta on Mac computers.
7461
62+
In the Rosetta terminal, install Homebrew. This will install Homebrew to the `/usr/local` directory, indicating an x86 installation
7563
```bash
76-
CONDA_SUBDIR=osx-64 conda create -n <name> python=<python>
77-
conda activate <name>
78-
conda config --env --set subdir osx-64
64+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
7965
```
8066

81-
Replace `<name>` with a name for the conda environment, and `<python>` with the python version to use.
82-
83-
3. Install build & test dependencies
84-
85-
Inside the virtual environment install the following dependencies:
67+
Next, in Rosetta terminal, install the desired python version using the x86 installation of brew:
68+
```
69+
/usr/local/bin/brew install python@3.13
70+
```
8671

87-
```bash
88-
conda install -y build pytest
72+
To verify the installation worked correctly run the following command:
73+
```
74+
python3.13 -c "import sysconfig; print(sysconfig.get_platform())"
8975
```
9076

91-
> **Note**: For python 3.12 the `build` package must be installed used `pip` instead.
77+
The output will be `macosx-13.0-x86_64` is running x86 version of python, otherwise the output will instead be `macosx-13.0-arm64` if running the arm version of python.
78+
79+
3. Build the package
9280

93-
4. Build the package
81+
Once the virtual environment is setup, the package can be built.
9482

9583
```bash
9684
make build THIRD_PARTY_DIR=/path/to/third/party/dir
9785
```
9886

99-
5. Run the unit tests
87+
4. Run the unit tests
10088

10189
```bash
10290
make test THIRD_PARTY_DIR=/path/to/third/party/dir TEST_DATA_DIR=/path/to/test/data/dir

docs/installation.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,43 @@ Pre-built binaries of this API can be installed from [PyPi](https://pypi.org/pro
77
pip install isx
88
```
99

10+
## Installation on Apple Silicon
11+
1012
::: {attention}
11-
For Apple Silicon (i.e., macOS with arm64 architecture), the package is currently not natively supported. However, it's possible to use [anaconda](https://www.anaconda.com/) to configure an x86 environment and use the project.
13+
Currently, pyisx is only supported for x86 architectures, which can be problematic, specifically on the newer Mac computers with Apple Silicon. The following section describes one option for how to use this package on newer Mac computers.
1214
:::
1315

16+
For usage with Apple Silicon, the Rosetta software must be installed, and the Terminal app must be configured to use this software for automatic translation of x86 binaries to arm64. Read more [here](https://support.apple.com/en-us/102527) on how to configure Rosetta on Mac computers.
17+
18+
Next, install an x86 version of python with the following steps.
19+
20+
First, in the Rosetta terminal, install Homebrew, which is a package manager for macOS. This will install Homebrew to the `/usr/local` directory, indicating an x86 installation:
1421
```bash
15-
CONDA_SUBDIR=osx-64 conda create -n <name> python=<python>
16-
conda activate <name>
17-
conda config --env --set subdir osx-64
18-
pip install isx
22+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
23+
```
24+
25+
Next, in the Rosetta terminal, install the desired python version using the x86 installation of brew:
26+
```bash
27+
/usr/local/bin/brew install python@3.13
1928
```
2029

21-
Replace `<name>` with a name for the conda environment, and `<python>` with the python version to use.
30+
Verify the installation worked correctly by running the following command:
31+
```bash
32+
python3.13 -c "import sysconfig; print(sysconfig.get_platform())"
33+
```
34+
35+
The output will be `macosx-13.0-x86_64` if running the x86 version of python, otherwise the output will instead be `macosx-13.0-arm64` if running the arm version of python.
36+
37+
If the output indicates the x86 version of python, you can install the `pyisx` package.
38+
For example, the following snippet demonstrates how to create a [virtual environment](https://docs.python.org/3/library/venv.html) using the x86 version of python, and then install the pyisx package within the virtual environment.
39+
```bash
40+
python3.13 -m venv venv
41+
source venv/bin/activate && python -m pip install pyisx
42+
```
2243

2344
## Supported Platforms
2445

25-
This package has been built and tested on the following operating systems, for python versions `3.9 - 3.12`:
46+
This package has been built and tested on the following operating systems, for python versions `3.9 - 3.13`:
2647

2748
| OS | Version | Architecture |
2849
| --------- | ------- | ----- |

docs/overview.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,9 @@ pip install isx
2020
```
2121

2222
::: {attention}
23-
For Apple Silicon (i.e., macOS with arm64 architecture), the package is currently not natively supported. However, it's possible to use [anaconda](https://www.anaconda.com/) to configure an x86 environment and use the project.
23+
Currently, pyisx is only supported for x86 architectures, which can be problematic, specifically on the newer Mac computers with Apple Silicon. For usage with Apple Silicon, the Rosetta software must be installed, and the Terminal app must be configured to use this software for automatic translation of x86 binaries to arm64. Read more [here](https://support.apple.com/en-us/102527) on how to configure Rosetta on Mac computers.
2424
:::
2525

26-
```bash
27-
CONDA_SUBDIR=osx-64 conda create -n <name> python=<python>
28-
conda activate <name>
29-
conda config --env --set subdir osx-64
30-
pip install isx
31-
```
32-
3326
Please refer to the [Installation](#installation) guide for more details.
3427

3528
## File Types

isx/_internal.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
_lib_dir = os.path.join(_this_dir, 'lib')
1919
_is_windows = os.name == 'nt'
2020
if _is_windows:
21+
# Special case for windows
22+
# If built apart of IDPS app, all dlls need to be in top-level app dir
23+
if not os.path.exists(_lib_dir):
24+
_lib_dir = os.path.join(_this_dir, '..')
2125
_cwd = os.getcwd()
2226
os.chdir(_lib_dir)
2327
_isx_lib_name = os.path.join(_lib_dir, 'isxpublicapi.dll')
@@ -1064,6 +1068,17 @@ def get_core_version():
10641068
ctypes.c_double]
10651069
c_api.isx_apply_cell_set.errcheck = _standard_errcheck
10661070

1071+
c_api.isx_apply_rois.argtypes = [
1072+
ctypes.c_int,
1073+
CharPtrPtr,
1074+
CharPtrPtr,
1075+
ctypes.c_int,
1076+
Int64Ptr,
1077+
Int64Ptr,
1078+
ctypes.c_bool,
1079+
CharPtrPtr]
1080+
c_api.isx_apply_rois.errcheck = _standard_errcheck
1081+
10671082
c_api.isx_export_cell_contours.argtypes = [
10681083
ctypes.c_int,
10691084
CharPtrPtr,
@@ -1227,7 +1242,9 @@ def get_core_version():
12271242
ctypes.c_char_p,
12281243
ctypes.c_bool,
12291244
ctypes.c_double,
1230-
ctypes.c_size_t]
1245+
ctypes.c_size_t,
1246+
ctypes.c_bool,
1247+
CharPtrPtr]
12311248
c_api.isx_estimate_vessel_diameter.errcheck = _standard_errcheck
12321249

12331250
c_api.isx_estimate_rbc_velocity.argtypes = [

0 commit comments

Comments
 (0)