Python deprecation.deprecated() Examples

The following are 15 code examples of deprecation.deprecated(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module deprecation , or try the search function .
Example #1
Source File: _compat_test.py    From OpenFermion-Cirq with Apache License 2.0 6 votes vote down vote up
def deprecated_test(test: Callable) -> Callable:
    """Marks a test as using deprecated functionality.

    Ensures the test is executed within the `pytest.deprecated_call()` context.

    Args:
        test: The test.

    Returns:
        The decorated test.
    """

    @functools.wraps(test)
    def decorated_test(*args, **kwargs) -> Any:
        with pytest.deprecated_call():
            test(*args, **kwargs)

    return decorated_test 
Example #2
Source File: test_deprecation.py    From deprecation with Apache License 2.0 6 votes vote down vote up
def test_multiline_fallback(self):
        docstring = "summary line\n\ndetails\nand more details\n"
        for test in [{"args": {"deprecated_in": "1.0"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"}]:
            with self.subTest(**test):
                deprecation.message_location = "pot"

                @deprecation.deprecated(**test["args"])
                def fn():
                    """summary line

                    details
                    and more details
                    """

                self.assertEqual(fn.__doc__, test["__doc__"] % (docstring)) 
Example #3
Source File: helpers.py    From cloudbridge with MIT License 5 votes vote down vote up
def rename_kwargs(func_name, kwargs, aliases):
    for alias, new in aliases.items():
        if alias in kwargs:
            if new in kwargs:
                raise InvalidParamException(
                    '{} received both {} and {}'.format(func_name, alias, new))
            # Manually invoke the deprecated decorator with an empty lambda
            # to signal deprecation
            deprecated(deprecated_in='1.1',
                       removed_in='2.0',
                       current_version=cloudbridge.__version__,
                       details='{} is deprecated, use {} instead'.format(
                           alias, new))(lambda: None)()
            kwargs[new] = kwargs.pop(alias) 
Example #4
Source File: project.py    From signac with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __setitem__(self, key, value):
        if not self._mutable:
            warnings.warn("Modifying the project configuration after project "
                          "initialization is deprecated as of version 1.3 and "
                          "will be removed in version 2.0.",
                          DeprecationWarning)

            assert version.parse(__version__) < version.parse("2.0")
        return super(_ProjectConfig, self).__setitem__(key, value) 
Example #5
Source File: project.py    From signac with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, project, filter, doc_filter):
        self._project = project
        self._filter = filter
        self._doc_filter = doc_filter

        # This private attribute allows us to implement the deprecated
        # next() method for this class.
        self._next_iter = None 
Example #6
Source File: project.py    From signac with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def next(self):
        """Return the next element.

        This function is deprecated, users should use iter(..).next() instead!

        .. deprecated:: 0.9.6
        """
        warnings.warn("Calling next() directly on a JobsCursor is deprecated!", DeprecationWarning)
        if self._next_iter is None:
            self._next_iter = iter(self)
        try:
            return next(self._next_iter)
        except StopIteration:
            self._next_iter = None
            raise 
Example #7
Source File: utils.py    From pysaliency with MIT License 5 votes vote down vote up
def deprecated_class(deprecated_in=None, removed_in=None, current_version=None, details=''):
    def wrap(cls):
        class DeprecatedClass(cls):
            @deprecation.deprecated(deprecated_in=deprecated_in, removed_in=removed_in, current_version=current_version, details=details)
            def __init__(self, *args, **kwargs):
                super(DeprecatedClass, self).__init__(*args, **kwargs)

        return DeprecatedClass

    return wrap 
Example #8
Source File: xarray.py    From wradlib with MIT License 5 votes vote down vote up
def __getitem__(self, key):
        if key == "root":
            warnings.warn(
                "WRADLIB: Use of `obj['root']` is deprecated, "
                "please use obj.root instead.",
                DeprecationWarning,
            )
            return self._root

        return self._sweeps[key] 
Example #9
Source File: test_deprecation.py    From deprecation with Apache License 2.0 5 votes vote down vote up
def test_removing_without_deprecating(self):
        self.assertRaises(TypeError, deprecation.deprecated,
                          deprecated_in=None, removed_in="1.0") 
Example #10
Source File: test_deprecation.py    From deprecation with Apache License 2.0 5 votes vote down vote up
def test_docstring(self):
        for test in [{"args": {},
                      "__doc__": "docstring\n\n.. deprecated::"},
                     {"args": {"deprecated_in": "1.0"},
                      "__doc__": "docstring\n\n.. deprecated:: 1.0"},
                     {"args": {"deprecated_in": "1.0", "removed_in": "2.0"},
                      "__doc__": "docstring\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed in 2.0."},
                     {"args": {"deprecated_in": "1.0", "removed_in": "2.0",
                               "details": "some details"},
                      "__doc__": "docstring\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed in 2.0. "
                                 "some details"},
                     {"args": {"deprecated_in": "1.0", "removed_in": date(2200, 5, 20)},
                      "__doc__": "docstring\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed on 2200-05-20."},
                     {"args": {"deprecated_in": "1.0", "removed_in": date(2100, 3, 15),
                               "details": "some details"},
                      "__doc__": "docstring\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed on 2100-03-15. "
                                 "some details"}]:
            with self.subTest(**test):
                @deprecation.deprecated(**test["args"])
                def fn():
                    """docstring"""

                self.assertEqual(fn.__doc__, test["__doc__"]) 
Example #11
Source File: test_deprecation.py    From deprecation with Apache License 2.0 5 votes vote down vote up
def test_multiline_docstring(self):
        docstring = "summary line\n\ndetails\nand more details\n"
        for test in [{"args": {},
                      "__doc__": "%s\n\n.. deprecated::"},
                     {"args": {"deprecated_in": "1.0"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"},
                     {"args": {"deprecated_in": "1.0", "removed_in": "2.0"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed in 2.0."},
                     {"args": {"deprecated_in": "1.0", "removed_in": "2.0",
                               "details": "some details"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed in 2.0. "
                                 "some details"},
                     {"args": {"deprecated_in": "1.0", "removed_in": date(2200, 11, 20)},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed on 2200-11-20."},
                     {"args": {"deprecated_in": "1.0", "removed_in": date(2100, 3, 15),
                               "details": "some details"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed on 2100-03-15. "
                                 "some details"}]:
            with self.subTest(**test):
                @deprecation.deprecated(**test["args"])
                def fn():
                    """summary line

                    details
                    and more details
                    """

                self.assertEqual(fn.__doc__, test["__doc__"] % (docstring)) 
Example #12
Source File: test_deprecation.py    From deprecation with Apache License 2.0 5 votes vote down vote up
def test_multiline_docstring_top(self):
        summary = "summary line"
        content = "\n\ndetails\nand more details\n"
        for test in [{"args": {},
                      "__doc__": "%s\n\n.. deprecated::%s"},
                     {"args": {"deprecated_in": "1.0"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0%s"},
                     {"args": {"deprecated_in": "1.0", "removed_in": "2.0"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed in 2.0.%s"},
                     {"args": {"deprecated_in": "1.0", "removed_in": "2.0",
                               "details": "some details"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed in 2.0. "
                                 "some details%s"},#####
                     {"args": {"deprecated_in": "1.0", "removed_in": date(2200, 11, 20)},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed on 2200-11-20.%s"},
                     {"args": {"deprecated_in": "1.0", "removed_in": date(2100, 3, 15),
                               "details": "some details"},
                      "__doc__": "%s\n\n.. deprecated:: 1.0"
                                 "\n   This will be removed on 2100-03-15. "
                                 "some details%s"}]:
            with self.subTest(**test):
                deprecation.message_location = "top"

                @deprecation.deprecated(**test["args"])
                def fn():
                    """summary line

                    details
                    and more details
                    """

                self.assertEqual(fn.__doc__, test["__doc__"] % (summary,
                                                                content)) 
Example #13
Source File: project.py    From signac-flow with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _add_direct_cmd_arg_group(cls, parser):
        direct_cmd_group = parser.add_argument_group("direct cmd")
        direct_cmd_group.add_argument(
            '--cmd',
            type=str,
            help="Directly specify the command for an operation. "
                 "For example: --cmd='echo {job._id}'. "
                 "--cmd option is deprecated as of 0.9 and will be removed in 0.11.")
        direct_cmd_group.add_argument(
            '--requires',
            type=str,
            nargs='+',
            help="Manually specify all labels that are required for the direct command "
                 "to be considered eligible for execution.") 
Example #14
Source File: project.py    From signac-flow with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _main_script(self, args):
        "Generate a script for the execution of operations."
        if args.requires and not args.cmd:
            raise ValueError(
                "The --requires option can only be used in combination with --cmd.")
        if args.cmd and args.operation_name:
            raise ValueError(
                "Cannot use the -o/--operation-name and the --cmd options in combination!")
        # Select jobs:
        jobs = self._select_jobs_from_args(args)

        # Gather all pending operations or generate them based on a direct command...
        with self._potentially_buffered():
            if args.cmd:
                warnings.warn("The --cmd option for script is deprecated as of "
                              "0.9 and will be removed in 0.11.",
                              DeprecationWarning)
                operations = self._generate_operations(args.cmd, jobs, args.requires)
            else:
                names = args.operation_name if args.operation_name else None
                default_directives = self._get_default_directives()
                operations = self._get_submission_operations(jobs, default_directives, names,
                                                             args.ignore_conditions,
                                                             args.ignore_conditions_on_execution)
            operations = list(islice(operations, args.num))

        # Generate the script and print to screen.
        print(self.script(
            operations=operations, parallel=args.parallel,
            template=args.template, show_template_help=args.show_template_help)) 
Example #15
Source File: project.py    From signac with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def create_linked_view(self, prefix=None, job_ids=None, index=None, path=None):
        """Create or update a persistent linked view of the selected data space.

        Similar to :meth:`~.export_to`, this function expands the data space for the selected
        jobs, but instead of copying data will create symbolic links to the individual job
        workspace directories. This is primarily useful for browsing through the data
        space using a file-browser with human-interpretable directory paths.

        By default, the paths of the view will be based on variable state point keys as part
        of the *implicit* schema of the selected jobs that we create the view for. For example,
        creating a linked view for a data space with schema

        .. code-block:: python

            >>> print(project.detect_schema())
            {
             'foo': 'int([0, 1, 2, ..., 8, 9], 10)',
            }

        by calling ``project.create_linked_view('my_view')`` will look similar to:

        .. code-block:: bash

            my_view/foo/0/job -> workspace/b8fcc6b8f99c56509eb65568922e88b8
            my_view/foo/1/job -> workspace/b6cd26b873ae3624653c9268deff4485
            ...

        It is possible to control the paths using the ``path`` argument, which behaves in
        the exact same manner as the equivalent argument for :meth:`~.Project.export_to`.

        .. note::

            The behavior of this function is almost equivalent to
            ``project.export_to('my_view', copytree=os.symlink)`` with the major difference,
            that view hierarchies are actually *updated*, that means no longer valid links
            are automatically removed.

        :param prefix:
            The path where the linked view will be created or updated.
        :type prefix:
            str
        :param job_ids:
            If None (the default), create the view for the complete data space,
            otherwise only for the sub space constituted by the provided job ids.
        :param index:
            A document index.
        :param path:
            The path (function) used to structure the linked data space.
        :returns:
            A dict that maps the source directory paths, to the linked
            directory paths.
        """
        if index is not None:
            warnings.warn(("The `index` argument is deprecated as of version 1.3 and will be "
                           "removed in version 2.0."), DeprecationWarning)

        from .linked_view import create_linked_view
        return create_linked_view(self, prefix, job_ids, index, path)