Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
43 changes: 35 additions & 8 deletions tools/azure-sdk-tools/ci_tools/parsing/parse_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
keywords: List[str],
ext_package: str,
ext_modules: List[Extension],
metapackage: bool
metapackage: bool,
):
self.name: str = name
self.version: str = version
Expand Down Expand Up @@ -109,7 +109,7 @@ def from_path(cls, parse_directory_or_file: str):
keywords,
ext_package,
ext_modules,
metapackage
metapackage,
)

def get_build_config(self) -> Optional[Dict[str, Any]]:
Expand Down Expand Up @@ -230,7 +230,9 @@ def read_setup_py_content(setup_filename: str) -> str:

def parse_setup_py(
setup_filename: str,
) -> Tuple[str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension], bool]:
) -> Tuple[
Comment thread
scbedd marked this conversation as resolved.
str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension], bool
]:
"""
Used to evaluate a setup.py (or a directory containing a setup.py) and return a tuple containing:
(
Expand Down Expand Up @@ -305,8 +307,6 @@ def setup(*args, **kwargs):
else:
metapackage = True



requires = kwargs.get("install_requires", [])
package_data = kwargs.get("package_data", None)
include_package_data = kwargs.get("include_package_data", None)
Expand Down Expand Up @@ -340,7 +340,9 @@ def setup(*args, **kwargs):

def parse_pyproject(
pyproject_filename: str,
) -> Tuple[str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension], bool]:
) -> Tuple[
str, str, str, List[str], bool, str, str, Dict[str, Any], bool, List[str], List[str], str, List[Extension], bool
]:
"""
Used to evaluate a pyproject (or a directory containing a pyproject.toml) with a [project] configuration within.
Returns a tuple containing:
Expand Down Expand Up @@ -383,7 +385,9 @@ def parse_pyproject(
else:
parsed_version = "0.0.0"
else:
raise ValueError(f"Unable to find a version value directly set in \"{pyproject_filename}\", nor is it available in a \"version.py\" or \"_version.py.\"")
raise ValueError(
f'Unable to find a version value directly set in "{pyproject_filename}", nor is it available in a "version.py" or "_version.py."'
)

name = project_config.get("name")
version = parsed_version
Expand Down Expand Up @@ -426,9 +430,32 @@ def get_version_py(setup_path: str) -> Optional[str]:
"""
Given the path to pyproject.toml or setup.py, attempts to find a (_)version.py file and return its location.
"""
# this list of directories will be excluded from the search for _version.py
# this is to avoid finding _version.py in the wrong place, such as in tests
# or in the venv directory or ANYWHERE ELSE that may mess with the parsing.
EXCLUDE = {
"venv",
"__pycache__",
"tests",
"test",
"generated_samples",
"generated_tests",
"samples",
"swagger",
"stress",
"docs",
"doc",
"local",
"scripts",
"images",
}

file_path, _ = os.path.split(setup_path)

# Find path to _version.py recursively
for root, _, files in os.walk(file_path):
for root, dirs, files in os.walk(file_path):
dirs[:] = [d for d in dirs if d not in EXCLUDE and not d.endswith(".egg-info")]

if VERSION_PY in files:
return os.path.join(root, VERSION_PY)
elif OLD_VERSION_PY in files:
Expand Down
4 changes: 2 additions & 2 deletions tools/azure-sdk-tools/ci_tools/scenario/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def create_package_and_install(
if cache_dir:
commands_options.extend(["--cache-dir", cache_dir])

target_package = ParsedSetup.from_path(setup_py_path)
Comment thread
scbedd marked this conversation as resolved.

discovered_packages = discover_packages(
setup_py_path, distribution_directory, target_setup, package_type, force_create
)

target_package = ParsedSetup.from_path(setup_py_path)

# ensure that discovered packages are always copied to the distribution directory regardless of other factors
for built_package in discovered_packages:
if os.getenv("PREBUILT_WHEEL_DIR") is not None:
Expand Down
4 changes: 2 additions & 2 deletions tools/azure-sdk-tools/ci_tools/versioning/version_set_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def version_set_dev_main() -> None:
for target_package in target_packages:
try:
new_version = get_dev_version(target_package.version, build_id)
print("{0}: {1} -> {2}".format(target_package.name, target_package.version, new_version))

print(f"Proccessing {target_package.name}.")
Comment thread
scbedd marked this conversation as resolved.
Outdated
process_requires(target_package.setup_filename, True)
set_version_py(target_package.setup_filename, new_version)
set_dev_classifier(target_package.setup_filename, new_version)
print("{0}: {1} -> {2}".format(target_package.name, target_package.version, new_version))
except:
print("Could not set dev version for package: {0}".format(target_package.name))
4 changes: 4 additions & 0 deletions tools/azure-sdk-tools/ci_tools/versioning/version_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def get_packages(
def set_version_py(setup_path, new_version):
version_py_location = get_version_py(setup_path)

if not version_py_location:
logging.error("No version.py file found in {}".format(setup_path))
Comment thread
scbedd marked this conversation as resolved.
sys.exit(1)

version_contents = ""
with open(version_py_location, "r") as version_py_file:
version_contents = version_py_file.read()
Expand Down
Loading