diff --git a/Makefile b/Makefile.in similarity index 75% rename from Makefile rename to Makefile.in index 19bf062..c16e989 100644 --- a/Makefile +++ b/Makefile.in @@ -1,7 +1,7 @@ C99 = $(CC) -std=c99 -CFLAGS = -g -O3 -DNDEBUG -DDONT_USE_TEST_MAIN -CPPFLAGS = -g -O3 -fpermissive -DNDEBUG -DDONT_USE_TEST_MAIN -LDLIBS = -lstdc++ -lz -lm -ltiff +CFLAGS = -g -O3 -DNDEBUG -DDONT_USE_TEST_MAIN {cflags} +CPPFLAGS = -g -O3 -fpermissive -DNDEBUG -DDONT_USE_TEST_MAIN {cppflags} +LDLIBS = -lstdc++ -lz -lm -ltiff {ldflags} default: bin bin/srtm4 bin/srtm4_which_tile diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat new file mode 100644 index 0000000..cbf296f --- /dev/null +++ b/conda-recipe/bld.bat @@ -0,0 +1 @@ +echo Windows build is not supported diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh new file mode 100644 index 0000000..50c8cfb --- /dev/null +++ b/conda-recipe/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +python setup.py install --prefix=$PREFIX diff --git a/conda-recipe/conda_build_config.yaml b/conda-recipe/conda_build_config.yaml new file mode 100644 index 0000000..e83db0c --- /dev/null +++ b/conda-recipe/conda_build_config.yaml @@ -0,0 +1,12 @@ +python: + - 3.6 + - 3.7 + - 3.8 +libtiff: + - 4.1.0 + +pin_run_as_build: + libtiff: + max_pin: x.x + python: + max_pin: x diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml new file mode 100644 index 0000000..fe6bf98 --- /dev/null +++ b/conda-recipe/meta.yaml @@ -0,0 +1,35 @@ +package: + name: srtm4 + version: "1.1.4.dev0" + +source: + git_rev: sharedlib + git_url: https://github.com/yxqd/srtm4 + +requirements: + build: + - {{ compiler('cxx') }} # [linux] + host: + - python + - libtiff + - filelock + - numpy + - requests + run: + - python + - libtiff + - filelock + - numpy + - requests + +build: + script_env: + +test: + imports: + - srtm4 + +about: + home: + license: + license_file: diff --git a/setup.py b/setup.py index b0bab4e..fc80922 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,16 @@ from setuptools import setup from setuptools.command import develop, build_py +def _createMakefile(): + template = open('Makefile.in').read() + cflags = os.environ.get('CFLAGS', '') + cppflags = os.environ.get('CPPFLAGS', '') + ldflags = os.environ.get('LDFLAGS', '') + content = template.format(**locals()) + open('Makefile', 'wt').write(content) + return +_createMakefile() + def readme(): with open('README.md', 'r', 'utf-8') as f: diff --git a/srtm4.py b/srtm4.py index 8b9dd4a..4b43cc5 100644 --- a/srtm4.py +++ b/srtm4.py @@ -26,7 +26,9 @@ if not SRTM_DIR: SRTM_DIR = os.path.join(os.path.expanduser('~'), '.srtm') -SRTM_URL = 'http://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF' +SRTM_HTTP_URL = 'http://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF' +SRTM_URL = os.environ.get('SRTM_DATA_URL', SRTM_HTTP_URL) +if SRTM_URL.endswith('/'): SRTM_URL = SRTM_URL[:-1] def _requests_retry_session( @@ -51,10 +53,28 @@ def _requests_retry_session( session.mount("https://", adapter) return session - def download(to_file, from_url): + '''download a file from the internet + + Args: + to_file: path where to store the downloaded file + from_url: url of the file to download. could be http or s3 + + Raises: + RetryError: if the `get` call exceeds the number of retries + on 5xx codes + ConnectionError: if the `get` call does not return a 200 code + NotImplementedError: if the url type is not supported + ''' + if from_url.startswith('http://') or from_url.startswith('https://'): + return _download_http(to_file, from_url) + if from_url.startswith('s3://'): + return _download_s3(to_file, from_url) + raise NotImplementedError("{} -> {}".format(from_url, to_file)) + +def _download_http(to_file, from_url): """ - Download a file from the internet. + Download a file from the internet using http. Args: to_file: path where to store the downloaded file @@ -83,6 +103,11 @@ def download(to_file, from_url): f.write(chunk) +def _download_s3(to_file, from_url): + import sh + sh.aws('s3', 'cp', from_url, to_file) + return + def get_srtm_tile(srtm_tile, out_dir): """ Download and unzip an srtm tile from the internet.