Skip to content

Commit

Permalink
Make classifiers, dependencies and requires-python static in sdists, …
Browse files Browse the repository at this point in the history
…and add more tests.
  • Loading branch information
domdfcoding committed Mar 21, 2021
1 parent d35d85a commit 581e7da
Show file tree
Hide file tree
Showing 40 changed files with 1,174 additions and 62 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apeye>=0.7.0
click>=7.1.2
consolekit>=1.0.1
dom-toml>=0.1.1
domdf-python-tools>=2.7.0
email-validator>=1.1.2
first>=2.0.2
Expand Down
35 changes: 35 additions & 0 deletions tests/example_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,41 @@
package = "whey"
"""

DYNAMIC_REQUIREMENTS = """\
[build-system]
requires = [ "whey",]
build-backend = "whey"
[project]
name = "Whey"
version = "2021.0.0"
description = "A simple Python wheel builder for simple projects."
readme = "README.rst"
keywords = [ "pep517", "pep621", "build", "sdist", "wheel", "packaging", "distribution",]
dynamic = [ "classifiers", "dependencies", "requires-python",]
[project.license]
file = "LICENSE"
[[project.authors]]
email = "dominic@davis-foster.co.uk"
name = "Dominic Davis-Foster"
[project.urls]
Homepage = "https://whey.readthedocs.io/en/latest"
Documentation = "https://whey.readthedocs.io/en/latest"
"Issue Tracker" = "https://github.com/repo-helper/whey/issues"
"Source Code" = "https://github.com/repo-helper/whey"
[tool.whey]
base-classifiers = [ "Development Status :: 4 - Beta",]
python-versions = [ "3.6", "3.7", "3.8", "3.9", "3.10",]
python-implementations = [ "CPython", "PyPy",]
platforms = [ "Windows", "macOS", "Linux",]
license-key = "MIT"
package = "whey"
"""

LONG_REQUIREMENTS = """\
[build-system]
requires = [ "whey",]
Expand Down
114 changes: 95 additions & 19 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
COMPLETE_A,
COMPLETE_B,
DEPENDENCIES,
DYNAMIC_REQUIREMENTS,
ENTRY_POINTS,
KEYWORDS,
LONG_REQUIREMENTS,
Expand Down Expand Up @@ -104,13 +105,31 @@ def test_build_success(
with tar.extractfile("spam/__init__.py") as fp: # type: ignore
assert fp.read().decode("UTF-8") == "print('hello world)\n"

with tar.extractfile("PKG-INFO") as fp: # type: ignore
check_file_regression(fp.read().decode("UTF-8"), file_regression)

with tar.extractfile("pyproject.toml") as fp: # type: ignore
check_file_regression(fp.read().decode("UTF-8"), file_regression, extension=".toml")

outerr = capsys.readouterr()
data["stdout"] = outerr.out.replace(tmp_pathplus.as_posix(), "...")
data["stderr"] = outerr.err

advanced_data_regression.check(data)


def check_built_wheel(filename: PathPlus, file_regression: FileRegressionFixture):
assert (filename).is_file()
zip_file = zipfile.ZipFile(filename)

with zip_file.open("whey/__init__.py", mode='r') as fp:
assert fp.read().decode("UTF-8") == "print('hello world)\n"
with zip_file.open("whey-2021.0.0.dist-info/METADATA", mode='r') as fp:
check_file_regression(fp.read().decode("UTF-8"), file_regression)

return sorted(zip_file.namelist())


@pytest.mark.parametrize(
"config",
[
Expand Down Expand Up @@ -147,15 +166,7 @@ def test_build_complete(
)

wheel = wheel_builder.build_wheel()
assert (tmp_pathplus / wheel).is_file()
zip_file = zipfile.ZipFile(tmp_pathplus / wheel)
data["wheel_content"] = sorted(zip_file.namelist())

with zip_file.open("whey/__init__.py", mode='r') as fp:
assert fp.read().decode("UTF-8") == "print('hello world)\n"

with zip_file.open("whey-2021.0.0.dist-info/METADATA", mode='r') as fp:
check_file_regression(fp.read().decode("UTF-8"), file_regression)
data["wheel_content"] = check_built_wheel(tmp_pathplus / wheel, file_regression)

with tempfile.TemporaryDirectory() as tmpdir:
sdist_builder = SDistBuilder(
Expand All @@ -181,6 +192,10 @@ def test_build_complete(
assert fp.read().decode("UTF-8") == "This is the license\n"
with tar.extractfile("requirements.txt") as fp: # type: ignore
assert fp.read().decode("UTF-8") == "domdf_python_tools\n"
with tar.extractfile("PKG-INFO") as fp: # type: ignore
check_file_regression(fp.read().decode("UTF-8"), file_regression)
with tar.extractfile("pyproject.toml") as fp: # type: ignore
check_file_regression(fp.read().decode("UTF-8"), file_regression, extension=".toml")

outerr = capsys.readouterr()
data["stdout"] = outerr.out.replace(tmp_pathplus.as_posix(), "...")
Expand Down Expand Up @@ -274,6 +289,66 @@ def test_build_additional_files(
advanced_data_regression.check(data)


def test_build_markdown_readme(
tmp_pathplus: PathPlus,
advanced_data_regression: AdvancedDataRegressionFixture,
file_regression: FileRegressionFixture,
capsys,
):

(tmp_pathplus / "pyproject.toml").write_clean(COMPLETE_B.replace(".rst", ".md"))
(tmp_pathplus / "whey").mkdir()
(tmp_pathplus / "whey" / "__init__.py").write_clean("print('hello world)")
(tmp_pathplus / "README.md").write_clean("Spam Spam Spam Spam")
(tmp_pathplus / "LICENSE").write_clean("This is the license")
(tmp_pathplus / "requirements.txt").write_clean("domdf_python_tools")

data = {}

with tempfile.TemporaryDirectory() as tmpdir:
wheel_builder = WheelBuilder(
project_dir=tmp_pathplus,
config=load_toml(tmp_pathplus / "pyproject.toml"),
build_dir=tmpdir,
out_dir=tmp_pathplus,
verbose=True,
colour=False,
)

wheel = wheel_builder.build_wheel()
data["wheel_content"] = check_built_wheel(tmp_pathplus / wheel, file_regression)

with tempfile.TemporaryDirectory() as tmpdir:
sdist_builder = SDistBuilder(
project_dir=tmp_pathplus,
build_dir=tmpdir,
out_dir=tmp_pathplus,
verbose=True,
colour=False,
config=load_toml(tmp_pathplus / "pyproject.toml"),
)
sdist = sdist_builder.build_sdist()
assert (tmp_pathplus / sdist).is_file()

tar = tarfile.open(tmp_pathplus / sdist)
data["sdist_content"] = sorted(tar.getnames())

with tar.extractfile("whey/__init__.py") as fp: # type: ignore
assert fp.read().decode("UTF-8") == "print('hello world)\n"
with tar.extractfile("README.md") as fp: # type: ignore
assert fp.read().decode("UTF-8") == "Spam Spam Spam Spam\n"
with tar.extractfile("LICENSE") as fp: # type: ignore
assert fp.read().decode("UTF-8") == "This is the license\n"
with tar.extractfile("requirements.txt") as fp: # type: ignore
assert fp.read().decode("UTF-8") == "domdf_python_tools\n"

outerr = capsys.readouterr()
data["stdout"] = outerr.out.replace(tmp_pathplus.as_posix(), "...")
data["stderr"] = outerr.err

advanced_data_regression.check(data)


def test_build_missing_dir(tmp_pathplus: PathPlus):
(tmp_pathplus / "pyproject.toml").write_clean(MINIMAL_CONFIG)

Expand Down Expand Up @@ -340,6 +415,7 @@ def test_build_empty_dir(tmp_pathplus: PathPlus):
[
pytest.param(COMPLETE_A, id="COMPLETE_A"),
pytest.param(COMPLETE_B, id="COMPLETE_B"),
pytest.param(DYNAMIC_REQUIREMENTS, id="DYNAMIC_REQUIREMENTS"),
pytest.param(LONG_REQUIREMENTS, id="LONG_REQUIREMENTS"),
]
)
Expand All @@ -355,7 +431,9 @@ def test_build_wheel_from_sdist(
(tmp_pathplus / "whey" / "__init__.py").write_clean("print('hello world)")
(tmp_pathplus / "README.rst").write_clean("Spam Spam Spam Spam")
(tmp_pathplus / "LICENSE").write_clean("This is the license")
(tmp_pathplus / "requirements.txt").write_clean("domdf_python_tools")
(tmp_pathplus / "requirements.txt").write_lines([
"httpx", "gidgethub[httpx]>4.0.0", "django>2.1; os_name != 'nt'", "django>2.0; os_name == 'nt'"
])

# Build the sdist

Expand Down Expand Up @@ -392,15 +470,7 @@ def test_build_wheel_from_sdist(
colour=False,
)
wheel = wheel_builder.build_wheel()
assert (tmp_pathplus / wheel).is_file()
zip_file = zipfile.ZipFile(tmp_pathplus / wheel)
data["wheel_content"] = sorted(zip_file.namelist())

with zip_file.open("whey/__init__.py", mode='r') as fp:
assert fp.read().decode("UTF-8") == "print('hello world)\n"

with zip_file.open("whey-2021.0.0.dist-info/METADATA", mode='r') as fp:
check_file_regression(fp.read().decode("UTF-8"), file_regression)
data["wheel_content"] = check_built_wheel(tmp_pathplus / wheel, file_regression)

outerr = capsys.readouterr()
data["stdout"] = outerr.out.replace(tmp_pathplus.as_posix(), "...")
Expand Down Expand Up @@ -529,6 +599,9 @@ def test_build_underscore_name(
with tar.extractfile("spam_spam/__init__.py") as fp: # type: ignore
assert fp.read().decode("UTF-8") == "print('hello world)\n"

with tar.extractfile("PKG-INFO") as fp: # type: ignore
check_file_regression(fp.read().decode("UTF-8"), file_regression)

outerr = capsys.readouterr()
data["stdout"] = outerr.out.replace(tmp_pathplus.as_posix(), "...")
data["stderr"] = outerr.err
Expand Down Expand Up @@ -592,6 +665,9 @@ def test_build_stubs_name(
with tar.extractfile("spam_spam-stubs/__init__.pyi") as fp: # type: ignore
assert fp.read().decode("UTF-8") == "print('hello world)\n"

with tar.extractfile("PKG-INFO") as fp: # type: ignore
check_file_regression(fp.read().decode("UTF-8"), file_regression)

outerr = capsys.readouterr()
data["stdout"] = outerr.out.replace(tmp_pathplus.as_posix(), "...")
data["stderr"] = outerr.err
Expand Down
48 changes: 48 additions & 0 deletions tests/test_build_/test_build_complete_COMPLETE_A_.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[build-system]
requires = [ "whey",]
build-backend = "whey"

[project]
name = "whey"
version = "2021.0.0"
description = "A simple Python wheel builder for simple projects."
keywords = [ "pep517", "pep621", "build", "sdist", "wheel", "packaging", "distribution",]
dynamic = []
readme = "README.rst"
dependencies = [ "httpx", "gidgethub[httpx]>4.0.0", "django>2.1; os_name != 'nt'", "django>2.0; os_name == 'nt'",]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
requires-python = ">=3.6"

[[project.authors]]
email = "dominic@davis-foster.co.uk"
name = "Dominic Davis-Foster"


[project.license]
file = "LICENSE"

[project.urls]
Homepage = "https://whey.readthedocs.io/en/latest"
Documentation = "https://whey.readthedocs.io/en/latest"
"Issue Tracker" = "https://github.com/repo-helper/whey/issues"
"Source Code" = "https://github.com/repo-helper/whey"

[tool.whey]
base-classifiers = [ "Development Status :: 4 - Beta",]
python-versions = [ "3.6", "3.7", "3.8", "3.9", "3.10",]
python-implementations = [ "CPython", "PyPy",]
platforms = [ "Windows", "macOS", "Linux",]
license-key = "MIT"
49 changes: 49 additions & 0 deletions tests/test_build_/test_build_complete_COMPLETE_B_.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[build-system]
requires = [ "whey",]
build-backend = "whey"

[project]
name = "Whey"
version = "2021.0.0"
description = "A simple Python wheel builder for simple projects."
readme = "README.rst"
keywords = [ "pep517", "pep621", "build", "sdist", "wheel", "packaging", "distribution",]
dynamic = []
dependencies = [ "httpx", "gidgethub[httpx]>4.0.0", "django>2.1; os_name != 'nt'", "django>2.0; os_name == 'nt'",]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
requires-python = ">=3.6"

[[project.authors]]
email = "dominic@davis-foster.co.uk"
name = "Dominic Davis-Foster"


[project.license]
file = "LICENSE"

[project.urls]
Homepage = "https://whey.readthedocs.io/en/latest"
Documentation = "https://whey.readthedocs.io/en/latest"
"Issue Tracker" = "https://github.com/repo-helper/whey/issues"
"Source Code" = "https://github.com/repo-helper/whey"

[tool.whey]
base-classifiers = [ "Development Status :: 4 - Beta",]
python-versions = [ "3.6", "3.7", "3.8", "3.9", "3.10",]
python-implementations = [ "CPython", "PyPy",]
platforms = [ "Windows", "macOS", "Linux",]
license-key = "MIT"
package = "whey"
36 changes: 36 additions & 0 deletions tests/test_build_/test_build_complete_LONG_REQUIREMENTS_.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[build-system]
requires = [ "whey",]
build-backend = "whey"

[project]
name = "Whey"
version = "2021.0.0"
description = "A simple Python wheel builder for simple projects."
readme = "README.rst"
dynamic = []
dependencies = [
"httpx",
"gidgethub[httpx]>4.0.0",
"django>2.1; os_name != 'nt'",
"django>2.0; os_name == 'nt'",
"typed-ast>=1.4.2; python_version < '3.8' and platform_python_implementation == 'CPython'",
]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
]
requires-python = "None"

[[project.authors]]
email = "dominic@davis-foster.co.uk"
name = "Dominic Davis-Foster"


[project.license]
file = "LICENSE"

[tool.whey]
base-classifiers = [ "Development Status :: 4 - Beta",]
license-key = "MIT"
package = "whey"

0 comments on commit 581e7da

Please sign in to comment.