Skip to content

Commit

Permalink
chakra install enhancements:
Browse files Browse the repository at this point in the history
- build and install with pip install from local source or directly from github
- use pyproject.toml to describe the project attibutes and dependecies in a declarative way
- install dependencies when installing the package
- upgrade to protobuf 4.x
- build proto file with setuptools-grpc instead of protoc; this removes the need of installing protobuf-compiler
  • Loading branch information
danmih-ixia committed Oct 7, 2023
1 parent ae7c671 commit a10d918
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
with:
activate-conda: true
python-version: 3.7
- run: conda install protobuf==3.6.1 setuptools pydot pytorch python-graphviz networkx
- run: conda install pytorch
- run: pip install fbgemm-gpu-cpu
- run: protoc et_def.proto --proto_path et_def --python_out et_def
- run: pip install .
- run: python3 setup.py install
- run: python3 -m utils.et_generator.et_generator --help
- run: python3 -m et_visualizer.et_visualizer --help
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.egg-info/
build/
*_pb2*.py*
*.pyc
18 changes: 14 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Chakra
## Installation
We use `setuptools` to install/uninstall the `chakra` package:
We use `pip` to install/uninstall the `chakra` package:
```shell
# Install package
# Install package from source
$ pip install .

# Install latest from github
$ pip install https://github.com/mlcommons/chakra/archive/refs/heads/main.zip

# Install specific revision from github
$ pip install https://github.com/mlcommons/chakra/archive/ae7c671db702eb1384015bb2618dc753eed787f2.zip

# Install as dependency from requirements.txt
$ cat requirements.txt
chakra@https://github.com/mlcommons/chakra/archive/ae7c671db702eb1384015bb2618dc753eed787f2.zip
$ pip install -r requirements.txt
$ python setup.py install

# Uninstall package
$ python -m pip uninstall chakra
$ pip uninstall chakra
```

## Execution Trace Converter (et_converter)
Expand Down
31 changes: 31 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[build-system]
requires = ["setuptools", "setuptools-grpc"]
build-backend = "setuptools.build_meta"

[project]
name = "chakra"
requires-python = ">=3.8"
version = "0.0.3"
readme = "README.md"
license = {file = "LICENSE.md"}
authors = [
{name = "MLCommons", email = "[email protected]"},
]
dependencies = ["protobuf==4.*", "graphviz", "networkx", "pydot"]

[project.urls]
Homepage = "https://github.com/mlcommons/chakra"
Documentation = "https://github.com/mlcommons/chakra/README.md"
Repository = "https://github.com/mlcommons/chakra.git"

[tool.setuptools.package-dir]
"chakra.et_def" = "et_def"
"chakra.et_converter" = "et_converter"
"chakra.et_visualizer" = "et_visualizer"
"chakra.timeline_visualizer" = "timeline_visualizer"
"chakra.et_generator" = "utils/et_generator"
"chakra.et_jsonizer" = "utils/et_jsonizer"
"chakra.third_party.utils" = "third_party/utils"

[tool.setuptools.package-data]
"chakra.et_def" = ["et_def_pb2.pyi", "et_def.proto"]
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build_grpc]
proto_files = et_def.proto
grpc_files = et_def.proto
proto_path = et_def
output_path = et_def
37 changes: 4 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,9 @@
#!/usr/bin/env python3

import os

from distutils.command.build import build
from setuptools import setup

def main():
package_base = "chakra"

# List the packages and their dir mapping:
# "install_destination_package_path": "source_dir_path"
package_dir_map = {
f"{package_base}": ".",
f"{package_base}.third_party.utils": "third_party/utils",
f"{package_base}.et_def": "et_def",
f"{package_base}.et_converter": "et_converter",
f"{package_base}.et_generator": "utils/et_generator",
f"{package_base}.et_jsonizer": "utils/et_jsonizer",
f"{package_base}.et_visualizer": "et_visualizer",
f"{package_base}.timeline_visualizer": "timeline_visualizer"
}

packages = list(package_dir_map)

os.system("protoc et_def.proto --proto_path et_def --python_out et_def")
class build_grpc(build):
sub_commands = [('build_grpc', None)] + build.sub_commands

setup(
name="chakra",
python_requires=">=3.8",
author="MLCommons",
author_email="[email protected]",
url="https://github.com/mlcommons/chakra",
packages=packages,
package_dir=package_dir_map
)

if __name__ == "__main__":
main()
setup(cmdclass={'build': build_grpc})

0 comments on commit a10d918

Please sign in to comment.