edq-utils 0.4.2__tar.gz → 0.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. {edq_utils-0.4.2 → edq_utils-0.4.4}/PKG-INFO +2 -1
  2. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/__init__.py +1 -1
  3. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/cli.py +27 -0
  4. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/httpserver.py +4 -0
  5. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/unittest.py +16 -0
  6. edq_utils-0.4.4/edq/util/git.py +113 -0
  7. edq_utils-0.4.4/edq/util/git_test.py +29 -0
  8. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/time.py +15 -0
  9. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/PKG-INFO +2 -1
  10. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/SOURCES.txt +2 -0
  11. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/requires.txt +1 -0
  12. {edq_utils-0.4.2 → edq_utils-0.4.4}/requirements.txt +1 -0
  13. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/gen_docs.sh +1 -1
  14. {edq_utils-0.4.2 → edq_utils-0.4.4}/.github/workflows/main.yml +0 -0
  15. {edq_utils-0.4.2 → edq_utils-0.4.4}/.gitignore +0 -0
  16. {edq_utils-0.4.2 → edq_utils-0.4.4}/.mypy.ini +0 -0
  17. {edq_utils-0.4.2 → edq_utils-0.4.4}/.pylintrc +0 -0
  18. {edq_utils-0.4.2 → edq_utils-0.4.4}/LICENSE +0 -0
  19. {edq_utils-0.4.2 → edq_utils-0.4.4}/README.md +0 -0
  20. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/__main__.py +0 -0
  21. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/__init__.py +0 -0
  22. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/__main__.py +0 -0
  23. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/config/__init__.py +0 -0
  24. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/config/__main__.py +0 -0
  25. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/config/list.py +0 -0
  26. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/doc/__init__.py +0 -0
  27. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/doc/__main__.py +0 -0
  28. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/doc/update-pdoc-cli.py +0 -0
  29. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/__init__.py +0 -0
  30. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/__main__.py +0 -0
  31. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/exchange-server.py +0 -0
  32. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/send-exchange.py +0 -0
  33. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/http/verify-exchanges.py +0 -0
  34. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/testing/__init__.py +0 -0
  35. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/testing/__main__.py +0 -0
  36. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/testing/cli-test.py +0 -0
  37. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/cli/version.py +0 -0
  38. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/clilib/__init__.py +0 -0
  39. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/clilib/list.py +0 -0
  40. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/clilib/model.py +0 -0
  41. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/clilib/pdoc.py +0 -0
  42. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/__init__.py +0 -0
  43. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/argparser.py +0 -0
  44. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/argparser_test.py +0 -0
  45. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/config.py +0 -0
  46. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/config_test.py +0 -0
  47. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/errors.py +0 -0
  48. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/log.py +0 -0
  49. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/core/version.py +0 -0
  50. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/__init__.py +0 -0
  51. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/cli.py +0 -0
  52. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/exchange.py +0 -0
  53. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/exchangeserver.py +0 -0
  54. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/request.py +0 -0
  55. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/request_test.py +0 -0
  56. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/net/util.py +0 -0
  57. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/procedure/__init__.py +0 -0
  58. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/procedure/verify_exchanges.py +0 -0
  59. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/py.typed +0 -0
  60. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/__init__.py +0 -0
  61. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/asserts.py +0 -0
  62. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/cli_test.py +0 -0
  63. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/httpserver_test.py +0 -0
  64. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/run.py +0 -0
  65. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/serverrunner.py +0 -0
  66. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/empty/edq-config.json +0 -0
  67. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/simple-1/edq-config.json +0 -0
  68. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/simple-2/edq-config.json +0 -0
  69. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/data/configs/value-number/edq-config.json +0 -0
  70. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_base.txt +0 -0
  71. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_config_value_number.txt +0 -0
  72. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_ignore_config.txt +0 -0
  73. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_no_config.txt +0 -0
  74. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_show_origin.txt +0 -0
  75. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/config/list/config_list_skip_header.txt +0 -0
  76. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/help_base.txt +0 -0
  77. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/platform_skip.txt +0 -0
  78. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/cli/tests/version_base.txt +0 -0
  79. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple.httpex.json +0 -0
  80. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_anchor.httpex.json +0 -0
  81. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file.httpex.json +0 -0
  82. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_binary.httpex.json +0 -0
  83. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_get_params.httpex.json +0 -0
  84. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_multiple.httpex.json +0 -0
  85. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_name.httpex.json +0 -0
  86. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_post_multiple.httpex.json +0 -0
  87. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_file_post_params.httpex.json +0 -0
  88. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_headers.httpex.json +0 -0
  89. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_jsonresponse_dict.httpex.json +0 -0
  90. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_jsonresponse_list.httpex.json +0 -0
  91. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_params.httpex.json +0 -0
  92. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_post.httpex.json +0 -0
  93. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_post_params.httpex.json +0 -0
  94. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_post_urlparams.httpex.json +0 -0
  95. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/simple_urlparams.httpex.json +0 -0
  96. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/specialcase_listparams_explicit.httpex.json +0 -0
  97. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/exchanges/specialcase_listparams_url.httpex.json +0 -0
  98. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/files/a.txt +0 -0
  99. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/testing/testdata/http/files/tiny.png +0 -0
  100. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/__init__.py +0 -0
  101. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/code.py +0 -0
  102. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/code_test.py +0 -0
  103. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/constants.py +0 -0
  104. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/dirent.py +0 -0
  105. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/dirent_test.py +0 -0
  106. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/encoding.py +0 -0
  107. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/gzip.py +0 -0
  108. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/gzip_test.py +0 -0
  109. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/hash.py +0 -0
  110. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/hash_test.py +0 -0
  111. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/json.py +0 -0
  112. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/json_test.py +0 -0
  113. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/parse.py +0 -0
  114. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/pyimport.py +0 -0
  115. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/pyimport_test.py +0 -0
  116. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/reflection.py +0 -0
  117. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/base.ipynb +0 -0
  118. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/base.py +0 -0
  119. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/base_with_raise.ipynb +0 -0
  120. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/base_with_raise.py +0 -0
  121. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/simple.ipynb +0 -0
  122. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/testdata/code/simple.py +0 -0
  123. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq/util/time_test.py +0 -0
  124. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/dependency_links.txt +0 -0
  125. {edq_utils-0.4.2 → edq_utils-0.4.4}/edq_utils.egg-info/top_level.txt +0 -0
  126. {edq_utils-0.4.2 → edq_utils-0.4.4}/pyproject.toml +0 -0
  127. {edq_utils-0.4.2 → edq_utils-0.4.4}/requirements-dev.txt +0 -0
  128. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/build_site.sh +0 -0
  129. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_all.sh +0 -0
  130. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_lint.sh +0 -0
  131. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_python_version.sh +0 -0
  132. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_strict_types.sh +0 -0
  133. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/check_types.sh +0 -0
  134. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/run_tests.sh +0 -0
  135. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/template/html/css/style.css +0 -0
  136. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/template/html/favicon.ico +0 -0
  137. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/template/html/images/favicon.png +0 -0
  138. {edq_utils-0.4.2 → edq_utils-0.4.4}/scripts/template/html/index.html +0 -0
  139. {edq_utils-0.4.2 → edq_utils-0.4.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: edq-utils
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Common utilities used by EduLinq Python projects.
5
5
  Author-email: Eriq Augustine <eriq@edulinq.org>
6
6
  License: MIT License
@@ -34,6 +34,7 @@ Classifier: Programming Language :: Python :: 3.9
34
34
  Requires-Python: >=3.9
35
35
  Description-Content-Type: text/markdown
36
36
  License-File: LICENSE
37
+ Requires-Dist: GitPython>=3.1.31
37
38
  Requires-Dist: beautifulsoup4>=4.10.0
38
39
  Requires-Dist: json5>=0.9.14
39
40
  Requires-Dist: platformdirs
@@ -2,4 +2,4 @@
2
2
  General Python tools used by several EduLinq projects.
3
3
  """
4
4
 
5
- __version__ = '0.4.2'
5
+ __version__ = '0.4.4'
@@ -14,6 +14,7 @@ then this method will be called with the test info right after the test info is
14
14
 
15
15
  If a test class implements a class method with the signature `get_test_basename(cls, path: str) -> str`,
16
16
  then this method will be called to create the base name for the test case at the given path.
17
+ Otherwise, the file's basename will be used.
17
18
 
18
19
  The expected output or any argument can reference the test's current temp or data dirs with `__TEMP_DIR__()` or `__DATA_DIR__()`, respectively.
19
20
  An optional slash-separated path can be used as an argument to reference a path within those base directories.
@@ -282,6 +283,32 @@ def replace_path_pattern(text: str, key: str, target_dir: str, normalize_path: b
282
283
 
283
284
  return text
284
285
 
286
+ def compute_ancestor_basename(path: str, cli_tests_dir: str) -> str:
287
+ """
288
+ Get the test's name based off of its filename and location.
289
+ A useful fuction to use in get_test_basename().
290
+ """
291
+
292
+ path = os.path.abspath(path)
293
+
294
+ name = os.path.splitext(os.path.basename(path))[0]
295
+
296
+ # Clean drive identifiers (for Windows).
297
+ cli_tests_dir_path = os.path.splitdrive(os.path.abspath(cli_tests_dir))[1]
298
+ path = os.path.splitdrive(path)[1]
299
+
300
+ ancestors = os.path.dirname(path).replace(cli_tests_dir_path, '')
301
+ prefix = ancestors.replace(os.sep, '_')
302
+
303
+ if (prefix.startswith('_')):
304
+ prefix = prefix.replace('_', '', 1)
305
+
306
+ if (len(prefix) > 0):
307
+ name = f"{prefix}_{name}"
308
+
309
+ return name
310
+
311
+
285
312
  def _get_test_method(test_name: str, path: str, data_dir: str) -> typing.Callable:
286
313
  """ Get a test method that represents the test case at the given path. """
287
314
 
@@ -49,6 +49,8 @@ class HTTPServerTest(edq.testing.unittest.BaseTest):
49
49
 
50
50
  @classmethod
51
51
  def setUpClass(cls) -> None:
52
+ super().setUpClass()
53
+
52
54
  if (not cls._child_class_setup_called):
53
55
  cls.child_class_setup()
54
56
  cls._child_class_setup_called = True
@@ -65,6 +67,8 @@ class HTTPServerTest(edq.testing.unittest.BaseTest):
65
67
 
66
68
  @classmethod
67
69
  def tearDownClass(cls) -> None:
70
+ super().tearDownClass()
71
+
68
72
  if (cls.server_key not in cls._servers):
69
73
  return
70
74
 
@@ -1,9 +1,11 @@
1
+ import datetime
1
2
  import typing
2
3
  import unittest
3
4
 
4
5
  import edq.util.dirent
5
6
  import edq.util.json
6
7
  import edq.util.reflection
8
+ import edq.util.time
7
9
 
8
10
  FORMAT_STR: str = "\n--- Expected ---\n%s\n--- Actual ---\n%s\n---\n"
9
11
 
@@ -15,6 +17,20 @@ class BaseTest(unittest.TestCase):
15
17
  maxDiff = None
16
18
  """ Don't limit the size of diffs. """
17
19
 
20
+ testing_timezone: typing.Union[datetime.timezone, None] = edq.util.time.UTC
21
+
22
+ @classmethod
23
+ def setUpClass(cls) -> None:
24
+ super().setUpClass()
25
+
26
+ edq.util.time.set_testing_local_timezone(cls.testing_timezone)
27
+
28
+ @classmethod
29
+ def tearDownClass(cls) -> None:
30
+ super().tearDownClass()
31
+
32
+ edq.util.time.set_testing_local_timezone(None)
33
+
18
34
  def assertJSONEqual(self, a: typing.Any, b: typing.Any, message: typing.Union[str, None] = None) -> None: # pylint: disable=invalid-name
19
35
  """
20
36
  Like unittest.TestCase.assertEqual(),
@@ -0,0 +1,113 @@
1
+ """
2
+ Handle interfacing with git repos.
3
+ """
4
+
5
+ import os
6
+ import re
7
+ import typing
8
+
9
+ import git
10
+
11
+ UNKNOWN_VERSION: str = 'UNKNOWN'
12
+ VERSION_LEN: int = 8
13
+ DIRTY_SIFFIX: str = '-d'
14
+
15
+ def get_version(path: str = '.', throw: bool = False) -> str:
16
+ """
17
+ Get a version string from the git repo.
18
+ This is just a commit hash with some dressup.
19
+ """
20
+
21
+ if (os.path.isfile(path)):
22
+ path = os.path.dirname(path)
23
+
24
+ try:
25
+ repo = git.Repo(path, search_parent_directories = True)
26
+ version = repo.head.commit.tree.hexsha[:VERSION_LEN]
27
+ except Exception as ex:
28
+ if (throw):
29
+ raise ValueError(f"Path '{path}' is not a valid Git repo.") from ex
30
+
31
+ return UNKNOWN_VERSION
32
+
33
+ if (repo.is_dirty()):
34
+ version += DIRTY_SIFFIX
35
+
36
+ return version
37
+
38
+ def ensure_repo(
39
+ url: str,
40
+ path: str,
41
+ username: typing.Union[str, None] = None,
42
+ token: typing.Union[str, None] = None,
43
+ update: bool = False,
44
+ ref: typing.Union[str, None] = None,
45
+ ) -> None:
46
+ """
47
+ Ensure that a git repo exists locally.
48
+ Clone the repo if it does not exist.
49
+ Optionally update (pull) the repo.
50
+ """
51
+
52
+ if (os.path.isfile(path)):
53
+ raise ValueError(f"Target git path exists and is a file: '{path}'.")
54
+
55
+ if (not os.path.exists(path)):
56
+ clone(url, path, username = username, token = token)
57
+
58
+ repo = get_repo(path)
59
+
60
+ if (update):
61
+ update_repo(repo)
62
+
63
+ if (ref is not None):
64
+ checkout_repo(repo, ref)
65
+
66
+ def get_repo(path: str) -> git.Repo:
67
+ """ Get a reference to a git repo. """
68
+
69
+ return git.Repo(path)
70
+
71
+ def clone(
72
+ url: str,
73
+ path: str,
74
+ username: typing.Union[str, None] = None,
75
+ token: typing.Union[str, None] = None,
76
+ ) -> git.Repo:
77
+ """ Clone a git repo to the target location and return a reference to it. """
78
+
79
+ # If we have a username or password, we need to rewrite the URL.
80
+ # This is not very robust, but should work.
81
+ # After clone, the credentials are saved in the local git config.
82
+ if (username is not None):
83
+ if (token is None):
84
+ raise ValueError("If username is specified, a token must also be specified.")
85
+
86
+ auth_text = f"{username}:{token}"
87
+ url = re.sub(r'(http(s?)://)', rf"\1{auth_text}@", url)
88
+
89
+ return git.Repo.clone_from(url, path)
90
+
91
+ def checkout_repo(repo: git.Repo, ref: str) -> None:
92
+ """ Checkout the given reference on the given repo. """
93
+
94
+ repo.git.checkout(ref)
95
+
96
+ def update_repo(repo: git.Repo) -> bool:
97
+ """
98
+ Update (pull) the given repo.
99
+ Return true if an update occurred.
100
+ """
101
+
102
+ fetch_results = repo.remotes.origin.pull()
103
+
104
+ for fetch_result in fetch_results:
105
+ if (fetch_result.ref.name != f"origin/{repo.active_branch.name}"):
106
+ continue
107
+
108
+ if (fetch_result.flags == git.remote.FetchInfo.HEAD_UPTODATE):
109
+ return False
110
+
111
+ return True
112
+
113
+ return False
@@ -0,0 +1,29 @@
1
+ import os
2
+
3
+ import edq.testing.unittest
4
+ import edq.util.dirent
5
+ import edq.util.git
6
+
7
+ THIS_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
8
+
9
+ class TestGit(edq.testing.unittest.BaseTest):
10
+ """ Test git functionality. """
11
+
12
+ def test_version_in_repo(self):
13
+ """ Test getting a git version inside of a repo. """
14
+
15
+ version = edq.util.git.get_version(THIS_DIR)
16
+ self.assertNotEqual(edq.util.git.UNKNOWN_VERSION, version, 'Got an unknown version (assumes test is run in a repo).')
17
+
18
+ def test_version_cwd(self):
19
+ """ Test getting a git version using the current working directory. """
20
+
21
+ version = edq.util.git.get_version()
22
+ self.assertNotEqual(edq.util.git.UNKNOWN_VERSION, version, 'Got an unknown version (assumes test is run in a repo)')
23
+
24
+ def test_version_not_in_repo(self):
25
+ """ Test getting a git version when not inside of a repo. """
26
+
27
+ path = edq.util.dirent.get_temp_path(prefix = 'edq-test-git-')
28
+ version = edq.util.git.get_version(path)
29
+ self.assertEqual(edq.util.git.UNKNOWN_VERSION, version)
@@ -24,6 +24,18 @@ UNIXTIME_THRESHOLD_MSECS: int = int(1e13)
24
24
  UNIXTIME_THRESHOLD_USECS: int = int(1e16)
25
25
  """ Epoch time guessing threshold for nanoseconds. """
26
26
 
27
+ _testing_timezone: typing.Union[datetime.timezone, None] = None # pylint: disable=invalid-name
28
+ """ A timezone to use for testing. """
29
+
30
+ def set_testing_local_timezone(timezone: typing.Union[datetime.timezone, None] = UTC):
31
+ """
32
+ Force the local timezone to be a specific value (UTC by default).
33
+ This will only affect this package (e.g., the stdlib will not be affected).
34
+ """
35
+
36
+ global _testing_timezone # pylint: disable=global-statement
37
+ _testing_timezone = timezone
38
+
27
39
  class Duration(int):
28
40
  """
29
41
  A Duration represents some length in time in milliseconds.
@@ -204,6 +216,9 @@ class Timestamp(int):
204
216
  def get_local_timezone() -> datetime.timezone:
205
217
  """ Get the local (system) timezone or raise an exception. """
206
218
 
219
+ if (_testing_timezone is not None):
220
+ return _testing_timezone
221
+
207
222
  local_timezone = datetime.datetime.now().astimezone().tzinfo
208
223
  if ((local_timezone is None) or (not isinstance(local_timezone, datetime.timezone))):
209
224
  raise ValueError("Could not discover local timezone.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: edq-utils
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Common utilities used by EduLinq Python projects.
5
5
  Author-email: Eriq Augustine <eriq@edulinq.org>
6
6
  License: MIT License
@@ -34,6 +34,7 @@ Classifier: Programming Language :: Python :: 3.9
34
34
  Requires-Python: >=3.9
35
35
  Description-Content-Type: text/markdown
36
36
  License-File: LICENSE
37
+ Requires-Dist: GitPython>=3.1.31
37
38
  Requires-Dist: beautifulsoup4>=4.10.0
38
39
  Requires-Dist: json5>=0.9.14
39
40
  Requires-Dist: platformdirs
@@ -98,6 +98,8 @@ edq/util/constants.py
98
98
  edq/util/dirent.py
99
99
  edq/util/dirent_test.py
100
100
  edq/util/encoding.py
101
+ edq/util/git.py
102
+ edq/util/git_test.py
101
103
  edq/util/gzip.py
102
104
  edq/util/gzip_test.py
103
105
  edq/util/hash.py
@@ -1,3 +1,4 @@
1
+ GitPython>=3.1.31
1
2
  beautifulsoup4>=4.10.0
2
3
  json5>=0.9.14
3
4
  platformdirs
@@ -1,3 +1,4 @@
1
+ GitPython>=3.1.31
1
2
  beautifulsoup4>=4.10.0
2
3
  json5>=0.9.14
3
4
  platformdirs
@@ -37,7 +37,7 @@ function main() {
37
37
  fi
38
38
 
39
39
  # Update the docs with CLI information.
40
- python3 -m edq.cli.doc.update-pdoc-cli "${PACKAGE_DIR}" "${BASE_PACKAGE}" "${outputDir}"
40
+ NO_COLOR=1 python3 -m edq.cli.doc.update-pdoc-cli "${PACKAGE_DIR}" "${BASE_PACKAGE}" "${outputDir}"
41
41
  if [[ $? -ne 0 ]] ; then
42
42
  echo "Failed to update docs with CLI information."
43
43
  return 3
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes