Skip to content

Commit

Permalink
update the tests so that they should pass
Browse files Browse the repository at this point in the history
  • Loading branch information
scbedd committed Oct 18, 2024
1 parent dd85116 commit 05dbbb5
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 46 deletions.
2 changes: 1 addition & 1 deletion eng/ci_tools.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# requirements leveraged by ci tools
setuptools==72.2.0
setuptools==74.1.3
virtualenv==20.25.1
wheel==0.43.0
packaging==23.1
Expand Down
2 changes: 1 addition & 1 deletion eng/conda_test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trio
typing_extensions>=3.7.2
cryptography
adal
setuptools==72.2.0
setuptools==74.1.3
pytest-asyncio==0.12.0
-e sdk/core/azure-core/tests/testserver_tests/coretestserver
azure-mgmt-storage
2 changes: 1 addition & 1 deletion eng/pipelines/templates/jobs/tests-nightly-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
export PATH=~/.local/bin:$PATH
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
python3 -m pip install setuptools==72.2.0 wheel
python3 -m pip install setuptools==74.1.3 wheel
python3 -m pip install tox packaging twine beautifulsoup4
python3 --version
cd $(Build.SourcesDirectory)
Expand Down
2 changes: 1 addition & 1 deletion eng/regression_tools.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# requirements leveraged by ci tools
setuptools==72.2.0
setuptools==74.1.3
virtualenv==20.23.0
wheel==0.43.0
Jinja2==3.1.2
Expand Down
2 changes: 1 addition & 1 deletion scripts/repo_health_status_report/dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
httpx==0.25.2
markdown==3.6
PyGitHub>=1.59.0
setuptools==72.2.0
setuptools==74.1.3
-e ./sdk/identity/azure-identity
-e ./tools/azure-sdk-tools
53 changes: 21 additions & 32 deletions tools/azure-sdk-tools/ci_tools/parsing/parse_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
from typing import Dict, List, Tuple, Any, Optional

# Assumes the presence of setuptools
from pkg_resources import (
parse_requirements,
Requirement
)
from pkg_resources import parse_requirements, Requirement

# this assumes the presence of "packaging"
from packaging.specifiers import SpecifierSet
Expand Down Expand Up @@ -208,6 +205,7 @@ def get_ci_config(package_path: str) -> Optional[Dict[str, Any]]:

if os.path.exists(ci_file):
import yaml

try:
with open(ci_file, "r") as f:
return yaml.safe_load(f)
Expand All @@ -225,6 +223,7 @@ def read_setup_py_content(setup_filename: str) -> str:
content = setup_file.read()
return content


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]]:
Expand Down Expand Up @@ -327,33 +326,25 @@ def setup(*args, **kwargs):
)
# fmt: on

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]]:

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]]:
toml_dict = get_pyproject_dict(pyproject_filename)

project_config = toml_dict.get("project", None)

# This stilted file evaluation is necessary because the setuptools.configuration.read_configuration doesn't properly
# evaluate a valid pyproject.toml...or at least I am unable to get it to do so properly. I just get an empty dict
# of values. Using read_configuration is preferred because it will handle all of the setuptools dynamic evaluation for us.
# however, in my experience, I have been unable to make this happen.
#
# I have been able to successfully call build.ProjectBuilder.prepare() and get a valid result, but that actually partially builds
# the project metadata into a dist-info folder, which is more work than I want to do to get the values I need. (Including needing the package dependencies to
# be installed, as we actually import the __init__ to evaluate the VERSION value.)
#
# I really want this to be a straightforward "read from disk" without needing the package to actually be installed to build it, so we're just going to go after
# the version.py if the `version` attribute isn't set in the project config.
#
# As mentioned before build phase will need to install _dependencies_ of the package prior to building, that will be taken care of in
# build.py create_package()
# - scbedd 1/26/2024 - 2/2/2024.
# to pull a version from pyproject.toml, we need to get a dynamic version out. We can ask
# setuptools to give us the metadata for a package, but that will involve _partially building_ the package
# to create an egginfo folder. This is a very expensive operation goes against the entire point of
# "give me the package metadata for this folder."
# We can avoid this expensive operation if we parse the version out of the _version or version file directly.
parsed_version = project_config.get("version", None)
if not parsed_version:
# go after the value from _version.py or version.py
parsed_version_py = get_version_py(pyproject_filename)

if parsed_version_py:
with open(parsed_version_py, 'r') as f:
with open(parsed_version_py, "r") as f:
parsed_version = re.search(VERSION_REGEX, f.read(), re.MULTILINE)

