-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = '0.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cmake | ||
packaging | ||
setuptools>=49.4.0 | ||
torch | ||
wheel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
# -------------------------------------------------------------------------- | ||
|
||
import os | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from setuptools import Command, Extension, find_packages, setup | ||
from setuptools.command.build_ext import build_ext | ||
|
||
cur_path = Path(__file__).parent | ||
|
||
|
||
def get_requirements(): | ||
"""Get Python package dependencies from requirements.txt.""" | ||
with open(cur_path / "requirements.txt") as f: | ||
requirements = f.read().strip().split("\n") | ||
requirements = [req for req in requirements if "https" not in req] | ||
return requirements | ||
|
||
|
||
class CMakeExtension(Extension): | ||
""" specify the root folder of the CMake projects""" | ||
|
||
def __init__(self, name, cmake_lists_dir=".", **kwargs): | ||
Extension.__init__(self, name, sources=[], **kwargs) | ||
self.cmake_lists_dir = os.path.abspath(cmake_lists_dir) | ||
|
||
|
||
class CMakeBuildExt(build_ext): | ||
"""launches the CMake build.""" | ||
|
||
def build_extension(self, ext: CMakeExtension) -> None: | ||
# Ensure that CMake is present and working | ||
try: | ||
subprocess.check_output(["cmake", "--version"]) | ||
except OSError: | ||
raise RuntimeError("Cannot find CMake executable") from None | ||
|
||
debug = int( | ||
os.environ.get("DEBUG", 0) | ||
) if self.debug is None else self.debug | ||
cfg = "Debug" if debug else "Release" | ||
|
||
parallel_level = os.environ.get("CMAKE_BUILD_PARALLEL_LEVEL", None) | ||
if parallel_level is not None: | ||
self.parallel = int(parallel_level) | ||
else: | ||
self.parallel = os.cpu_count() | ||
|
||
for ext in self.extensions: | ||
extdir = os.path.abspath( | ||
os.path.dirname(self.get_ext_fullpath(ext.name)) | ||
) | ||
|
||
cmake_args = [ | ||
"-DCMAKE_BUILD_TYPE=%s" % cfg, | ||
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format( | ||
cfg.upper(), extdir | ||
), "-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}".format( | ||
cfg.upper(), self.build_temp | ||
) | ||
] | ||
|
||
# Adding CMake arguments set as environment variable | ||
if "CMAKE_ARGS" in os.environ: | ||
cmake_args += [ | ||
item for item in os.environ["CMAKE_ARGS"].split(" ") if item | ||
] | ||
|
||
if not os.path.exists(self.build_temp): | ||
os.makedirs(self.build_temp) | ||
|
||
build_args = [] | ||
build_args += ["--config", cfg] | ||
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level | ||
# across all generators. | ||
if ( | ||
"CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ and | ||
hasattr(self, "parallel") and self.parallel | ||
): | ||
build_args += [f"-j{self.parallel}"] | ||
|
||
build_temp = Path(self.build_temp) / ext.name | ||
if not build_temp.exists(): | ||
build_temp.mkdir(parents=True) | ||
|
||
# Config | ||
subprocess.check_call(["cmake", ext.cmake_lists_dir] + cmake_args, | ||
cwd=self.build_temp) | ||
|
||
# Build | ||
subprocess.check_call(["cmake", "--build", "."] + build_args, | ||
cwd=self.build_temp) | ||
|
||
|
||
class clean(Command): | ||
user_options = [] | ||
|
||
def initialize_options(self): | ||
pass | ||
|
||
def finalize_options(self): | ||
pass | ||
|
||
def run(self): | ||
import glob | ||
import re | ||
import shutil | ||
|
||
with open(".gitignore") as f: | ||
ignores = f.read() | ||
pat = re.compile(r"^#( BEGIN NOT-CLEAN-FILES )?") | ||
for wildcard in filter(None, ignores.split("\n")): | ||
match = pat.match(wildcard) | ||
if match: | ||
if match.group(1): | ||
# Marker is found and stop reading .gitignore. | ||
break | ||
# Ignore lines which begin with '#'. | ||
else: | ||
# Don't remove absolute paths from the system | ||
wildcard = wildcard.lstrip("./") | ||
|
||
for filename in glob.glob(wildcard): | ||
print(f"cleaning '{filename}'") | ||
try: | ||
os.remove(filename) | ||
except OSError: | ||
shutil.rmtree(filename, ignore_errors=True) | ||
|
||
|
||
description = ("TileFusion: A Python wrapper for tilefusion C++ library.") | ||
|
||
with open(os.path.join("pytilefusion", '__version__.py')) as f: | ||
exec(f.read()) | ||
|
||
setup( | ||
name="tilefusion", | ||
python_requires=">=3.10", | ||
packages=find_packages(exclude=[""]), | ||
install_requires=get_requirements(), | ||
version=__version__, # noqa F821 | ||
description=description, | ||
ext_modules=[CMakeExtension("tilefusion")], | ||
cmdclass={ | ||
"build_ext": CMakeBuildExt, | ||
"clean": clean, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters