forked from openvinotoolkit/nncf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pyproject.toml (openvinotoolkit#2981)
### Changes Use pyproject.toml instead of setup.py ### Reason for changes - [PEP 517/518](https://peps.python.org/pep-0517/#source-trees) - Tools like Black, Isort, Ruff, and Mypy can automatically use settings defined in a pyproject.toml file, allowing these tools to apply configurations directly from the repository without requiring additional configuration in text editor or extra arguments in terminal. ### Tests nightly/job/install_onnx/543/ nightly/job/install_ov/567/ nightly/job/install_pt_cpu/566/ nightly/job/ubuntu20_install_tf/672/
- Loading branch information
1 parent
8ef38ec
commit e81a1a3
Showing
17 changed files
with
280 additions
and
260 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
This file was deleted.
Oops, something went wrong.
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,114 @@ | ||
# Copyright (c) 2024 Intel Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
Dynamic Version Generation for Package Builds | ||
This module is responsible for generating the dynamic version for the package during the build process. | ||
It provides the `version` attribute for setuptools as specified in the `pyproject.toml` configuration file: | ||
[tool.setuptools.dynamic] | ||
version = { attr = "_version_helper.version" } | ||
Environment Variable Instructions: | ||
----------------------------------- | ||
1. **NNCF_RELEASE_BUILD**: | ||
- Set this environment variable to generate a release package using `python -m build` without including | ||
the commit hash in the version. | ||
- If this variable is not set, the file `nncf/version.py` will be overridden with a custom version | ||
that includes the commit hash. Example usage: | ||
NNCF_RELEASE_BUILD=1 python -m build | ||
2. **NNCF_BUILD_SUFFIX**: | ||
- Use this environment variable to specify a particular suffix for the build. Example usage: | ||
NNCF_BUILD_SUFFIX="rc1" python -m build | ||
Post-Build Recommendation: | ||
--------------------------- | ||
After generating the package, it is recommended to revert any changes to `nncf/version.py` to avoid potential conflicts. | ||
This can be done using the following command: | ||
git checkout nncf/version.py | ||
This ensures that `nncf/version.py` remains in its original state after the dynamic versioning process. | ||
""" | ||
|
||
|
||
from __future__ import annotations | ||
|
||
import contextlib | ||
import os | ||
import re | ||
import subprocess | ||
from pathlib import Path | ||
|
||
NNCF_VERSION_FILE = "nncf/version.py" | ||
|
||
|
||
def get_custom_version() -> str: | ||
version_match = re.search( | ||
r"^__version__ = ['\"]((\d+\.\d+\.\d+)([^'\"]*))['\"]", Path(NNCF_VERSION_FILE).read_text(), re.M | ||
) | ||
if not version_match: | ||
raise RuntimeError("Unable to find version string.") | ||
|
||
version_full = version_match.group(1) | ||
version_value = version_match.group(2) | ||
version_suffix = version_match.group(3) | ||
|
||
nncf_build_suffix = os.environ.get("NNCF_BUILD_SUFFIX") | ||
if nncf_build_suffix: | ||
# Suffix expected on build package | ||
return f"{version_value}.{nncf_build_suffix}" | ||
|
||
is_building_release = "NNCF_RELEASE_BUILD" in os.environ | ||
if is_building_release or version_suffix: | ||
return version_full | ||
|
||
dev_version_id = "unknown_version" | ||
repo_root = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
# Get commit hash | ||
with contextlib.suppress(subprocess.CalledProcessError): | ||
dev_version_id = ( | ||
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], cwd=repo_root).strip().decode() # nosec | ||
) | ||
|
||
# Detect modified files | ||
with contextlib.suppress(subprocess.CalledProcessError): | ||
run = subprocess.run(["git", "diff-index", "--quiet", "HEAD"], cwd=repo_root) # nosec | ||
if run.returncode == 1: | ||
dev_version_id += "dirty" | ||
|
||
return version_value + f".dev0+{dev_version_id}" | ||
|
||
|
||
version: str | ||
|
||
|
||
def __getattr__(name: str) -> str: | ||
|
||
if name == "version": | ||
global version | ||
version = get_custom_version() | ||
|
||
# Rewrite version.py to pass custom version to package | ||
if os.environ.get("_PYPROJECT_HOOKS_BUILD_BACKEND"): | ||
content = Path(NNCF_VERSION_FILE).read_text() | ||
version_str = re.search(r"^__version__ = ['\"][^'\"]*['\"]", content, re.M).group(0) | ||
content = content.replace(version_str, f'__version__ = "{version}"') | ||
Path(NNCF_VERSION_FILE).write_text(content) | ||
|
||
return version | ||
|
||
raise AttributeError(name) |
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 was deleted.
Oops, something went wrong.
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,151 @@ | ||
[build-system] | ||
requires = ["setuptools>=61.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "nncf" | ||
description = "Neural Networks Compression Framework" | ||
readme="docs/PyPiPublishing.md" | ||
license = { text = "Apache-2.0" } | ||
authors = [{ name = "Intel" }, { email = "alexander.kozlov@intel.com" }] | ||
requires-python = ">=3.8" | ||
dynamic = ["version"] | ||
keywords = [ | ||
"bert", | ||
"classification", | ||
"compression", | ||
"hawq", | ||
"mixed-precision-training", | ||
"mmdetection", | ||
"nas", | ||
"nlp", | ||
"object-detection", | ||
"pruning", | ||
"quantization", | ||
"quantization-aware-training", | ||
"semantic-segmentation", | ||
"sparsity", | ||
"transformers", | ||
] | ||
classifiers = [ | ||
"License :: OSI Approved :: Apache Software License", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python :: 3", | ||
] | ||
dependencies = [ | ||
"jsonschema>=3.2.0", | ||
"jstyleson>=0.0.2", | ||
"natsort>=7.1.0", | ||
"networkx>=2.6, <=3.3", | ||
"ninja>=1.10.0.post2, <1.12", | ||
"numpy>=1.19.1, <1.27", | ||
"openvino-telemetry>=2023.2.0", | ||
"packaging>=20.0", | ||
"pandas>=1.1.5,<2.3", | ||
"psutil", | ||
"pydot>=1.4.1, <3.0.0", | ||
"pymoo>=0.6.0.1", | ||
"rich>=13.5.2", | ||
"scikit-learn>=0.24.0", | ||
"scipy>=1.3.2", | ||
"tabulate>=0.9.0", | ||
"tqdm>=4.54.1", | ||
] | ||
|
||
[project.optional-dependencies] | ||
plots = [ | ||
"kaleido>=0.2.1", | ||
"matplotlib>=3.3.4, <3.6", | ||
"pillow>=9.0.0", | ||
"plotly-express>=0.4.1", | ||
] | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/openvinotoolkit/nncf" | ||
|
||
[tool.setuptools.dynamic] | ||
version = { attr = "custom_version.version" } | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["."] | ||
exclude = ["tests", "tests.*", "examples", "examples.*", "tools", "tools.*"] | ||
namespaces = false | ||
|
||
[tool.black] | ||
line-length = 120 | ||
|
||
[tool.md_dead_link_check] | ||
exclude_files = ["ReleaseNotes.md"] | ||
|
||
[tool.isort] | ||
line_length = 120 | ||
force_single_line = true | ||
profile = "black" | ||
single_line_exclusions = "typing" | ||
skip_glob = "examples/post_training_quantization/torch/ssd300_vgg16/main.py" | ||
|
||
[tool.mypy] | ||
follow_imports = "silent" | ||
strict = true | ||
# should be removed later | ||
# mypy recommends the following tool as an autofix: | ||
# https://github.com/hauntsaninja/no_implicit_optional | ||
implicit_optional = true | ||
files = [ | ||
"nncf/common/sparsity", | ||
"nncf/common/graph", | ||
"nncf/common/accuracy_aware_training/", | ||
"nncf/common/utils/", | ||
"nncf/common/tensor_statistics", | ||
"nncf/experimental/torch2", | ||
] | ||
|
||
[tool.ruff] | ||
line-length = 120 | ||
exclude = ["nncf/tensorflow/__init__.py"] | ||
|
||
[tool.ruff.lint] | ||
preview = true | ||
ignore-init-module-imports = true | ||
ignore = [ | ||
"E201", # whitespace-after-open-bracket | ||
"E203", # whitespace-before-punctuation | ||
"E231", # missing-whitespace | ||
"E251", # unexpected-spaces-around-keyword-parameter-equals | ||
"E731", # lambda-assignment | ||
"SIM108", # if-else-block-instead-of-if-exp | ||
"SIM110", # reimplemented-builtin | ||
"SIM117", # multiple-with-statements | ||
"SIM103", # needless-bool | ||
"NPY002", # numpy-legacy-random | ||
] | ||
select = [ | ||
"E", # pycodestyle rules | ||
"F", # pyflakes rules | ||
"CPY001", # copyright check | ||
"NPY", # numpy rules | ||
] | ||
extend-select = [ | ||
"SIM", # https://pypi.org/project/flake8-simplify | ||
] | ||
|
||
[tool.ruff.lint.per-file-ignores] | ||
"nncf/experimental/torch/nas/bootstrapNAS/__init__.py" = ["F401"] | ||
"nncf/torch/__init__.py" = ["F401", "E402"] | ||
"tests/**/*.py" = ["F403"] | ||
"tests/**/__init__.py" = ["F401"] | ||
"examples/**/*.py" = ["F403"] | ||
|
||
[tool.ruff.lint.flake8-copyright] | ||
notice-rgx = """\ | ||
# Copyright \\(c\\) (\\d{4}|\\d{4}-\\d{4}) Intel Corporation | ||
# Licensed under the Apache License, Version 2.0 \\(the "License"\\); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" |
Oops, something went wrong.