if parsed_version:
Expand All @@ -372,17 +363,10 @@ def parse_pyproject(pyproject_filename: str) -> Tuple[str, str, str, List[str],
classifiers = project_config.get("classifiers", [])
keywords = project_config.get("keywords", [])

setuptools_config = toml_dict.get("tool.setuptools", {})
# as of setuptools 74.1 ext_packages and ext_modules are now present in tool.setuptools config namespace
ext_package = get_value_from_dict(setuptools_config, "ext_package", None)
ext_modules = get_value_from_dict(setuptools_config, "ext_modules", [])
ext_modules = [
Extension(
name=module['name'],
sources=module['sources'],
)
for module in ext_modules
]
ext_package = get_value_from_dict(toml_dict, "tool.setuptools.ext-package", None)
ext_modules = get_value_from_dict(toml_dict, "tool.setuptools.ext-modules", [])
ext_modules = [Extension(**moduleArgDict) for moduleArgDict in ext_modules]

# fmt: off
return (
Expand All @@ -402,6 +386,7 @@ def parse_pyproject(pyproject_filename: str) -> Tuple[str, str, str, List[str],
)
# fmt: on


def get_version_py(setup_path: str):
file_path, _ = os.path.split(setup_path)
# Find path to _version.py recursively in azure folder of package
Expand All @@ -414,6 +399,7 @@ def get_version_py(setup_path: str):

return None


def get_pyproject(folder: str) -> Optional[str]:
"""
Given a folder, attempts to find a pyproject.toml file with a "project" configuration and return its location.
Expand All @@ -427,6 +413,7 @@ def get_pyproject(folder: str) -> Optional[str]:

return None


def get_setup_py(folder: str) -> Optional[str]:
"""
Given a folder, attempts to find a setup.py file and return its location.
Expand All @@ -438,6 +425,7 @@ def get_setup_py(folder: str) -> Optional[str]:

return None


def parse_setup(
setup_filename_or_folder: str,
):
Expand Down Expand Up @@ -472,6 +460,7 @@ def parse_setup(
else:
return parse_setup_py(resolved_filename)


def get_pyproject_dict(pyproject_file: str) -> Dict[str, Any]:
"""
Given a pyproject.toml file, returns a dictionary of a target section. Defaults to `project` section.
Expand Down
2 changes: 1 addition & 1 deletion tools/azure-sdk-tools/ci_tools/versioning/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
packaging==23.1
pyparsing==2.4.5
six==1.13.0
setuptools==72.2.0
setuptools==74.1.3
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ dynamic = ["version"]
readme = "README.md"

[tool.setuptools]
ext-modules = [
{name = "crc64", sources = ["crc64/crc64module.c"], py_limited_api=true}
]
ext_package = "azure.keyvault.keys"
ext-modules = [{ name = "crc64", sources = ["crc64/crc64module.c"], py_limited_api = true }]
ext-package = "azure.keyvault.keys"

[project.urls]
repository = "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/keyvault/azure-keyvault-keys"
Expand Down
8 changes: 4 additions & 4 deletions tools/azure-sdk-tools/tests/test_parse_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_parse_recognizes_extensions(test_patch):

def test_parse_pyproject():
# ensure that we can parse from a folder and a specific file
parsed_project = ParsedSetup.from_path(pyproject_scenario)
parsed_project = ParsedSetup.from_path(pyproject_extension_scenario)

assert parsed_project.name == "azure-keyvault-keys"
assert parsed_project.version == "0.0.1"
Expand All @@ -227,17 +227,17 @@ def test_parse_pyproject():

def test_parse_pyproject_extensions():
# ensure that we can parse from a folder and a specific file
parsed_project = ParsedSetup.from_path(pyproject_scenario)
parsed_project = ParsedSetup.from_path(pyproject_extension_scenario)

assert parsed_project.name == "azure-keyvault-keys"
assert parsed_project.version == "0.0.1"
assert parsed_project.version == "0.0.1b1"
assert parsed_project.requires == ["azure-common~=1.1", "azure-core<2.0.0,>=1.24.0", "cryptography>=2.1.4", "isodate>=0.6.1", "typing-extensions>=4.0.1"]
assert parsed_project.python_requires == ">=3.7"
assert parsed_project.is_new_sdk == True
assert parsed_project.is_pyproject == True
assert parsed_project.package_data == { "py.typed": ["py.typed"] }
assert parsed_project.include_package_data == True
assert parsed_project.folder == pyproject_scenario
assert parsed_project.folder == pyproject_extension_scenario
assert parsed_project.namespace == "azure.keyvault.keys"
assert parsed_project.ext_package == "azure.keyvault.keys"
assert parsed_project.ext_modules is not None
Expand Down

0 comments on commit 05dbbb5

Please sign in to comment.