Skip to content

Commit a74466c

Browse files
committed
Run code style formetters on all existing files
1 parent b2890e1 commit a74466c

39 files changed

+850
-840
lines changed

.github/workflows/PR_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
This pull request was created by GitHub Actions/AWS CodeBuild! Before merging, please do the following:
22
- [ ] Review changelog/staleness report.
33
- [ ] Review build/test results by clicking *Build Logs* in CI Report (be patient, tests take ~4hr).
4-
- [ ] Review ECR Scan results.
4+
- [ ] Review ECR Scan results.

.github/workflows/monthly-minor-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ jobs:
4141
uses: aws/sagemaker-distribution/.github/workflows/build-image.yml@main
4242
with:
4343
release-type: "minor"
44-
base-version: ${{ matrix.version }}
44+
base-version: ${{ matrix.version }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__pycache__
22
.idea
3-
.DS_Store
3+
.DS_Store

CONTRIBUTING.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,60 +41,60 @@ GitHub provides additional document on [forking a repository](https://help.githu
4141

4242

4343
## For adding new Conda packages to SageMaker Distribution
44-
SageMaker Distribution will add new Conda packages only during a minor/major version release.
44+
SageMaker Distribution will add new Conda packages only during a minor/major version release.
4545
New packages will not be added during a patch version release.
4646

4747
Follow these steps for sending out a pull request for adding new packages:
4848
1. Identify the latest version of SageMaker Distribution.
4949
2. Create the next minor/major version's build artifacts folder here: https://github.com/aws/sagemaker-distribution/tree/main/build_artifacts
50-
3. Currently, SageMaker Distribution is using Conda forge channel as our source (for Conda
51-
packages).
50+
3. Currently, SageMaker Distribution is using Conda forge channel as our source (for Conda
51+
packages).
5252
Ensure that the new package which you are trying to add is present in Conda forge channel. https://conda-forge.org/feedstock-outputs/
53-
4. Create {cpu/gpu}.additional_packages_env.in file in that folder containing the new packages.
53+
4. Create {cpu/gpu}.additional_packages_env.in file in that folder containing the new packages.
5454
Specify the new package based on the following examples:
5555

5656
i. conda-forge::new-package
57-
57+
5858
ii. conda-forge::new-package[version='>=some-version-number,<some-version-number']
59-
5. Run the following commands to verify whether the new package which you are trying to add is
59+
5. Run the following commands to verify whether the new package which you are trying to add is
6060
compatible with the existing packages in SageMaker Distribution
6161
```
6262
This project uses Conda to manage its dependencies. Run the following to setup your local environment:
6363
6464
conda env update --file environment.yml -n sagemaker-distribution
65-
65+
6666
conda activate sagemaker-distribution
67-
67+
6868
export BASE_PATCH_VERSION='current.latest.version'
69-
70-
# NEXT_VERSION refers to the version number corresponding to the folder you created as part
69+
70+
# NEXT_VERSION refers to the version number corresponding to the folder you created as part
7171
of Step 2.
72-
72+
7373
export NEXT_VERSION='specify.next.version'
74-
74+
7575
# If NEXT_VERSION is a new minor version:
76-
76+
7777
python src/main.py create-minor-version-artifacts --base-patch-version=$BASE_PATCH_VERSION --force
78-
78+
7979
# Or for a new major version:
80-
80+
8181
python src/main.py create-major-version-artifacts --base-patch-version=$BASE_PATCH_VERSION --force
82-
82+
8383
# Build the image:
8484
python src/main.py build \
8585
--target-patch-version=$NEXT_VERSION --skip-tests
8686
8787
```
88-
6. Ensure that the build command succeeds. If it fails, then it means that the package isn't
89-
compatible with the existing packages in SageMaker Distribution. Create a Github Issue, so
88+
6. Ensure that the build command succeeds. If it fails, then it means that the package isn't
89+
compatible with the existing packages in SageMaker Distribution. Create a Github Issue, so
9090
that we can look more into it.
91-
7. Add the relevant tests in https://github.com/aws/sagemaker-distribution/blob/main/test/test_dockerfile_based_harness.py
91+
7. Add the relevant tests in https://github.com/aws/sagemaker-distribution/blob/main/test/test_dockerfile_based_harness.py
9292
and run the build command once again without `--skip-tests` flag.
9393
```
94-
# When writing or debugging tests, you can use standard pytest commands and arguments (https://docs.pytest.org/en/8.0.x/how-to/usage.html) to run specific tests and change test execution behavior. Some useful commands:
94+
# When writing or debugging tests, you can use standard pytest commands and arguments (https://docs.pytest.org/en/8.0.x/how-to/usage.html) to run specific tests and change test execution behavior. Some useful commands:
9595
9696
# The sagemaker-distribution conda env set up earlier should be activated before running below commands
97-
97+
9898
# Runs only tests for cpu image, verbose, shows reason for skipped tests
9999
python -m pytest -n auto -m cpu -vv -rs --local-image-version $VERSION
100100
@@ -104,9 +104,9 @@ Follow these steps for sending out a pull request for adding new packages:
104104
8. Submit the PR containing the following files.
105105
* {cpu/gpu}.additional_packages_env.in files
106106
* All the test files and test_dockerfile_based_harness.py changes
107-
107+
108108
Note: you don't have to include other files such as env.in/ env.out/ Dockerfile etc in your PR
109-
109+
110110
Also Note: We might ask you to include the test results as part of the PR.
111111
112112
## Finding contributions to work on

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ in the relevant _RELEASE.md_ file in the [build_artifacts](build_artifacts) dire
2222

2323
### Versioning strategy
2424

25-
Amazon SageMaker Distribution supports semantic versioning as described on [semver.org](https://semver.org/). A major
25+
Amazon SageMaker Distribution supports semantic versioning as described on [semver.org](https://semver.org/). A major
2626
version upgrade of Amazon SageMaker Distribution allows major version upgrades of all its dependencies, and similarly
2727
for minor and patch version upgrades. However, it is important to note that Amazon SageMaker Distribution’s ability to
2828
follow semver guidelines is currently dependent on how its dependencies adhere to them.
@@ -47,7 +47,7 @@ will remain the same over time.
4747

4848
### Package Staleness Report
4949

50-
If you want to generate/view the staleness report for each of the individual packages in a given
50+
If you want to generate/view the staleness report for each of the individual packages in a given
5151
SageMaker distribution image version, then run the following command:
5252

5353
```
@@ -98,7 +98,7 @@ directory (such as Jupyter Lab notebooks) will persist.
9898

9999
### Amazon SageMaker Studio
100100

101-
> [Amazon SageMaker Studio](https://docs.aws.amazon.com/sagemaker/latest/dg/studio.html) is a web-based, integrated
101+
> [Amazon SageMaker Studio](https://docs.aws.amazon.com/sagemaker/latest/dg/studio.html) is a web-based, integrated
102102
> development environment (IDE) for machine learning that lets you build, train, debug, deploy, and monitor your
103103
> machine learning models.
104104
@@ -125,8 +125,8 @@ RUN micromamba install sagemaker-inference --freeze-installed --yes --channel co
125125

126126
## FIPS
127127

128-
As of sagemaker-distribution: v0.12+, v1.6+, and v2+, the images come with FIPS 140-2 validated openssl provider
129-
available for use. You can enable the FIPS provider by running:
128+
As of sagemaker-distribution: v0.12+, v1.6+, and v2+, the images come with FIPS 140-2 validated openssl provider
129+
available for use. You can enable the FIPS provider by running:
130130

131131
`export OPENSSL_CONF=/opt/conda/ssl/openssl-fips.cnf`
132132

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ python src/main.py build \
5151

5252
Note:
5353

54-
- As you can see above, the `--target-ecr-repo` parameter can be supplied zero or multiple times. If not supplied, the
54+
- As you can see above, the `--target-ecr-repo` parameter can be supplied zero or multiple times. If not supplied, the
5555
tool will just build a local image. If supplied multiple times, it'll upload the images to all those ECR repositories.
5656
- There is also a `--skip-tests` flag which, by default, is `false`. You can supply it if you'd like to skip tests
5757
locally. However, we'll make sure the tests succeed before any image is release publicly.

src/changelog_generator.py

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,65 @@
11
import os
2-
from utils import (
3-
get_dir_for_version,
4-
get_semver,
5-
get_match_specs,
6-
)
2+
73
from semver import Version
84

5+
from utils import get_dir_for_version, get_match_specs, get_semver
6+
97

10-
def _derive_changeset(target_version_dir, source_version_dir, image_config) -> (dict[str,
11-
list[str]], dict[str, str]):
12-
env_in_file_name = image_config['build_args']['ENV_IN_FILENAME']
13-
env_out_file_name = image_config['env_out_filename']
14-
required_packages_from_target = get_match_specs(
15-
target_version_dir + "/" + env_in_file_name
16-
).keys()
8+
def _derive_changeset(target_version_dir, source_version_dir, image_config) -> (dict[str, list[str]], dict[str, str]):
9+
env_in_file_name = image_config["build_args"]["ENV_IN_FILENAME"]
10+
env_out_file_name = image_config["env_out_filename"]
11+
required_packages_from_target = get_match_specs(target_version_dir + "/" + env_in_file_name).keys()
1712
target_match_spec_out = get_match_specs(target_version_dir + "/" + env_out_file_name)
1813
source_match_spec_out = get_match_specs(source_version_dir + "/" + env_out_file_name)
1914

2015
# Note: required_packages_from_source is not currently used.
2116
# In the future, If we remove any packages from env.in, at that time required_packages_from_source will be needed.
2217
# We only care about the packages which are present in the target version env.in file
23-
installed_packages_from_target = {k: str(v.get('version')).removeprefix('==')
24-
for k, v in target_match_spec_out.items()
25-
if k in required_packages_from_target}
18+
installed_packages_from_target = {
19+
k: str(v.get("version")).removeprefix("==")
20+
for k, v in target_match_spec_out.items()
21+
if k in required_packages_from_target
22+
}
2623
# Note: A required package in the target version might not be a required package in the source version
2724
# But source version could still have this package pulled as a dependency of a dependency.
28-
installed_packages_from_source = {k: str(v.get('version')).removeprefix('==') for
29-
k, v in source_match_spec_out.items()
30-
if k in required_packages_from_target}
31-
upgrades = {k: [installed_packages_from_source[k], v] for k, v in installed_packages_from_target.items()
32-
if k in installed_packages_from_source and installed_packages_from_source[k] != v}
33-
new_packages = {k: v for k, v in installed_packages_from_target.items()
34-
if k not in installed_packages_from_source}
25+
installed_packages_from_source = {
26+
k: str(v.get("version")).removeprefix("==")
27+
for k, v in source_match_spec_out.items()
28+
if k in required_packages_from_target
29+
}
30+
upgrades = {
31+
k: [installed_packages_from_source[k], v]
32+
for k, v in installed_packages_from_target.items()
33+
if k in installed_packages_from_source and installed_packages_from_source[k] != v
34+
}
35+
new_packages = {k: v for k, v in installed_packages_from_target.items() if k not in installed_packages_from_source}
3536
# TODO: Add support for removed packages.
3637
return upgrades, new_packages
3738

3839

3940
def generate_change_log(target_version: Version, image_config):
4041
target_version_dir = get_dir_for_version(target_version)
41-
source_version_txt_file_path = f'{target_version_dir}/source-version.txt'
42+
source_version_txt_file_path = f"{target_version_dir}/source-version.txt"
4243
if not os.path.exists(source_version_txt_file_path):
43-
print('[WARN]: Generating CHANGELOG is skipped because \'source-version.txt\' isn\'t '
44-
'found.')
44+
print("[WARN]: Generating CHANGELOG is skipped because 'source-version.txt' isn't " "found.")
4545
return
46-
with open(source_version_txt_file_path, 'r') as f:
46+
with open(source_version_txt_file_path, "r") as f:
4747
source_patch_version = f.readline()
4848
source_version = get_semver(source_patch_version)
4949
source_version_dir = get_dir_for_version(source_version)
50-
image_type = image_config['image_type']
51-
upgrades, new_packages = _derive_changeset(target_version_dir, source_version_dir,
52-
image_config)
53-
with open(f'{target_version_dir}/CHANGELOG-{image_type}.md', 'w') as f:
54-
f.write('# Change log: ' + str(target_version) + '(' + image_type + ')\n\n')
50+
image_type = image_config["image_type"]
51+
upgrades, new_packages = _derive_changeset(target_version_dir, source_version_dir, image_config)
52+
with open(f"{target_version_dir}/CHANGELOG-{image_type}.md", "w") as f:
53+
f.write("# Change log: " + str(target_version) + "(" + image_type + ")\n\n")
5554
if len(upgrades) != 0:
56-
f.write('## Upgrades: \n\n')
57-
f.write('Package | Previous Version | Current Version\n')
58-
f.write('---|---|---\n')
55+
f.write("## Upgrades: \n\n")
56+
f.write("Package | Previous Version | Current Version\n")
57+
f.write("---|---|---\n")
5958
for package in upgrades:
60-
f.write(package + '|' + upgrades[package][0] + '|'
61-
+ upgrades[package][1] + '\n')
59+
f.write(package + "|" + upgrades[package][0] + "|" + upgrades[package][1] + "\n")
6260
if len(new_packages) != 0:
63-
f.write('\n## What\'s new: \n\n')
64-
f.write('Package | Version \n')
65-
f.write('---|---\n')
61+
f.write("\n## What's new: \n\n")
62+
f.write("Package | Version \n")
63+
f.write("---|---\n")
6664
for package in new_packages:
67-
f.write(package + '|' + new_packages[package] + '\n')
65+
f.write(package + "|" + new_packages[package] + "\n")

src/config.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
_image_generator_configs = [
22
{
3-
'build_args': {
4-
'TAG_FOR_BASE_MICROMAMBA_IMAGE': 'jammy-cuda-11.8.0',
5-
'CUDA_MAJOR_MINOR_VERSION': '11.8', # Should match the previous one.
6-
'ENV_IN_FILENAME': 'gpu.env.in',
7-
'ARG_BASED_ENV_IN_FILENAME': 'gpu.arg_based_env.in',
3+
"build_args": {
4+
"TAG_FOR_BASE_MICROMAMBA_IMAGE": "jammy-cuda-11.8.0",
5+
"CUDA_MAJOR_MINOR_VERSION": "11.8", # Should match the previous one.
6+
"ENV_IN_FILENAME": "gpu.env.in",
7+
"ARG_BASED_ENV_IN_FILENAME": "gpu.arg_based_env.in",
88
},
9-
'additional_packages_env_in_file': 'gpu.additional_packages_env.in',
10-
'image_tag_generator': '{image_version}-gpu',
11-
'env_out_filename': 'gpu.env.out',
12-
'pytest_flags': ['--use-gpu'],
13-
'image_type': 'gpu'
9+
"additional_packages_env_in_file": "gpu.additional_packages_env.in",
10+
"image_tag_generator": "{image_version}-gpu",
11+
"env_out_filename": "gpu.env.out",
12+
"pytest_flags": ["--use-gpu"],
13+
"image_type": "gpu",
1414
},
1515
{
16-
'build_args': {
17-
'TAG_FOR_BASE_MICROMAMBA_IMAGE': 'jammy',
18-
'ENV_IN_FILENAME': 'cpu.env.in',
16+
"build_args": {
17+
"TAG_FOR_BASE_MICROMAMBA_IMAGE": "jammy",
18+
"ENV_IN_FILENAME": "cpu.env.in",
1919
},
20-
'additional_packages_env_in_file': 'cpu.additional_packages_env.in',
21-
'image_tag_generator': '{image_version}-cpu',
22-
'env_out_filename': 'cpu.env.out',
23-
'pytest_flags': [],
24-
'image_type': 'cpu'
25-
}
20+
"additional_packages_env_in_file": "cpu.additional_packages_env.in",
21+
"image_tag_generator": "{image_version}-cpu",
22+
"env_out_filename": "cpu.env.out",
23+
"pytest_flags": [],
24+
"image_type": "cpu",
25+
},
2626
]

src/dependency_upgrader.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
from semver import Version
22

3-
_MAJOR = 'major'
4-
_MINOR = 'minor'
5-
_PATCH = 'patch'
3+
_MAJOR = "major"
4+
_MINOR = "minor"
5+
_PATCH = "patch"
66

77

88
def _get_dependency_upper_bound_for_runtime_upgrade(dependency_name: str, lower_bound: str, runtime_upgrade_type):
99
metadata = _dependency_metadata.get(dependency_name, None)
10-
version_upgrade_strategy = 'semver' if metadata is None else metadata['version_upgrade_strategy']
10+
version_upgrade_strategy = "semver" if metadata is None else metadata["version_upgrade_strategy"]
1111

12-
func = _version_upgrade_metadata[version_upgrade_strategy]['func']
12+
func = _version_upgrade_metadata[version_upgrade_strategy]["func"]
1313
# Version strings on conda-forge follow PEP standards rather than SemVer, which support
1414
# version strings such as X.Y.Z.postN, X.Y.Z.preN. These cause errors in semver.Version.parse
1515
# so we keep the first 3 entries as version string.
16-
if lower_bound.count('.') > 2:
17-
lower_bound = '.'.join(lower_bound.split('.')[:3])
16+
if lower_bound.count(".") > 2:
17+
lower_bound = ".".join(lower_bound.split(".")[:3])
1818
return func(lower_bound, runtime_upgrade_type)
1919

2020

2121
def _get_dependency_upper_bound_for_semver(lower_bound: str, runtime_upgrade_type):
2222
lower_semver = Version.parse(lower_bound, optional_minor_and_patch=True)
2323
if runtime_upgrade_type == _MAJOR:
24-
return '' # No upper bound.
24+
return "" # No upper bound.
2525
elif runtime_upgrade_type == _MINOR:
26-
return f',<{lower_semver.bump_major()}'
26+
return f",<{lower_semver.bump_major()}"
2727
elif runtime_upgrade_type == _PATCH:
28-
return f',<{lower_semver.bump_minor()}'
28+
return f",<{lower_semver.bump_minor()}"
2929
else:
3030
raise Exception()
3131

3232

3333
def _get_dependency_upper_bound_for_pythonesque(lower_bound: str, runtime_upgrade_type):
3434
lower_semver = Version.parse(lower_bound, optional_minor_and_patch=True)
3535
if runtime_upgrade_type == _MAJOR:
36-
return '' # No upper bound.
36+
return "" # No upper bound.
3737
elif runtime_upgrade_type == _MINOR:
38-
return f',<{lower_semver.bump_minor()}'
38+
return f",<{lower_semver.bump_minor()}"
3939
elif runtime_upgrade_type == _PATCH:
40-
return f',<{lower_semver.bump_minor()}'
40+
return f",<{lower_semver.bump_minor()}"
4141
else:
4242
raise Exception()
4343

@@ -50,21 +50,13 @@ def _get_dependency_upper_bound_for_pythonesque(lower_bound: str, runtime_upgrad
5050
# happens in the given month). So, 2nd release in December 2022 was versioned as '2022.12.1'.
5151
# In Amazon SageMaker Distribution, we want to move to a new month only during a minor version upgrade and new year
5252
# during a major version upgrade.
53-
'semver': {
54-
'func': _get_dependency_upper_bound_for_semver
55-
},
53+
"semver": {"func": _get_dependency_upper_bound_for_semver},
5654
# Some dependencies follow, for lack of a better word, "python style" release cycles. For e.g., even if Python does
5755
# a minor version upgrade from 3.9 to 3.10, we will only introduce 3.10 in Amazon SageMaker Distribution as part of
5856
# a major version upgrade. In other words, for dependencies below, minor version upgrades are treated as major
5957
# version upgrades in Amazon SageMaker Distribution.
60-
'pythonesque': {
61-
'func': _get_dependency_upper_bound_for_pythonesque
62-
}
58+
"pythonesque": {"func": _get_dependency_upper_bound_for_pythonesque},
6359
}
6460

6561

66-
_dependency_metadata = {
67-
'python': {
68-
'version_upgrade_strategy': 'pythonesque'
69-
}
70-
}
62+
_dependency_metadata = {"python": {"version_upgrade_strategy": "pythonesque"}}

0 commit comments

Comments
 (0)