Represent a single revision file in a ``versions/`` directory. The :class:`.Script` instance is returned by methods such as :meth:`.ScriptDirectory.iterate_revisions`.
| 800 | |
| 801 | |
| 802 | class Script(revision.Revision): |
| 803 | """Represent a single revision file in a ``versions/`` directory. |
| 804 | |
| 805 | The :class:`.Script` instance is returned by methods |
| 806 | such as :meth:`.ScriptDirectory.iterate_revisions`. |
| 807 | |
| 808 | """ |
| 809 | |
| 810 | def __init__( |
| 811 | self, |
| 812 | module: ModuleType, |
| 813 | rev_id: str, |
| 814 | path: Union[str, os.PathLike[str]], |
| 815 | ): |
| 816 | self.module = module |
| 817 | self.path = _preserving_path_as_str(path) |
| 818 | super().__init__( |
| 819 | rev_id, |
| 820 | module.down_revision, |
| 821 | branch_labels=util.to_tuple( |
| 822 | getattr(module, "branch_labels", None), default=() |
| 823 | ), |
| 824 | dependencies=util.to_tuple( |
| 825 | getattr(module, "depends_on", None), default=() |
| 826 | ), |
| 827 | ) |
| 828 | |
| 829 | module: ModuleType |
| 830 | """The Python module representing the actual script itself.""" |
| 831 | |
| 832 | path: str |
| 833 | """Filesystem path of the script.""" |
| 834 | |
| 835 | @property |
| 836 | def _script_path(self) -> Path: |
| 837 | return Path(self.path) |
| 838 | |
| 839 | _db_current_indicator: Optional[bool] = None |
| 840 | """Utility variable which when set will cause string output to indicate |
| 841 | this is a "current" version in some database""" |
| 842 | |
| 843 | @property |
| 844 | def doc(self) -> str: |
| 845 | """Return the docstring given in the script.""" |
| 846 | |
| 847 | return re.split("\n\n", self.longdoc)[0] |
| 848 | |
| 849 | @property |
| 850 | def longdoc(self) -> str: |
| 851 | """Return the docstring given in the script.""" |
| 852 | |
| 853 | doc = self.module.__doc__ |
| 854 | if doc: |
| 855 | if hasattr(self.module, "_alembic_source_encoding"): |
| 856 | doc = doc.decode( # type: ignore[attr-defined] |
| 857 | self.module._alembic_source_encoding |
| 858 | ) |
| 859 | return doc.strip() |
no outgoing calls
no test coverage detected
searching dependent graphs…