Makefile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. .PHONY: deps_table_update modified_only_fixup extra_style_checks quality style fixup fix-copies test test-examples
  2. # make sure to test the local checkout in scripts and not the pre-installed one (don't use quotes!)
  3. export PYTHONPATH = src
  4. check_dirs := examples tests src utils
  5. modified_only_fixup:
  6. $(eval modified_py_files := $(shell python utils/get_modified_files.py $(check_dirs)))
  7. @if test -n "$(modified_py_files)"; then \
  8. echo "Checking/fixing $(modified_py_files)"; \
  9. black $(modified_py_files); \
  10. ruff $(modified_py_files) --fix; \
  11. else \
  12. echo "No library .py files were modified"; \
  13. fi
  14. # Update src/transformers/dependency_versions_table.py
  15. deps_table_update:
  16. @python setup.py deps_table_update
  17. deps_table_check_updated:
  18. @md5sum src/transformers/dependency_versions_table.py > md5sum.saved
  19. @python setup.py deps_table_update
  20. @md5sum -c --quiet md5sum.saved || (printf "\nError: the version dependency table is outdated.\nPlease run 'make fixup' or 'make style' and commit the changes.\n\n" && exit 1)
  21. @rm md5sum.saved
  22. # autogenerating code
  23. autogenerate_code: deps_table_update
  24. # Check that the repo is in a good state
  25. repo-consistency:
  26. python utils/check_copies.py
  27. python utils/check_table.py
  28. python utils/check_dummies.py
  29. python utils/check_repo.py
  30. python utils/check_inits.py
  31. python utils/check_config_docstrings.py
  32. python utils/check_config_attributes.py
  33. python utils/check_doctest_list.py
  34. python utils/update_metadata.py --check-only
  35. python utils/check_task_guides.py
  36. # this target runs checks on all files
  37. quality:
  38. black --check $(check_dirs) setup.py conftest.py
  39. python utils/custom_init_isort.py --check_only
  40. python utils/sort_auto_mappings.py --check_only
  41. ruff $(check_dirs) setup.py conftest.py
  42. doc-builder style src/transformers docs/source --max_len 119 --check_only --path_to_docs docs/source
  43. python utils/check_doc_toc.py
  44. # Format source code automatically and check is there are any problems left that need manual fixing
  45. extra_style_checks:
  46. python utils/custom_init_isort.py
  47. python utils/sort_auto_mappings.py
  48. doc-builder style src/transformers docs/source --max_len 119 --path_to_docs docs/source
  49. python utils/check_doc_toc.py --fix_and_overwrite
  50. # this target runs checks on all files and potentially modifies some of them
  51. style:
  52. black $(check_dirs) setup.py conftest.py
  53. ruff $(check_dirs) setup.py conftest.py --fix
  54. ${MAKE} autogenerate_code
  55. ${MAKE} extra_style_checks
  56. # Super fast fix and check target that only works on relevant modified files since the branch was made
  57. fixup: modified_only_fixup extra_style_checks autogenerate_code repo-consistency
  58. # Make marked copies of snippets of codes conform to the original
  59. fix-copies:
  60. python utils/check_copies.py --fix_and_overwrite
  61. python utils/check_table.py --fix_and_overwrite
  62. python utils/check_dummies.py --fix_and_overwrite
  63. python utils/check_doctest_list.py --fix_and_overwrite
  64. python utils/check_task_guides.py --fix_and_overwrite
  65. # Run tests for the library
  66. test:
  67. python -m pytest -n auto --dist=loadfile -s -v ./tests/
  68. # Run tests for examples
  69. test-examples:
  70. python -m pytest -n auto --dist=loadfile -s -v ./examples/pytorch/
  71. # Run tests for SageMaker DLC release
  72. test-sagemaker: # install sagemaker dependencies in advance with pip install .[sagemaker]
  73. TEST_SAGEMAKER=True python -m pytest -n auto -s -v ./tests/sagemaker
  74. # Release stuff
  75. pre-release:
  76. python utils/release.py
  77. pre-patch:
  78. python utils/release.py --patch
  79. post-release:
  80. python utils/release.py --post_release
  81. post-patch:
  82. python utils/release.py --post_release --patch
  83. build-release:
  84. rm -rf dist
  85. rm -rf build
  86. python setup.py bdist_wheel
  87. python setup.py sdist
  88. python utils/check_build.py