%bcond tests %{undefined rhel} %bcond docs %{undefined rhel} # %%cargo_generate_buildrequires hardcodes %%{with check} as the condition for # when to install dev dependencies :/. %bcond check 1 # Use --with all_tests to run all tests %bcond_with all_tests Name: python-libcst Version: 1.0.1 Release: %autorelease Summary: A concrete syntax tree with AST-like properties for Python 3 # see LICENSE in the upstream sources for the breakdown License: MIT AND (MIT OR PSF-2.0) AND Apache-2.0 URL: https://github.com/Instagram/LibCST Source: %{pypi_source libcst} BuildRequires: cargo-rpm-macros BuildRequires: python3-devel BuildRequires: tomcli %if %{with tests} # test dependencies are intermingled with dev dependencies # so list them manually for now BuildRequires: python3dist(hypothesis) BuildRequires: python3dist(hypothesmith) BuildRequires: python3dist(pytest) BuildRequires: python3dist(pytest-xdist) %endif %if %{with docs} BuildRequires: graphviz BuildRequires: sed BuildRequires: python3-docs BuildRequires: python3-metakernel-python BuildRequires: python3dist(sphinx) BuildRequires: python3dist(nbsphinx) >= 0.4.2 BuildRequires: python3dist(sphinx-rtd-theme) >= 0.4.3 %endif %global _description %{expand: LibCST parses Python source code as a CST tree that keeps all formatting details (comments, whitespaces, parentheses, etc). It's useful for building automated refactoring (codemod) applications and linters. LibCST creates a compromise between an Abstract Syntax Tree (AST) and a traditional Concrete Syntax Tree (CST). By carefully reorganizing and naming node types and fields, it creates a lossless CST that looks and feels like an AST.} # ' this comment fixes vim syntax highlighting %description %_description %package -n python3-libcst Summary: %{summary} %description -n python3-libcst %_description %if %{with docs} %package doc Summary: %{name} documentation Requires: python3-docs %description doc Documentation for %{name} %endif %prep %autosetup -p1 -n libcst-%{version} # Python %if %{with docs} # Use local intersphinx inventory sed -r \ -e 's|https://docs.python.org/3|%{_docdir}/python3-docs/html|' \ -i docs/source/conf.py %endif # Rust # Remove unused config file that only contains buildflags for Darwin #rm -v .cargo/config.toml # Sets up our own cargo config file %cargo_prep cd native # Update to a supported pyo3 version. tomcli-set libcst/Cargo.toml str 'dependencies.pyo3.version' '0.19' # Remove unneeded dev-dependencies tomcli-set libcst/Cargo.toml del 'dev-dependencies.criterion' tomcli-set libcst/Cargo.toml del 'dev-dependencies.criterion-cycles-per-byte' find -name Cargo.lock -print -delete cd - %generate_buildrequires %pyproject_buildrequires cd native %cargo_generate_buildrequires %build export RUSTFLAGS="%{build_rustflags}" %pyproject_wheel %if %{with docs} # Create a temporary virtual environment for docs %{python3} -m venv --system-site-packages venv ./venv/bin/pip install %{_pyproject_wheeldir}/* # generate html docs ./venv/bin/python -Pm sphinx docs/source html # remove the sphinx-build leftovers rm -rf html/.{doctrees,buildinfo} %endif %install %pyproject_install %pyproject_save_files libcst %check %pyproject_check_import %if %{with tests} # test_codegen_clean is tracked in https://github.com/Instagram/LibCST/issues/304 # test_codemod_cli is tracked in https://github.com/Instagram/LibCST/issues/331 # test_type_enforce is tracked in https://github.com/Instagram/LibCST/issues/305 # test_type_inference_provider requires pyre which is not packaged # # FAILED libcst/codegen/tests/test_codegen_clean.py::TestCodegenClean::test_codegen_clean_matcher_classes # FAILED libcst/codegen/tests/test_codegen_clean.py::TestCodegenClean::test_codegen_clean_return_types # FAILED libcst/codegen/tests/test_codegen_clean.py::TestCodegenClean::test_codegen_clean_visitor_functions # FAILED libcst/tests/test_type_enforce.py::TypeEnforcementTest::test_basic_pass_19 EXCLUDES="not test_codegen_clean_matcher_classes and not test_codegen_clean_return_types" EXCLUDES+=" and not test_codegen_clean_visitor_functions and not test_basic_pass_19" # ERROR libcst/metadata/tests/test_type_inference_provider.py::TypeInferenceProviderTest::test_gen_cache_0 # ERROR libcst/metadata/tests/test_type_inference_provider.py::TypeInferenceProviderTest::test_simple_class_types_0 # ERROR libcst/metadata/tests/test_type_inference_provider.py::TypeInferenceProviderTest::test_with_empty_cache EXCLUDES+=" and not test_gen_cache_0 and not test_simple_class_types_0 and not test_with_empty_cache" # Don't use local copy when running tests. # This causes weird errors and failures to import the extension module. mv {,.}libcst for LIBCST_PARSER_TYPE in pure native; do export LIBCST_PARSER_TYPE echo "Running ${LIBCST_PARSER_TYPE} tests..." if [ "${LIBCST_PARSER_TYPE}" = "native" ]; then EXCLUDES+=" and not test_codemod_formatter_error_input" fi %pytest \ %dnl Apply excludes unless the all_tests bcond is set %{!?with_all_tests:-k "$EXCLUDES"} \ --import-mode=importlib \ -nauto \ -v \ %{buildroot}%{python3_sitearch}/libcst done cd native %cargo_test %endif %files -n python3-libcst -f %{pyproject_files} %doc README.rst %if %{with docs} %files doc %doc html %license LICENSE %endif %changelog %autochangelog