Skip to content

Commit

Permalink
[PyOV] Migrate from direct setup.py calls in Benchmark App and Docs CI (
Browse files Browse the repository at this point in the history
openvinotoolkit#27220)

### Details:
 - Remove direct `setup.py` calls from comments in cmake files
 - Change the docs building command in GHA
- Migrate Benchmark App wheel building command to use `python -m pip
wheel .`
- Since `openvino_dev` is deprecated and set to be removed soon anyway,
the `constraints.txt` file has been unpinned from Benchmark App
requirements. In my opinion this simplifies the code significantly with
no drawbacks, because `numpy` version for benchmark_app (the only
dependency) is not even specified in `constraints.txt`, which will soon
be removed.


### Tickets:
 - CVS-155956
 - CVS-155957

---------

Co-authored-by: Ilya Lavrenov <[email protected]>
  • Loading branch information
p-wysocki and ilya-lavrenov authored Oct 28, 2024
1 parent de5f765 commit 6f001e9
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Install python dependencies
run: |
python3 -m pip install -r docs/requirements.txt
(cd docs/openvino_sphinx_theme && python3 setup.py install)
(cd docs/openvino_sphinx_theme && python3 -m pip install .)
python3 -m pip install docs/openvino_custom_sphinx_sitemap
- name: Download and install doxygen
Expand Down
4 changes: 2 additions & 2 deletions cmake/developer_package/packaging/common-libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ macro(ov_common_libraries_cpack_set_dirs)

ov_get_pyversion(pyversion)
if(pyversion)
# should not be used in production; only by setup.py install
# should not be used in production; only by pip install
set(OV_CPACK_PYTHONDIR lib/${pyversion}/site-packages)
endif()

Expand Down Expand Up @@ -94,7 +94,7 @@ macro(ov_define_component_include_rules)
set(OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL EXCLUDE_FROM_ALL)
set(OV_CPACK_COMP_BENCHMARK_APP_EXCLUDE_ALL ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL})
set(OV_CPACK_COMP_OVC_EXCLUDE_ALL ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL})
# we don't pack artifacts of setup.py install, because it's called explicitly in conda / brew
# we don't pack artifacts of pip install, because it's called explicitly in conda / brew
# or not used at all like in cases with conan / vcpkg
set(OV_CPACK_COMP_PYTHON_OPENVINO_PACKAGE_EXCLUDE_ALL ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL})
# we don't need wheels in the distribution packages
Expand Down
4 changes: 2 additions & 2 deletions cmake/developer_package/packaging/debian/debian.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ macro(ov_define_component_include_rules)
endif()
# python
if(ENABLE_PYTHON_PACKAGING)
# pack artifacts of setup.py install
# pack artifacts of pip install
unset(OV_CPACK_COMP_PYTHON_OPENVINO_PACKAGE_EXCLUDE_ALL)
else()
set(OV_CPACK_COMP_PYTHON_OPENVINO_PACKAGE_EXCLUDE_ALL EXCLUDE_FROM_ALL)
endif()
# we don't pack python components itself, we pack artifacts of setup.py install
# we don't pack python components itself, we pack artifacts of pip install
set(OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL EXCLUDE_FROM_ALL)
set(OV_CPACK_COMP_BENCHMARK_APP_EXCLUDE_ALL ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL})
set(OV_CPACK_COMP_OVC_EXCLUDE_ALL ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL})
Expand Down
4 changes: 2 additions & 2 deletions cmake/developer_package/packaging/rpm/rpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ macro(ov_define_component_include_rules)
endif()
# python
if(ENABLE_PYTHON_PACKAGING)
# pack artifacts of setup.py install
# pack artifacts of pip install
unset(OV_CPACK_COMP_PYTHON_OPENVINO_PACKAGE_EXCLUDE_ALL)
else()
set(OV_CPACK_COMP_PYTHON_OPENVINO_PACKAGE_EXCLUDE_ALL EXCLUDE_FROM_ALL)
endif()
# we don't pack python components itself, we pack artifacts of setup.py install
# we don't pack python components itself, we pack artifacts of pip install
set(OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL EXCLUDE_FROM_ALL)
set(OV_CPACK_COMP_BENCHMARK_APP_EXCLUDE_ALL ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL})
set(OV_CPACK_COMP_OVC_EXCLUDE_ALL ${OV_CPACK_COMP_PYTHON_OPENVINO_EXCLUDE_ALL})
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation_build_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ source env/bin/activate
```
5. Install the sphinx theme
```
(env) $ cd docs/openvino_sphinx_theme && python setup.py install && cd -
(env) $ python -m pip install docs/openvino_sphinx_theme
``````
6. Install the custom sphinx sitemap
```
Expand Down
3 changes: 2 additions & 1 deletion docs/openvino_sphinx_theme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

1. Install the `openvino_sphinx_theme` using `python`:
```
python setup.py install --user
cd openvino/docs/openvino_sphinx_theme
python -m pip install --user .
```

2. Update the `html_theme` variable in your `conf.py`:
Expand Down
1 change: 0 additions & 1 deletion tools/benchmark_tool/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
-c ../constraints.txt
numpy>=1.16.6,<2.1.0
87 changes: 7 additions & 80 deletions tools/benchmark_tool/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,18 @@
"""
Use this script to create a wheel with OpenVINO™ Python* tools:
$ python setup.py sdist bdist_wheel
$ python -m pip wheel .
"""
import pkg_resources
import re
from setuptools import setup, find_packages
from pathlib import Path
from typing import Dict, List


with open('requirements.txt', 'r', encoding='utf-8') as f:
raw_contents = f.readlines()
reqs = [line.strip() for line in raw_contents]

with open('README.md', 'r', encoding='utf-8') as f:
long_description = f.read()


def read_constraints(path: str='../constraints.txt') -> Dict[str, List[str]]:
"""
Read a constraints.txt file and return a dict
of {package_name: [required_version_1, required_version_2]}.
The dict values are a list because a package can be mentioned
multiple times, for example:
mxnet~=1.2.0; sys_platform == 'win32'
mxnet>=1.7.0; sys_platform != 'win32'
"""
constraints = {}
with open(Path(__file__).resolve().parent / path) as f:
raw_constraints = f.readlines()
for line in raw_constraints:
# skip comments
if line.startswith('#'):
continue
line = line.replace('\n', '')
# read constraints for that package
package, delimiter, constraint = re.split('(~|=|<|>|;)', line, maxsplit=1)
# if there is no entry for that package, add it
if constraints.get(package) is None:
constraints[package] = [delimiter + constraint]
# else add another entry for that package
else:
constraints[package].extend([delimiter + constraint])
return constraints


def read_requirements(path: str) -> List[str]:
"""
Read a requirements.txt file and return a list
of requirements. Three cases are supported, the
list corresponds to priority:
1. version specified in requirements.txt
2. version specified in constraints.txt
3. version unbound
Putting environment markers into constraints.txt is prone to bugs.
They should be specified in requirements.txt files.
"""
requirements = []
constraints = read_constraints()
with open(Path(__file__).resolve().parent / path) as f:
raw_requirements = f.readlines()
for line in raw_requirements:
# skip comments and constraints link
if line.startswith(('#', '-c')):
continue
# get rid of newlines
line = line.replace('\n', '')
# if version is specified (non-word chars present)
package_constraint = constraints.get(line.split(';')[0])
if re.search('(~|=|<|>)', line) and len(line.split(';'))>1:
if package_constraint: # both markers and versions specified
marker_index = line.find(";")
# insert package version between package name and environment markers
line = line[:marker_index] \
+ ",".join([constraint for constraint in package_constraint]) \
+ line[marker_index:]
requirements.append(line)
# else get version from constraints
else:
constraint = constraints.get(line)
# if version found in constraints.txt
if constraint:
for marker in constraint:
requirements.append(line+marker)
# else version is unbound
else:
requirements.append(line)
return requirements


setup(
name='benchmark_tool',
version='0.0.0',
Expand All @@ -111,6 +37,7 @@ def read_requirements(path: str) -> List[str]:
'Operating System :: OS Independent',
],
packages=find_packages(),
install_requires=read_requirements('requirements.txt'),
install_requires=reqs,
data_files=[('.', ['requirements.txt'])],
python_requires='>=3.9',
)

0 comments on commit 6f001e9

Please sign in to comment.