Changeset View
Changeset View
Standalone View
Standalone View
setup.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from distutils.cmd import Command | from distutils.cmd import Command | ||||
from distutils.command.build import build | |||||
from io import open | from io import open | ||||
from os import environ, path, system | from os import environ, path, system | ||||
from setuptools import find_packages, setup | from setuptools import find_packages, setup | ||||
from setuptools.command.build_py import build_py | |||||
from setuptools.command.sdist import sdist | |||||
here = path.abspath(path.dirname(__file__)) | here = path.abspath(path.dirname(__file__)) | ||||
# Get the long description from the README file | # Get the long description from the README file | ||||
with open(path.join(here, "README.md"), encoding="utf-8") as f: | with open(path.join(here, "README.md"), encoding="utf-8") as f: | ||||
long_description = f.read() | long_description = f.read() | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | class TSBuildCommand(TSCommand): | ||||
def run(self): | def run(self): | ||||
self.run_command("ts_build_so") | self.run_command("ts_build_so") | ||||
self.run_command("ts_build_wasm") | self.run_command("ts_build_wasm") | ||||
class TSBuildExportCommand(TSCommand): | class TSBuildExportCommand(TSCommand): | ||||
description = "Builds swh_ql.so and swh_ql.wasm and exports them to static/" | description = "Builds swh_ql.so and swh_ql.wasm and exports them to static/" | ||||
def initialize_options(self): | |||||
self.build_lib = None | |||||
super().initialize_options() | |||||
def finalize_options(self): | |||||
self.set_undefined_options("build", ("build_lib", "build_lib")) | |||||
super().finalize_options() | |||||
def run(self): | def run(self): | ||||
self.run_command("ts_install") | self.run_command("ts_install") | ||||
self.run_command("ts_build") | self.run_command("ts_build") | ||||
system("echo 'static files generated. copying them to static/ dir'") | system("echo 'static files generated. copying them to package dir'") | ||||
system("mkdir static") | system(f"cp query_language/swh_ql.so {self.build_lib}/swh/search/swh_ql.so") | ||||
system("cp query_language/swh_ql.so static/swh_ql.so") | system(f"cp query_language/swh_ql.wasm {self.build_lib}/swh/search/swh_ql.wasm") | ||||
system("cp query_language/swh_ql.wasm static/swh_ql.wasm") | |||||
class custom_build(build): | class custom_build(build_py): | ||||
def run(self): | def run(self): | ||||
super().run() | |||||
if not self.dry_run: | if not self.dry_run: | ||||
self.run_command("ts_build_export") | self.run_command("ts_build_export") | ||||
super().run() | |||||
class custom_sdist(sdist): | |||||
def make_release_tree(self, base_dir, files): | |||||
super().make_release_tree(base_dir, files) | |||||
# TODO: build the .c file and .wasm but not .so, because it's architecture- | |||||
# dependent, and shouldn't be in a sdist (aka *source* distribution) | |||||
if not self.dry_run: | |||||
self.run_command("ts_install") | |||||
self.run_command("ts_build") | |||||
system("echo 'static files generated. copying them to package dir'") | |||||
system(f"cp query_language/swh_ql.so {base_dir}/swh/search/swh_ql.so") | |||||
system(f"cp query_language/swh_ql.wasm {base_dir}/swh/search/swh_ql.wasm") | |||||
setup( | setup( | ||||
name="swh.search", | name="swh.search", | ||||
description="Software Heritage search service", | description="Software Heritage search service", | ||||
long_description=long_description, | long_description=long_description, | ||||
long_description_content_type="text/markdown", | long_description_content_type="text/markdown", | ||||
python_requires=">=3.7", | python_requires=">=3.7", | ||||
Show All 20 Lines | setup( | ||||
], | ], | ||||
project_urls={ | project_urls={ | ||||
"Bug Reports": "https://forge.softwareheritage.org/maniphest", | "Bug Reports": "https://forge.softwareheritage.org/maniphest", | ||||
"Funding": "https://www.softwareheritage.org/donate", | "Funding": "https://www.softwareheritage.org/donate", | ||||
"Source": "https://forge.softwareheritage.org/source/swh-search", | "Source": "https://forge.softwareheritage.org/source/swh-search", | ||||
"Documentation": "https://docs.softwareheritage.org/devel/swh-search/", | "Documentation": "https://docs.softwareheritage.org/devel/swh-search/", | ||||
}, | }, | ||||
cmdclass={ | cmdclass={ | ||||
"build": custom_build, | "build_py": custom_build, | ||||
"sdist": custom_sdist, | |||||
"ts_install": TSInstallCommand, | "ts_install": TSInstallCommand, | ||||
"ts_generate": TSGenerateCommand, | "ts_generate": TSGenerateCommand, | ||||
"ts_build_so": TSBuildSoCommand, | "ts_build_so": TSBuildSoCommand, | ||||
"ts_build_wasm": TSBuildWasmCommand, | "ts_build_wasm": TSBuildWasmCommand, | ||||
"ts_build": TSBuildCommand, | "ts_build": TSBuildCommand, | ||||
"ts_build_export": TSBuildExportCommand, | "ts_build_export": TSBuildExportCommand, | ||||
}, | }, | ||||
data_files=[("share/swh/search", ["static/swh_ql.so", "static/swh_ql.wasm"])], | zip_safe=False, | ||||
) | ) |