Changeset 266628 in webkit


Ignore:
Timestamp:
Sep 4, 2020 12:12:16 PM (4 years ago)
Author:
Jonathan Bedard
Message:

[webkitscmpy] Add root, branch and remote for local SCM repositories
https://bugs.webkit.org/show_bug.cgi?id=215960
<rdar://problem/67968919>

Reviewed by Dewei Zhu.

  • Scripts/libraries/webkitcorepy/webkitcorepy/init.py: Bump version.
  • Scripts/libraries/webkitcorepy/webkitcorepy/decorators.py: Added.

(Memoize): Add a memoize call that can cache a response for a set amount of time
Or be explicitly cleared.

  • Scripts/libraries/webkitcorepy/webkitcorepy/tests/decorators_unittest.py: Added.

(TestMemoize):

  • Scripts/libraries/webkitscmpy/webkitscmpy/init.py: Bump version.
  • Scripts/libraries/webkitscmpy/webkitscmpy/local: Added.
  • Scripts/libraries/webkitscmpy/webkitscmpy/local/init.py: Added.
  • Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py: Added.

(Git): Object representing a local git checkout.
(Git.is_checkout): Check if a given path is a git checkout.
(Git.init): Initialize a Git checkout.
(Git.root_path): Return the path for the root of the local repository.
(Git.branch): Return the current branch.
(Git.remote): Return the url of the remote.

  • Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py: Added.

(Scm): Base class for all local SCM checkouts.
(Scm.Exception):
(Scm.from_path): Given a path, return an instantiated SVN object from that
path, if possible.
(Scm.init):
(Scm.root_path): Virtual function implemented by children.
(Scm.branch): Ditto.
(Scm.remote): Ditto.

  • Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py: Added.

(Svn): Object representing a local Svn checkout.
(Svn.is_checkout): Check if a given path is a svn checkout.
(Svn.init): Initialize a Svn checkout.
(Svn.info): Return the contents of svn info as a dictionary.
(Svn.root_path): Return the path for the root of the local repository.
(Svn.branch): Return the current branch.
(Svn.remote): Return the url of the remote.

  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks: Added.
  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks/init.py: Added.
  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local: Added.
  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/init.py: Added.
  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py: Added.

(Git): Mock a local Git repository.
(Git.init):

  • Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py: Added.

(Svn): Mock a local SVN repository.

  • Scripts/libraries/webkitscmpy/webkitscmpy/test: Added.
  • Scripts/libraries/webkitscmpy/webkitscmpy/test/init.py: Added.
  • Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py: Added.

(TestGit):

  • Scripts/libraries/webkitscmpy/webkitscmpy/test/scm_unittest.py: Added.

(TestScm):

  • Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py: Added.

(TestSvn):

