I created a cudmore-make-pip-install branch that converts the repo to allow "pip install ." from local source.
This required a few additions and changes.
First, I added some files to the root MapManagerCore folder including:
manifest.ini
pyproject.toml
setup.py
The setup.py file does the heavy lifting to allow "pip install .".
Change 1
In general, source code folders are all lower case, see pep8.
Changed source code folder MapManagerCore to all lower case mapmanagercore.
This requires all source code to use all lower case for imports, like from mapmanagercore import MapAnnotations.
Important. When merging this branch we might need to manually change the source code folder from MapManagerCore to all lower case mapmanagercore. This is because I am pushing from macOS and the folder name is the same and macOS does not make a distinction between same folder/file names with different cases. I think git has this same issue?
Here is a snippit from pep8.
Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.
Change 2
Moved example.ipynb into examples/ folder
and modified its import to be lowercase import mapmanagercore.
Error 1
imageLoader.read("./data/rr30a_s0u/t0/rr30a_s0_ch1.tif", channel=0)
Yields
File "/Users/cudmore/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/tifffile/tifffile.py", line 8516, in decode_raise_compression
raise ValueError(f'{exc}')
ValueError: <COMPRESSION.ZSTD: 50000> requires the 'imagecodecs' package
Fixed by ading imagecodecs to setup.
Error 2
typing.Self was added in Python 3.11
Fixed by requiring python >= 3.11
Change 3
All source code folders need an __init__.py file. Ideally this is empty but if not empty is ok.
Added an __init__.py to the following folders:
mapmanagercore/annotations/__init__.py
mapmanagercore/image/__init__.py
Change 3
Added to mapmanagercore/__init__.py
from ._version import __version__
Our setup.py is using a version manager which is of course complicated to understand but should work moving forward.
Important. Never add mapmanagercore/_version.py with git add as it is auto created by versioning in setup.py
Change 4
Set MapManagerCore str to all lower case in mapmanagercore/utils.py
def isMapManagerCore():
"""
Returns true if the caller is in the MapManagerCore module.
"""
frm = inspect.stack()[2]
mod = inspect.getmodule(frm[0])
if mod == None:
return False
return "mapmanagercore" in mod.__name__
Random changes
Added to .gitignore
# macOS hidden files
.AppleDouble
.DS_Store
Install
Finally, here is how the mapmanagercore package can be installed from source.
- Create and activate a conda environment named
mmc-env
conda create -y -n mmc-env python=3.11
conda activate mmc-env
- Install with pip (make sure you are in the
MapManagerCore folder)
- Verify the install
python -c "import mapmanagercore; print(mapmanagercore.__version__)"
Yields (version might be different)
How does this affect Javascript Piodide code?
This part is not done! We need to work out how to import a local pip install of mapmanagercore into the browser.
In general, we want to import mapmanager core from a local wheel
Create a wheel
python setup.py bdist_wheel
This creates dist/mapmanagercore-0.0.post9-py3-none-any.whl
Then in Javascript you do something like this
await micropip.install(serverAddress + 'mapmanagercore-0.0.post9-py3-none-any.whl');
Where serverAddress is the local address of a simple http server.
I created a cudmore-make-pip-install branch that converts the repo to allow "
pip install ." from local source.This required a few additions and changes.
First, I added some files to the root
MapManagerCorefolder including:The
setup.pyfile does the heavy lifting to allow "pip install .".Change 1
In general, source code folders are all lower case, see pep8.
Changed source code folder
MapManagerCoreto all lower casemapmanagercore.This requires all source code to use all lower case for imports, like
from mapmanagercore import MapAnnotations.Important. When merging this branch we might need to manually change the source code folder from
MapManagerCoreto all lower casemapmanagercore. This is because I am pushing from macOS and the folder name is the same and macOS does not make a distinction between same folder/file names with different cases. I think git has this same issue?Here is a snippit from pep8.
Change 2
Moved
example.ipynbintoexamples/folderand modified its import to be lowercase
import mapmanagercore.Error 1
Yields
Fixed by ading
imagecodecsto setup.Error 2
Fixed by requiring python >= 3.11
Change 3
All source code folders need an
__init__.pyfile. Ideally this is empty but if not empty is ok.Added an
__init__.pyto the following folders:Change 3
Added to
mapmanagercore/__init__.pyOur
setup.pyis using a version manager which is of course complicated to understand but should work moving forward.Important. Never add
mapmanagercore/_version.pywithgit addas it is auto created by versioning in setup.pyChange 4
Set
MapManagerCorestr to all lower case inmapmanagercore/utils.pyRandom changes
Added to
.gitignore# macOS hidden files .AppleDouble .DS_StoreInstall
Finally, here is how the
mapmanagercorepackage can be installed from source.mmc-envMapManagerCorefolder)pip install -e '.[dev]'python -c "import mapmanagercore; print(mapmanagercore.__version__)"Yields (version might be different)
How does this affect Javascript Piodide code?
This part is not done! We need to work out how to import a local pip install of mapmanagercore into the browser.
In general, we want to import mapmanager core from a local wheel
Create a wheel
This creates
dist/mapmanagercore-0.0.post9-py3-none-any.whlThen in Javascript you do something like this
Where
serverAddressis the local address of a simple http server.