Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyproject.toml #2981

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: Install mypy
run: pip install mypy==1.8.0
- name: Run mypy
run: mypy --install-types --config-file=.mypy.ini --non-interactive
run: mypy --install-types --non-interactive
3 changes: 1 addition & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ jobs:
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: AlexanderDokuchaev/md-dead-link-check@cc3ed55268899a1a6d5fd7068abbc4591eab1f74 # v0.9
with:
config: md_dead_link_check.toml

3 changes: 1 addition & 2 deletions .github/workflows/pre-commit-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ jobs:
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: AlexanderDokuchaev/md-dead-link-check@cc3ed55268899a1a6d5fd7068abbc4591eab1f74 # v0.9
with:
config: md_dead_link_check.toml

3 changes: 2 additions & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ jobs:
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
NNCF_RELEASE_BUILD: "1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes need to be placed in our release procedure documentation.

run: |
python -m build -C--global-option=--release
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no way to pass global option to control format of version, that used env variable instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more convenient to pass this option into CLI.

python -m build

# Disallow uploading dev packages
for file in dist/*; do
Expand Down
6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

9 changes: 0 additions & 9 deletions .mypy.ini

This file was deleted.

1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repos:
hooks:
- id: black
files: '^.*\.py'
args: ["--line-length", "120"]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ graft nncf/common/hardware/configs
include LICENSE
include licensing/third-party-programs.txt
include docs/PyPiPublishing.md
include _version_helper.py
73 changes: 73 additions & 0 deletions _version_helper.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my perspective, it is not correct to place helper-like files named with _ at the root of the project.
@alexsu52, @AlexKoff88, could you please comment on this?

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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.


# NOTE 1: This module generates the dynamic version for the package during the build process.
# It provides the version attribute for setuptools as specified in pyproject.toml:
# [tool.setuptools.dynamic]
# version = { attr = "_version_helper.version" }
Comment on lines +13 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct NOTE and behaviour in general, since trying to build without the NNCF_RELEASE_BUILD variable leads to incorrect file naming:
image
Need to be fixed despite the fact that this issue exists on the develop.


# NOTE 2: To generate a release package without including the commit hash in the version,
# set the NNCF_RELEASE_BUILD environment variable.

from __future__ import annotations

import contextlib
import os
import re
from pathlib import Path

NNCF_VERSION_FILE = "nncf/version.py"


def get_custom_version() -> str:
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", Path(NNCF_VERSION_FILE).read_text(), re.M)
if not version_match:
raise RuntimeError("Unable to find version string.")
version_value = version_match.group(1)
is_building_release = "NNCF_RELEASE_BUILD" in os.environ

if not is_building_release:

import subprocess # nosec

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) # nosec
.strip()
.decode()
)

# Detect modified files
with contextlib.suppress(subprocess.CalledProcessError):
repo_root = os.path.dirname(os.path.realpath(__file__))
run = subprocess.run(["git", "diff-index", "--quiet", "HEAD"], cwd=repo_root) # nosec
if run.returncode == 1:
dev_version_id += "dirty"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detect editable mode pip install -e is not possible to check here, instead of it add dirty suffix if code was modified.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous editable suffix was more correct.


return version_value + f".dev0+{dev_version_id}"

return version_value


version: str


def __getattr__(name: str) -> str:
if name == "version":
global version
version = get_custom_version()
return version
raise AttributeError(name)
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def _mobilenet_v3_model(
last_channel: int,
pretrained: bool,
progress: bool,
**kwargs: Any
**kwargs: Any,
):
model = MobileNetV3(inverted_residual_setting, last_channel, **kwargs)
if pretrained:
Expand Down
2 changes: 0 additions & 2 deletions md_dead_link_check.toml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def __init__(
base_lr: float,
num_epochs: float,
warmup_epochs: float = 0,
warmup_lr: float = 3.4e-4
warmup_lr: float = 3.4e-4,
):
super().__init__(optimizer, num_steps_in_epoch)
self._base_lr = base_lr
Expand Down
150 changes: 150 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
[build-system]
requires = ["setuptools>=61.0"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the recommended setuptools version was bupmed?

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 = "_version_helper.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",
]

[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.
"""
49 changes: 0 additions & 49 deletions ruff.toml

This file was deleted.

Loading
Loading