Location:
trunk/Tools
Files:
14 added
4 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r266626 r266628  
     12020-09-04  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [webkitscmpy] Add root, branch and remote for local SCM repositories
     4        https://bugs.webkit.org/show_bug.cgi?id=215960
     5        <rdar://problem/67968919>
     6
     7        Reviewed by Dewei Zhu.
     8
     9        * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Bump version.
     10        * Scripts/libraries/webkitcorepy/webkitcorepy/decorators.py: Added.
     11        (Memoize): Add a memoize call that can cache a response for a set amount of time
     12        Or be explicitly cleared.
     13        * Scripts/libraries/webkitcorepy/webkitcorepy/tests/decorators_unittest.py: Added.
     14        (TestMemoize):
     15        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Bump version.
     16        * Scripts/libraries/webkitscmpy/webkitscmpy/local: Added.
     17        * Scripts/libraries/webkitscmpy/webkitscmpy/local/__init__.py: Added.
     18        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py: Added.
     19        (Git): Object representing a local git checkout.
     20        (Git.is_checkout): Check if a given path is a git checkout.
     21        (Git.__init__): Initialize a Git checkout.
     22        (Git.root_path): Return the path for the root of the local repository.
     23        (Git.branch): Return the current branch.
     24        (Git.remote): Return the url of the remote.
     25        * Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py: Added.
     26        (Scm): Base class for all local SCM checkouts.
     27        (Scm.Exception):
     28        (Scm.from_path): Given a path, return an instantiated SVN object from that
     29        path, if possible.
     30        (Scm.__init__):
     31        (Scm.root_path): Virtual function implemented by children.
     32        (Scm.branch): Ditto.
     33        (Scm.remote): Ditto.
     34        * Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py: Added.
     35        (Svn): Object representing a local Svn checkout.
     36        (Svn.is_checkout): Check if a given path is a svn checkout.
     37        (Svn.__init__): Initialize a Svn checkout.
     38        (Svn.info): Return the contents of svn info as a dictionary.
     39        (Svn.root_path): Return the path for the root of the local repository.
     40        (Svn.branch): Return the current branch.
     41        (Svn.remote): Return the url of the remote.
     42        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks: Added.
     43        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/__init__.py: Added.
     44        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local: Added.
     45        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/__init__.py: Added.
     46        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py: Added.
     47        (Git): Mock a local Git repository.
     48        (Git.__init__):
     49        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py: Added.
     50        (Svn): Mock a local SVN repository.
     51        * Scripts/libraries/webkitscmpy/webkitscmpy/test: Added.
     52        * Scripts/libraries/webkitscmpy/webkitscmpy/test/__init__.py: Added.
     53        * Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py: Added.
     54        (TestGit):
     55        * Scripts/libraries/webkitscmpy/webkitscmpy/test/scm_unittest.py: Added.
     56        (TestScm):
     57        * Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py: Added.
     58        (TestSvn):
     59
    1602020-09-04  Aakash Jain  <aakash_jain@apple.com>
    261
  • trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py

    r266478 r266628  
    3636from webkitcorepy.output_capture import LoggerCapture, OutputCapture, OutputDuplicate
    3737
    38 version = Version(0, 4, 4)
     38version = Version(0, 4, 5)
    3939
    4040from webkitcorepy.autoinstall import Package, AutoInstall
  • trunk/Tools/Scripts/libraries/webkitscmpy/setup.py

    r266255 r266628  
    4949    author_email='jbedard@apple.com',
    5050    license='Modified BSD',
    51     packages=['webkitscmpy'],
     51    packages=[
     52        'webkitscmpy',
     53        'webkitscmpy.local',
     54        'webkitscmpy.mocks',
     55        'webkitscmpy.mocks.local',
     56        'webkitscmpy.test',
     57    ],
    5258    install_requires=['webkitcorepy'],
    5359    include_package_data=True,
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py

    r266255 r266628  
    1 # Copyright (C) 2019 Apple Inc. All rights reserved.
     1# Copyright (C) 2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    4747    )
    4848
    49 version = Version(0, 0, 1)
     49version = Version(0, 0, 2)
     50
     51from webkitscmpy import local
     52from webkitscmpy import mocks
     53
    5054name = 'webkitscmpy'
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py

    r266627 r266628  
    1 # Copyright (C) 2019 Apple Inc. All rights reserved.
     1# Copyright (C) 2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 import logging
    24 import os
    25 import sys
    2623
    27 log = logging.getLogger('webkitscmpy')
     24class Scm(object):
     25    class Exception(RuntimeError):
     26        pass
    2827
     28    executable = None
    2929
    30 def _maybe_add_webkitcorepy_path():
    31     # Hopefully we're beside webkitcorepy, otherwise webkitcorepy will need to be installed.
    32     libraries_path = os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
    33     webkitcorepy_path = os.path.join(libraries_path, 'webkitcorepy')
    34     if os.path.isdir(webkitcorepy_path) and os.path.isdir(os.path.join(webkitcorepy_path, 'webkitcorepy')) and webkitcorepy_path not in sys.path:
    35         sys.path.insert(0, webkitcorepy_path)
     30    @classmethod
     31    def from_path(cls, path):
     32        from webkitscmpy import local
    3633
     34        if local.Git.is_checkout(path):
     35            return local.Git(path)
     36        if local.Svn.is_checkout(path):
     37            return local.Svn(path)
     38        raise OSError('{} is not a known SCM type')
    3739
    38 _maybe_add_webkitcorepy_path()
     40    def __init__(self, path):
     41        if not isinstance(path, str):
     42            raise ValueError('')
     43        self.path = path
    3944
    40 try:
    41     from webkitcorepy.version import Version
    42 except ImportError:
    43     raise ImportError(
    44         "'webkitcorepy' could not be found on your Python path.\n" +
    45         "You are not running from a WebKit checkout.\n" +
    46         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
    47     )
     45    @property
     46    def root_path(self):
     47        raise NotImplementedError()
    4848
    49 version = Version(0, 0, 1)
    50 name = 'webkitscmpy'
     49    @property
     50    def branch(self):
     51        raise NotImplementedError()
     52
     53    def remote(self, name=None):
     54        raise NotImplementedError()
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/git_unittest.py

    r266627 r266628  
    1 # Copyright (C) 2019 Apple Inc. All rights reserved.
     1# Copyright (C) 2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 import logging
    2423import os
    25 import sys
     24import unittest
    2625
    27 log = logging.getLogger('webkitscmpy')
     26from webkitscmpy import local, mocks
    2827
    2928
    30 def _maybe_add_webkitcorepy_path():
    31     # Hopefully we're beside webkitcorepy, otherwise webkitcorepy will need to be installed.
    32     libraries_path = os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
    33     webkitcorepy_path = os.path.join(libraries_path, 'webkitcorepy')
    34     if os.path.isdir(webkitcorepy_path) and os.path.isdir(os.path.join(webkitcorepy_path, 'webkitcorepy')) and webkitcorepy_path not in sys.path:
    35         sys.path.insert(0, webkitcorepy_path)
     29class TestGit(unittest.TestCase):
     30    path = '/mock/repository'
    3631
     32    def test_detection(self):
     33        with mocks.local.Git(self.path), mocks.local.Svn():
     34            detect = local.Scm.from_path(self.path)
     35            self.assertEqual(detect.executable, local.Git.executable)
    3736
    38 _maybe_add_webkitcorepy_path()
     37    def test_root(self):
     38        with mocks.local.Git(self.path):
     39            self.assertEqual(local.Git(self.path).root_path, self.path)
    3940
    40 try:
    41     from webkitcorepy.version import Version
    42 except ImportError:
    43     raise ImportError(
    44         "'webkitcorepy' could not be found on your Python path.\n" +
    45         "You are not running from a WebKit checkout.\n" +
    46         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
    47     )
     41            with self.assertRaises(OSError):
     42                local.Git(os.path.dirname(self.path)).root_path
    4843
    49 version = Version(0, 0, 1)
    50 name = 'webkitscmpy'
     44    def test_branch(self):
     45        with mocks.local.Git(self.path):
     46            self.assertEqual(local.Git(self.path).branch, 'master')
     47
     48        with mocks.local.Git(self.path, detached=True):
     49            self.assertEqual(local.Git(self.path).branch, None)
     50
     51    def test_remote(self):
     52        with mocks.local.Git(self.path) as repo:
     53            self.assertEqual(local.Git(self.path).remote(), repo.remote)
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/scm_unittest.py

    r266627 r266628  
    1 # Copyright (C) 2019 Apple Inc. All rights reserved.
     1# Copyright (C) 2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 import logging
    24 import os
    25 import sys
    2623
    27 log = logging.getLogger('webkitscmpy')
     24import unittest
     25from webkitscmpy import local, mocks
    2826
    2927
    30 def _maybe_add_webkitcorepy_path():
    31     # Hopefully we're beside webkitcorepy, otherwise webkitcorepy will need to be installed.
    32     libraries_path = os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
    33     webkitcorepy_path = os.path.join(libraries_path, 'webkitcorepy')
    34     if os.path.isdir(webkitcorepy_path) and os.path.isdir(os.path.join(webkitcorepy_path, 'webkitcorepy')) and webkitcorepy_path not in sys.path:
    35         sys.path.insert(0, webkitcorepy_path)
     28class TestScm(unittest.TestCase):
     29    path = '/mock/directory'
    3630
     31    def test_detection(self):
     32        with mocks.local.Git(), mocks.local.Svn():
     33            with self.assertRaises(OSError):
     34                local.Scm.from_path(self.path)
    3735
    38 _maybe_add_webkitcorepy_path()
     36    def test_root(self):
     37        with self.assertRaises(NotImplementedError):
     38            local.Scm(self.path).root_path
    3939
    40 try:
    41     from webkitcorepy.version import Version
    42 except ImportError:
    43     raise ImportError(
    44         "'webkitcorepy' could not be found on your Python path.\n" +
    45         "You are not running from a WebKit checkout.\n" +
    46         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
    47     )
     40    def test_branch(self):
     41        with self.assertRaises(NotImplementedError):
     42            local.Scm(self.path).branch
    4843
    49 version = Version(0, 0, 1)
    50 name = 'webkitscmpy'
     44    def test_remote(self):
     45        with self.assertRaises(NotImplementedError):
     46            local.Scm(self.path).remote()
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/svn_unittest.py

    r266627 r266628  
    1 # Copyright (C) 2019 Apple Inc. All rights reserved.
     1# Copyright (C) 2020 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 import logging
    2423import os
    25 import sys
     24import unittest
    2625
    27 log = logging.getLogger('webkitscmpy')
     26from webkitscmpy import local, mocks
    2827
    2928
    30 def _maybe_add_webkitcorepy_path():
    31     # Hopefully we're beside webkitcorepy, otherwise webkitcorepy will need to be installed.
    32     libraries_path = os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
    33     webkitcorepy_path = os.path.join(libraries_path, 'webkitcorepy')
    34     if os.path.isdir(webkitcorepy_path) and os.path.isdir(os.path.join(webkitcorepy_path, 'webkitcorepy')) and webkitcorepy_path not in sys.path:
    35         sys.path.insert(0, webkitcorepy_path)
     29class TestSvn(unittest.TestCase):
     30    path = '/mock/repository'
    3631
     32    def test_detection(self):
     33        with mocks.local.Svn(self.path), mocks.local.Git():
     34            detect = local.Scm.from_path(self.path)
     35            self.assertEqual(detect.executable, local.Svn.executable)
    3736
    38 _maybe_add_webkitcorepy_path()
     37    def test_root(self):
     38        with mocks.local.Svn(self.path):
     39            self.assertEqual(local.Svn(self.path).root_path, self.path)
    3940
    40 try:
    41     from webkitcorepy.version import Version
    42 except ImportError:
    43     raise ImportError(
    44         "'webkitcorepy' could not be found on your Python path.\n" +
    45         "You are not running from a WebKit checkout.\n" +
    46         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
    47     )
     41            with self.assertRaises(OSError):
     42                local.Svn(os.path.dirname(self.path)).root_path
    4843
    49 version = Version(0, 0, 1)
    50 name = 'webkitscmpy'
     44    def test_branch(self):
     45        with mocks.local.Svn(self.path):
     46            self.assertEqual(local.Svn(self.path).branch, 'trunk')
     47
     48    def test_remote(self):
     49        with mocks.local.Svn(self.path) as repo:
     50            self.assertEqual(local.Svn(self.path).remote(), repo.remote)
Note: See TracChangeset for help on using the changeset viewer.