Skip to content

Commit

Permalink
Added conda recipe, setup.py, and other changes to make python packag…
Browse files Browse the repository at this point in the history
…ing possible
  • Loading branch information
DavidJVitale committed Feb 22, 2020
1 parent 95cf763 commit ac13703
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 36 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Expand Up @@ -20,5 +20,14 @@
*_i.c
*_p.c
.svn
build/windows/MS_VS2019/.vs/
build/conda/output/

cmake

OtherLanguages/Python/lerc/Lerc.dll
OtherLanguages/Python/lerc/Lerc.lib
OtherLanguages/Python/lerc/Lerc.so
/OtherLanguages/Python/build/
/OtherLanguages/Python/dist/
/OtherLanguages/Python/*.egg*
1 change: 1 addition & 0 deletions OtherLanguages/Python/lerc/__init__.py
@@ -0,0 +1 @@
from ._lerc import *
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
# Copyright 2016 - 2019 Esri
# Copyright 2016 - 2020 Esri
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,9 +38,14 @@
import numpy as np
import ctypes as ct
from timeit import default_timer as timer
import platform
import os
dir_path = os.path.dirname(os.path.realpath(__file__))

lercDll = ct.CDLL ('D:/GitHub/LercOpenSource/bin/Windows/Lerc64.dll') # windows
#lercDll = ct.CDLL ('../../bin/Linux/Lerc64.so') # linux
if platform.system() == "Windows":
lercDll = ct.CDLL (os.path.join(dir_path, 'Lerc.dll'))
if platform.system() == "Linux":
lercDll = ct.CDLL (os.path.join(dir_path, 'Lerc.so'))

#-------------------------------------------------------------------------------

Expand Down Expand Up @@ -395,10 +400,3 @@ def test():
print('------')

return result

#-------------------------------------------------------------------------------

#>>> import sys
#>>> sys.path.append('D:/GitHub/LercOpenSource/OtherLanguages/Python')
#>>> import Lerc
#>>> Lerc.test()
Empty file.
Expand Up @@ -214,11 +214,11 @@ def read_tiles(self, blob):
offset = 66 + self.m_nB
result = array.array('f', (0.0, ) * self.w * self.h)
for x, y in dloop(range(0, self.w, bw), range(0, self.h, bh)):
offset = read_block(result,
range(x, x + min(bw, self.w - x)),
range(y, y + min(bh, self.h - y)),
self.mask, self.u, self.v_maxVal,
blob, offset)
offset = read_block(result,
range(x, x + min(bw, self.w - x)),
range(y, y + min(bh, self.h - y)),
self.mask, self.u, self.v_maxVal,
blob, offset)
return result

def decode(self, blob):
Expand All @@ -240,24 +240,3 @@ def __str__(self):
s += "\n\tMask: block count {}x{}, bytes {}, maxvalue {}".format(
self.m_nbX, self.m_nbY, self.m_nB, self.m_maxVal)
return s

def main():
# world.lerc contains the world elevation in WebMercator 257x257
# with a 1 value NoData border
blob = open("world.lerc", "rb").read()
codec = lerc(blob)
data = codec.decode(blob)

# Mask can be interogated with mask.at(x,y),
assert codec.valid
assert codec.mask.at(0,0) == 0 and codec.mask.at(1, 1) == 1
assert data[74 * codec.w + 74] == 111.0
print codec

## for row in range(info.height): # Write data as CSV
## print ",".join(`data[row * info.width + column]`
## for column in range(info.width))
##

if __name__ == '__main__':
main()
31 changes: 31 additions & 0 deletions OtherLanguages/Python/setup.py
@@ -0,0 +1,31 @@
import setuptools
import os

dir_path = os.path.dirname(os.path.realpath(__file__))
readme_path = os.path.join(dir_path, "..", "..", "README.md")

try:
with open(readme_path, "r") as fh:
long_description = fh.read()
except Exception:
long_description = "Limited Error Raster Compression"


setuptools.setup(
name="lerc",
version="0.1.0",
author="esri",
author_email="python@esri.com",
description="Limited Error Raster Compression",
#long_description=long_description,
#long_description_content_type="text/markdown",
url="https://github.com/Esri/lerc",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
package_data={
"lerc":["*.dll", "*.lib", ".so"]},
python_requires='>=3.6')
10 changes: 10 additions & 0 deletions build/conda/README.md
@@ -0,0 +1,10 @@
## conda package

To build the conda package:
1. Place the appropriate compiled binaries in `/OtherLanguages/Python/lerc/`
- For windows, this is the `.lib` and `.dll` files
- For Linux, this is the `.so` files
- For OSX, this is the `.dylib` files
2. In this directory, run `conda build lerc --output-folder /some/output/folder --python 3.6` to build the python3.6 package for the architecture of your host computer
3. Repeat step 2 with `--python 3.7`, then again with `--python 3.8` (Or whatever python versions you want to release in the future)
4. Repeat steps 1-3 for the other architectures you want to release for (Windows, Linux, OSX)
2 changes: 2 additions & 0 deletions build/conda/lerc/bld.bat
@@ -0,0 +1,2 @@
"%PYTHON%" setup.py install
if errorlevel 1 exit 1
1 change: 1 addition & 0 deletions build/conda/lerc/build.sh
@@ -0,0 +1 @@
$PYTHON setup.py install
21 changes: 21 additions & 0 deletions build/conda/lerc/meta.yaml
@@ -0,0 +1,21 @@
package:
name: lerc
version: 0.1.0

requirements:
build:
- python
- setuptools
- vs2015_runtime >=14 [win]
- numpy
run:
- python
- vs2015_runtime >=14 [win]
- numpy

source:
path: ../../../OtherLanguages/Python

test:
imports:
- lerc

0 comments on commit ac13703

Please sign in to comment.