Files
pytorch/tools/code_coverage/package/util/setting.py
Xuehai Pan 0314c4c101 [BE][Easy] use pathlib.Path instead of dirname / ".." / pardir (#129374)
Changes by apply order:

1. Replace all `".."` and `os.pardir` usage with `os.path.dirname(...)`.
2. Replace nested `os.path.dirname(os.path.dirname(...))` call with `str(Path(...).parent.parent)`.
3. Reorder `.absolute()` ~/ `.resolve()`~ and `.parent`: always resolve the path first.

    `.parent{...}.absolute()` -> `.absolute().parent{...}`

4. Replace chained `.parent x N` with `.parents[${N - 1}]`: the code is easier to read (see 5.)

    `.parent.parent.parent.parent` -> `.parents[3]`

5. ~Replace `.parents[${N - 1}]` with `.parents[${N} - 1]`: the code is easier to read and does not introduce any runtime overhead.~

    ~`.parents[3]` -> `.parents[4 - 1]`~

6. ~Replace `.parents[2 - 1]` with `.parent.parent`: because the code is shorter and easier to read.~

Pull Request resolved: https://github.com/pytorch/pytorch/pull/129374
Approved by: https://github.com/justinchuby, https://github.com/malfet
2024-06-25 08:28:38 +00:00

67 lines
1.5 KiB
Python

import os
from enum import Enum
from pathlib import Path
from typing import Dict, List, Set
# <project folder>
HOME_DIR = os.environ["HOME"]
TOOLS_FOLDER = str(Path(__file__).resolve().parents[2])
# <profile folder>
PROFILE_DIR = os.path.join(TOOLS_FOLDER, "profile")
JSON_FOLDER_BASE_DIR = os.path.join(PROFILE_DIR, "json")
MERGED_FOLDER_BASE_DIR = os.path.join(PROFILE_DIR, "merged")
SUMMARY_FOLDER_DIR = os.path.join(PROFILE_DIR, "summary")
# <log path>
LOG_DIR = os.path.join(PROFILE_DIR, "log")
# test type, DO NOT change the name, it should be consistent with [buck query --output-attribute] result
class TestType(Enum):
CPP: str = "cxx_test"
PY: str = "python_test"
class Test:
name: str
target_pattern: str
test_set: str # like __aten__
test_type: TestType
def __init__(
self, name: str, target_pattern: str, test_set: str, test_type: TestType
) -> None:
self.name = name
self.target_pattern = target_pattern
self.test_set = test_set
self.test_type = test_type
TestList = List[Test]
TestStatusType = Dict[str, Set[str]]
# option
class Option:
need_build: bool = False
need_run: bool = False
need_merge: bool = False
need_export: bool = False
need_summary: bool = False
need_pytest: bool = False
# test platform
class TestPlatform(Enum):
FBCODE: str = "fbcode"
OSS: str = "oss"
# compiler type
class CompilerType(Enum):
CLANG: str = "clang"
GCC: str = "gcc"