Skip to content

Commit 9796730

Browse files
author
Mohamed Zeidan
committed
fix: stop sagemaker-train/serve/mlops from shipping sagemaker/__init__.py (#5795)
sagemaker-core, -train, -serve, and -mlops each shipped an identical top-level sagemaker/__init__.py. Installing two of them writes the same file path, which strict installers and OS package managers (e.g. FreeBSD pkg) reject as a conflict. It also meant the last-installed wheel silently clobbered the others' init -- and sagemaker-core's is the only one that registers the v2->v3 removed- module migration finder, so that guidance could be lost depending on install order. Make sagemaker-core the sole owner of sagemaker/__init__.py (it is a required dependency of the other three, so the file is always present exactly once). The other three now contribute to the sagemaker namespace via PEP 420 / the pkgutil extend_path in core's init. Add per-distribution regression guards.
1 parent 7ac2708 commit 9796730

9 files changed

Lines changed: 120 additions & 15 deletions

File tree

‎sagemaker-mlops/src/sagemaker/__init__.py‎

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Regression guard for GH #5795.
14+
15+
sagemaker-mlops must not ship its own top-level ``sagemaker/__init__.py``:
16+
sagemaker-core owns that file, and having two distributions install the same
17+
path makes strict installers / OS package managers refuse to co-install them.
18+
The ``sagemaker`` package is a namespace shared across the sub-distributions.
19+
"""
20+
21+
from __future__ import absolute_import
22+
23+
from pathlib import Path
24+
25+
_SRC = Path(__file__).resolve().parents[2] / "src"
26+
27+
28+
def test_does_not_ship_top_level_sagemaker_init():
29+
top_level_init = _SRC / "sagemaker" / "__init__.py"
30+
assert not top_level_init.exists(), (
31+
f"{top_level_init} must not exist: sagemaker-core owns "
32+
"sagemaker/__init__.py (see GH #5795)."
33+
)
34+
35+
36+
def test_still_ships_the_subpackage_init():
37+
# The distribution's own sub-package must remain a real package.
38+
assert (_SRC / "sagemaker" / "mlops" / "__init__.py").exists()

‎sagemaker-mlops/tox.ini‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ setenv =
136136
deps =
137137
-r ../requirements/tox/pylint_requirements.txt
138138
commands =
139-
python -m pylint --rcfile=../.pylintrc -j 0 src/sagemaker --fail-under=9.9
139+
python -m pylint --rcfile=../.pylintrc -j 0 --recursive=y src/sagemaker --fail-under=9.9
140140

141141
[testenv:spelling]
142142
skipdist = true
143143
skip_install = true
144144
deps =
145145
-r ../requirements/tox/spelling_requirements.txt
146146
commands =
147-
python -m pylint --rcfile=../.pylintrc --disable all --enable spelling --spelling-dict en_US src/sagemaker/{posargs}
147+
python -m pylint --rcfile=../.pylintrc --disable all --enable spelling --spelling-dict en_US --recursive=y src/sagemaker/{posargs}
148148

149149
[testenv:twine]
150150
# https://packaging.python.org/guides/making-a-pypi-friendly-readme/#validating-restructuredtext-markup

‎sagemaker-serve/src/sagemaker/__init__.py‎

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Regression guard for GH #5795.
14+
15+
sagemaker-serve must not ship its own top-level ``sagemaker/__init__.py``:
16+
sagemaker-core owns that file, and having two distributions install the same
17+
path makes strict installers / OS package managers refuse to co-install them.
18+
The ``sagemaker`` package is a namespace shared across the sub-distributions.
19+
"""
20+
21+
from __future__ import absolute_import
22+
23+
from pathlib import Path
24+
25+
_SRC = Path(__file__).resolve().parents[2] / "src"
26+
27+
28+
def test_does_not_ship_top_level_sagemaker_init():
29+
top_level_init = _SRC / "sagemaker" / "__init__.py"
30+
assert not top_level_init.exists(), (
31+
f"{top_level_init} must not exist: sagemaker-core owns "
32+
"sagemaker/__init__.py (see GH #5795)."
33+
)
34+
35+
36+
def test_still_ships_the_subpackage_init():
37+
# The distribution's own sub-package must remain a real package.
38+
assert (_SRC / "sagemaker" / "serve" / "__init__.py").exists()

‎sagemaker-serve/tox.ini‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ setenv =
139139
deps =
140140
-r ../requirements/tox/pylint_requirements.txt
141141
commands =
142-
python -m pylint --rcfile=../.pylintrc -j 0 src/sagemaker --fail-under=9.9
142+
python -m pylint --rcfile=../.pylintrc -j 0 --recursive=y src/sagemaker --fail-under=9.9
143143

144144
[testenv:spelling]
145145
skipdist = true
146146
skip_install = true
147147
deps =
148148
-r ../requirements/tox/spelling_requirements.txt
149149
commands =
150-
python -m pylint --rcfile=../.pylintrc --disable all --enable spelling --spelling-dict en_US src/sagemaker/{posargs}
150+
python -m pylint --rcfile=../.pylintrc --disable all --enable spelling --spelling-dict en_US --recursive=y src/sagemaker/{posargs}
151151

152152
[testenv:twine]
153153
# https://packaging.python.org/guides/making-a-pypi-friendly-readme/#validating-restructuredtext-markup

‎sagemaker-train/src/sagemaker/__init__.py‎

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Regression guard for GH #5795.
14+
15+
sagemaker-train must not ship its own top-level ``sagemaker/__init__.py``:
16+
sagemaker-core owns that file, and having two distributions install the same
17+
path makes strict installers / OS package managers refuse to co-install them.
18+
The ``sagemaker`` package is a namespace shared across the sub-distributions.
19+
"""
20+
21+
from __future__ import absolute_import
22+
23+
from pathlib import Path
24+
25+
_SRC = Path(__file__).resolve().parents[2] / "src"
26+
27+
28+
def test_does_not_ship_top_level_sagemaker_init():
29+
top_level_init = _SRC / "sagemaker" / "__init__.py"
30+
assert not top_level_init.exists(), (
31+
f"{top_level_init} must not exist: sagemaker-core owns "
32+
"sagemaker/__init__.py (see GH #5795)."
33+
)
34+
35+
36+
def test_still_ships_the_subpackage_init():
37+
# The distribution's own sub-package must remain a real package.
38+
assert (_SRC / "sagemaker" / "train" / "__init__.py").exists()

‎sagemaker-train/tox.ini‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ setenv =
143143
deps =
144144
-r ../requirements/tox/pylint_requirements.txt
145145
commands =
146-
python -m pylint --rcfile=../.pylintrc -j 0 src/sagemaker --fail-under=9.9
146+
python -m pylint --rcfile=../.pylintrc -j 0 --recursive=y src/sagemaker --fail-under=9.9
147147

148148
[testenv:spelling]
149149
skipdist = true
150150
skip_install = true
151151
deps =
152152
-r ../requirements/tox/spelling_requirements.txt
153153
commands =
154-
python -m pylint --rcfile=../.pylintrc --disable all --enable spelling --spelling-dict en_US src/sagemaker/{posargs}
154+
python -m pylint --rcfile=../.pylintrc --disable all --enable spelling --spelling-dict en_US --recursive=y src/sagemaker/{posargs}
155155

156156
[testenv:twine]
157157
# https://packaging.python.org/guides/making-a-pypi-friendly-readme/#validating-restructuredtext-markup

0 commit comments

Comments
 (0)