From 79c14d22c7adf1381a1a8df5813b1e56ef50ba90 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 29 Sep 2022 11:06:36 +0100 Subject: [PATCH 1/5] limit sdist contents --- .github/workflows/ci.yml | 6 +++++- Cargo.toml | 18 ++++++++++++++++++ generate_self_schema.py | 4 +--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e97f93af5..3b10a324b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -233,7 +233,7 @@ jobs: build: name: build on ${{ matrix.platform || matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }}) # only run on push to main and on release - if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')" +# if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')" needs: [test, lint] strategy: fail-fast: false @@ -346,6 +346,10 @@ jobs: - run: ls -lh dist/ - run: echo "`ls dist | wc -l` files" + - run: mkdir sdist-files + - run: tar -xvf dist/*.tar.gz -C sdist-files + - run: tree sdist-files + - run: python -m zipfile --list `ls target/wheels/*x86_64.whl | head -n 1` release: needs: [build, build-wasm-emscripten] diff --git a/Cargo.toml b/Cargo.toml index 03f328c9d..f6bb1987b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,24 @@ license = "MIT" homepage = "https://github.com/pydantic/pydantic-core" repository = "https://github.com/pydantic/pydantic-core.git" readme = "README.md" +include = [ + "/pyproject.toml", + "/README.md", + "/LICENSE", + "/Makefile", + "/build.rs", + "/generate_self_schema.py", + "/rust-toolchain", + "/src", + "!/src/self_schema.py", + "/pydantic_core", + "/tests", + "/.cargo", + "!__pycache__", + "!tests/.hypothesis", + "!tests/.pytest_cache", + "!*.so", +] [dependencies] pyo3 = "0.17.1" diff --git a/generate_self_schema.py b/generate_self_schema.py index 255df73d7..6a7b77b72 100644 --- a/generate_self_schema.py +++ b/generate_self_schema.py @@ -11,7 +11,6 @@ from collections.abc import Callable from datetime import date, datetime, time, timedelta from pathlib import Path -from pprint import pformat from typing import TYPE_CHECKING, Any, Dict, ForwardRef, List, Type, Union from typing_extensions import get_args, is_typeddict @@ -169,8 +168,7 @@ def main() -> None: 'choices': choices, } python_code = ( - f'# this file is auto-generated by generate_self_schema.py, DO NOT edit manually\n' - f'self_schema = {pformat(schema)}\n' + f'# this file is auto-generated by generate_self_schema.py, DO NOT edit manually\nself_schema = {schema}\n' ) try: from black import Mode, TargetVersion, format_file_contents From 9b1f6fd32378da45a38be31133383fe2f7f4cfd4 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 29 Sep 2022 11:08:34 +0100 Subject: [PATCH 2/5] run build faster --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b10a324b..faad69570 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -234,7 +234,7 @@ jobs: name: build on ${{ matrix.platform || matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }}) # only run on push to main and on release # if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')" - needs: [test, lint] +# needs: [test, lint] strategy: fail-fast: false matrix: From 69e5b00290e0339035a855930fb1375fe8d4077d Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 29 Sep 2022 11:43:32 +0100 Subject: [PATCH 3/5] add build_profile property, fix list --- .github/workflows/ci.yml | 6 +++--- build.rs | 3 ++- pydantic_core/_pydantic_core.pyi | 1 + pyproject.toml | 1 - src/lib.rs | 1 + tests/test_misc.py | 7 ++++++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index faad69570..b083ff9f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -331,7 +331,7 @@ jobs: name: pypi_files path: dist - list-pypi-files: + inspect-pypi-assets: needs: [build] runs-on: ubuntu-latest @@ -348,8 +348,8 @@ jobs: - run: echo "`ls dist | wc -l` files" - run: mkdir sdist-files - run: tar -xvf dist/*.tar.gz -C sdist-files - - run: tree sdist-files - - run: python -m zipfile --list `ls target/wheels/*x86_64.whl | head -n 1` + - run: tree -a sdist-files + - run: python -m zipfile --list `ls dist/*x86_64.whl | head -n 1` release: needs: [build, build-wasm-emscripten] diff --git a/build.rs b/build.rs index 594120e96..ecb7cbeda 100644 --- a/build.rs +++ b/build.rs @@ -28,5 +28,6 @@ fn main() { if let Some(true) = version_check::supports_feature("no_coverage") { println!("cargo:rustc-cfg=has_no_coverage"); } - generate_self_schema() + generate_self_schema(); + println!("cargo:rustc-env=PROFILE={}", std::env::var("PROFILE").unwrap()); } diff --git a/pydantic_core/_pydantic_core.pyi b/pydantic_core/_pydantic_core.pyi index 872c1a967..b7d8ff2dc 100644 --- a/pydantic_core/_pydantic_core.pyi +++ b/pydantic_core/_pydantic_core.pyi @@ -10,6 +10,7 @@ else: __all__ = '__version__', 'SchemaValidator', 'SchemaError', 'ValidationError', 'PydanticValueError' __version__: str +build_profile: str class SchemaValidator: title: str diff --git a/pyproject.toml b/pyproject.toml index baee3c7e4..913f2cce9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,6 @@ Source = 'https://github.com/pydantic/pydantic-core' [tool.maturin] bindings = 'pyo3' -sdist-include = ['src/self_schema.py'] [tool.pytest.ini_options] testpaths = 'tests' diff --git a/src/lib.rs b/src/lib.rs index f5cf3bba4..82a222332 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,7 @@ pub fn get_version() -> String { #[pymodule] fn _pydantic_core(_py: Python, m: &PyModule) -> PyResult<()> { m.add("__version__", get_version())?; + m.add("build_profile", env!("PROFILE"))?; m.add_class::()?; m.add_class::()?; m.add_class::()?; diff --git a/tests/test_misc.py b/tests/test_misc.py index 4f8432899..5b47aac35 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -4,7 +4,7 @@ import pytest -from pydantic_core._pydantic_core import SchemaError, SchemaValidator, ValidationError, __version__ +from pydantic_core._pydantic_core import SchemaError, SchemaValidator, ValidationError, __version__, build_profile @pytest.mark.parametrize('obj', [ValidationError, SchemaValidator, SchemaError]) @@ -17,6 +17,11 @@ def test_version(): assert '.' in __version__ +def test_build_profile(): + assert isinstance(build_profile, str) + assert build_profile in ('debug', 'release') + + def test_schema_error(): err = SchemaError('test') assert isinstance(err, Exception) From f42d46951209f3a4903725ec8a83e70ac9192635 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 29 Sep 2022 12:22:24 +0100 Subject: [PATCH 4/5] tweak inspect-pypi-assets --- .github/workflows/ci.yml | 16 ++++++++++------ tests/test_misc.py | 1 - 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b083ff9f2..659602bbb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -344,12 +344,16 @@ jobs: name: pypi_files path: dist - - run: ls -lh dist/ - - run: echo "`ls dist | wc -l` files" - - run: mkdir sdist-files - - run: tar -xvf dist/*.tar.gz -C sdist-files - - run: tree -a sdist-files - - run: python -m zipfile --list `ls dist/*x86_64.whl | head -n 1` + - run: | + ls -lh dist/ + echo "`ls dist | wc -l` files" + - run: | + mkdir sdist-files + tar -xvf dist/*.tar.gz -C sdist-files + tree -a sdist-files + - run: | + ls dist/*cp310-manylinux*x86_64.whl | head -n 1 + python -m zipfile --list `ls dist/*cp310-manylinux*x86_64.whl | head -n 1` release: needs: [build, build-wasm-emscripten] diff --git a/tests/test_misc.py b/tests/test_misc.py index 5b47aac35..9599c60ef 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -18,7 +18,6 @@ def test_version(): def test_build_profile(): - assert isinstance(build_profile, str) assert build_profile in ('debug', 'release') From 78c47a96dc5cf52634def9a11a76df01e5fce58d Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 29 Sep 2022 12:37:59 +0100 Subject: [PATCH 5/5] [skip-ci] replace if and needs on build --- .github/workflows/ci.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 659602bbb..82c349e63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -233,8 +233,8 @@ jobs: build: name: build on ${{ matrix.platform || matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }}) # only run on push to main and on release -# if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')" -# needs: [test, lint] + if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')" + needs: [test, lint] strategy: fail-fast: false matrix: @@ -344,14 +344,19 @@ jobs: name: pypi_files path: dist - - run: | + - name: list dist files + run: | ls -lh dist/ echo "`ls dist | wc -l` files" - - run: | + + - name: extract and list s-dist file + run: | mkdir sdist-files tar -xvf dist/*.tar.gz -C sdist-files tree -a sdist-files - - run: | + + - name: extract and list wheel file + run: | ls dist/*cp310-manylinux*x86_64.whl | head -n 1 python -m zipfile --list `ls dist/*cp310-manylinux*x86_64.whl | head -n 1`