Raul Farkas | 428a8d5 | 2023-01-16 16:52:18 +0000 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 6 | # not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Rickard Bolin | bc6ee58 | 2022-11-04 08:24:29 +0000 | [diff] [blame] | 16 | # |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 17 | # Description: |
| 18 | # Packaging for the Vela compiler |
Michael McGeagh | 1e05afa | 2020-12-03 13:08:32 +0000 | [diff] [blame] | 19 | import os |
Michael McGeagh | 3adc1e4 | 2020-11-25 14:23:08 +0000 | [diff] [blame] | 20 | import re |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 21 | |
| 22 | from setuptools import Extension |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 23 | from setuptools import setup |
Dwight Lidman | e917cdc | 2021-05-12 18:58:05 +0200 | [diff] [blame] | 24 | from setuptools.command.build_ext import build_ext |
Raul Farkas | fcda685 | 2023-03-14 15:19:46 +0000 | [diff] [blame] | 25 | from setuptools_scm import get_version |
Dwight Lidman | e917cdc | 2021-05-12 18:58:05 +0200 | [diff] [blame] | 26 | |
| 27 | |
| 28 | class BuildExtension(build_ext): |
| 29 | def finalize_options(self): |
| 30 | build_ext.finalize_options(self) |
| 31 | import builtins |
| 32 | |
| 33 | # tell numpy it's not in setup anymore |
| 34 | builtins.__NUMPY_SETUP__ = False |
| 35 | import numpy as np |
| 36 | |
| 37 | # add the numpy headers to the mlw_codec extension |
| 38 | self.include_dirs.append(np.get_include()) |
| 39 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 40 | |
| 41 | # Read the contents of README.md file |
Michael McGeagh | 1e05afa | 2020-12-03 13:08:32 +0000 | [diff] [blame] | 42 | this_directory = os.path.abspath(os.path.dirname(__file__)) |
| 43 | with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f: |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 44 | long_description = f.read() |
Raul Farkas | fcda685 | 2023-03-14 15:19:46 +0000 | [diff] [blame] | 45 | tag = get_version() |
Michael McGeagh | 3adc1e4 | 2020-11-25 14:23:08 +0000 | [diff] [blame] | 46 | url = f"https://review.mlplatform.org/plugins/gitiles/ml/ethos-u/ethos-u-vela/+/refs/tags/{tag}/" |
Michael McGeagh | 1e05afa | 2020-12-03 13:08:32 +0000 | [diff] [blame] | 47 | # Find all markdown links that match the format: [text](link) |
| 48 | for match, link in re.findall(r"(\[.+?\]\((.+?)\))", long_description): |
| 49 | # If the link is a file that exists, replace it with the web link to the file instead |
| 50 | if os.path.exists(os.path.join(this_directory, link)): |
| 51 | url_link = match.replace(link, url + link) |
| 52 | long_description = long_description.replace(match, url_link) |
| 53 | if os.getenv("ETHOSU_VELA_DEBUG"): |
| 54 | # Verify the contents of the modifications made in a markdown renderer |
| 55 | with open(os.path.join(this_directory, "PYPI.md"), "wt", encoding="utf-8") as fout: |
| 56 | fout.write(long_description) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 57 | |
| 58 | mlw_module = Extension( |
| 59 | "ethosu.mlw_codec", |
| 60 | ["ethosu/mlw_codec/mlw_encode.c", "ethosu/mlw_codec/mlw_decode.c", "ethosu/mlw_codec/mlw_codecmodule.c"], |
Fredrik Svedberg | 93d5c35 | 2021-05-11 13:51:47 +0200 | [diff] [blame] | 61 | define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_9_API_VERSION")], |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 62 | ) |
| 63 | |
| 64 | setup( |
Tim Hall | 1793e2f | 2022-01-25 18:17:10 +0000 | [diff] [blame] | 65 | use_scm_version=True, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 66 | long_description=long_description, |
| 67 | long_description_content_type="text/markdown", |
Louis Verhaard | d700252 | 2021-01-20 17:23:54 +0100 | [diff] [blame] | 68 | ext_modules=[mlw_module], |
Jonas Ohlsson | 845e232 | 2022-03-01 12:39:55 +0100 | [diff] [blame] | 69 | cmdclass={"build_ext": BuildExtension}, # type: ignore[dict-item] |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 70 | ) |