moat-src 0.3.1__tar.gz → 0.5.2__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 (25) hide show
  1. {moat-src-0.3.1/moat_src.egg-info → moat-src-0.5.2}/PKG-INFO +1 -1
  2. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_main.py +45 -59
  3. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_templates/make/py +13 -6
  4. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_templates/pyproject.default.yaml +69 -0
  5. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/test.py +34 -0
  6. {moat-src-0.3.1 → moat-src-0.5.2/moat_src.egg-info}/PKG-INFO +1 -1
  7. {moat-src-0.3.1 → moat-src-0.5.2}/tests/test_basic.py +5 -0
  8. {moat-src-0.3.1 → moat-src-0.5.2}/.gitignore +0 -0
  9. {moat-src-0.3.1 → moat-src-0.5.2}/Makefile +0 -0
  10. {moat-src-0.3.1 → moat-src-0.5.2}/moat/__init__.py +0 -0
  11. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/__init__.py +0 -0
  12. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_templates/LICENSE.txt +0 -0
  13. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_templates/Makefile +0 -0
  14. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_templates/gitignore +0 -0
  15. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_templates/moat/__init__.py +0 -0
  16. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_templates/pyproject.forced.yaml +0 -0
  17. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/_templates/test_basic_py +0 -0
  18. {moat-src-0.3.1 → moat-src-0.5.2}/moat/src/inspect.py +0 -0
  19. {moat-src-0.3.1 → moat-src-0.5.2}/moat_src.egg-info/SOURCES.txt +0 -0
  20. {moat-src-0.3.1 → moat-src-0.5.2}/moat_src.egg-info/dependency_links.txt +0 -0
  21. {moat-src-0.3.1 → moat-src-0.5.2}/moat_src.egg-info/requires.txt +0 -0
  22. {moat-src-0.3.1 → moat-src-0.5.2}/moat_src.egg-info/top_level.txt +0 -0
  23. {moat-src-0.3.1 → moat-src-0.5.2}/pyproject.toml +0 -0
  24. {moat-src-0.3.1 → moat-src-0.5.2}/setup.cfg +0 -0
  25. {moat-src-0.3.1 → moat-src-0.5.2}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: moat-src
3
- Version: 0.3.1
3
+ Version: 0.5.2
4
4
  Summary: Tools for managing the MoaT sources
5
5
  Author-email: Matthias Urlichs <matthias@urlichs.de>
6
6
  Project-URL: homepage, https://m-o-a-t.org
@@ -38,27 +38,26 @@ class Repo(git.Repo):
38
38
  mi = p.parts.index("moat")
39
39
  self.moat_name = "-".join(p.parts[mi:])
40
40
 
41
- def subrepos(self, recurse=True, depth=True):
41
+ def subrepos(self, recurse=True, depth=True, same=True):
42
42
  """List subrepositories (and cache them)."""
43
43
 
44
- if recurse and not depth:
44
+ if same and recurse and not depth:
45
45
  yield self
46
46
 
47
- if "/lib/" in self.working_dir:
48
- return
49
- for r in self.submodules:
50
- try:
51
- res = self._subrepo_cache[r.path]
52
- except KeyError:
53
- p = Path(self.working_dir) / r.path
54
- self._subrepo_cache[r.path] = res = Repo(p)
55
- res.submod = r
56
- if recurse:
57
- yield from res.subrepos(depth=depth)
58
- else:
59
- yield res
47
+ if "/lib/" not in self.working_dir:
48
+ for r in self.submodules:
49
+ try:
50
+ res = self._subrepo_cache[r.path]
51
+ except KeyError:
52
+ p = Path(self.working_dir) / r.path
53
+ self._subrepo_cache[r.path] = res = Repo(p)
54
+ res.submod = r
55
+ if recurse:
56
+ yield from res.subrepos(depth=depth)
57
+ else:
58
+ yield res
60
59
 
61
- if recurse and depth:
60
+ if same and recurse and depth:
62
61
  yield self
63
62
 
64
63
  def commits(self, ref=None):
@@ -444,10 +443,10 @@ async def setup(no_dirty, no_commit, skip, only, message, amend, no_amend):
444
443
 
445
444
  Default: amend if the text is identical and the prev head isn't tagged.
446
445
  """
447
- repo = Repo(None)
446
+ repo = Repo()
448
447
  skip = set(skip)
449
448
  if only:
450
- repos = (Repo(repo, x) for x in only)
449
+ repos = (Repo(x) for x in only)
451
450
  else:
452
451
  repos = (x for x in repo.subrepos(depth=True) if x.moat_name[5:] not in skip)
453
452
 
@@ -547,10 +546,13 @@ async def fix_main(repo):
547
546
 
548
547
  async def _fix(r):
549
548
  if not r.head.is_detached:
550
- if r.head.ref.name != "main":
549
+ if r.head.ref.name not in {"main", "moat"}:
551
550
  print(f"{r.working_dir}: Head is {r.head.ref.name !r}", file=sys.stderr)
552
551
  return
553
- m = r.refs["main"]
552
+ if "moat" in r.refs:
553
+ m = r.refs["moat"]
554
+ else:
555
+ m = r.refs["main"]
554
556
  if m.commit != r.head.commit:
555
557
  ch = await run_process(
556
558
  ["git", "-C", r.working_dir, "merge-base", m.commit.hexsha, r.head.commit.hexsha],
@@ -564,7 +566,6 @@ async def fix_main(repo):
564
566
  m.set_reference(ref=r.head.commit, logmsg="fix_main")
565
567
  r.head.set_reference(ref=m, logmsg="fix_main 2")
566
568
 
567
- await _fix(repo)
568
569
  for r in repo.subrepos():
569
570
  await _fix(r)
570
571
 
@@ -608,7 +609,7 @@ async def push(obj, remote):
608
609
 
609
610
  @cli.command()
610
611
  @click.option("-r", "--remote", type=str, help="Remote to fetch. Default: probably 'origin'.")
611
- @click.option("-b", "--branch", type=str, default="main", help="Branch to merge.")
612
+ @click.option("-b", "--branch", type=str, default=None, help="Branch to merge.")
612
613
  @click.pass_obj
613
614
  async def pull(obj, remote, branch):
614
615
  """Fetch updates"""
@@ -631,7 +632,9 @@ async def pull(obj, remote, branch):
631
632
  elif obj.debug > 1:
632
633
  cmd.append("-v")
633
634
  if remote is not None:
634
- cmd.append(remote if branch is None else f"{remote}/{branch}")
635
+ if branch is None:
636
+ branch = "moat" if "moat" in r.refs else "main"
637
+ cmd.append(f"{remote}/{branch}")
635
638
  await run_process(cmd, input=None, stdout=sys.stdout, stderr=sys.stderr)
636
639
 
637
640
  except subprocess.CalledProcessError as exc:
@@ -692,6 +695,10 @@ async def build(version, no_test, no_commit, no_dirty, cache):
692
695
 
693
696
  heads[r.moat_name] = r.commit().hexsha
694
697
  t = r.tagged(r.head.commit)
698
+ if t is not None:
699
+ if r.is_dirty(index=False, working_tree=False, untracked_files=False, submodules=True):
700
+ t = None
701
+
695
702
  if t is None:
696
703
  for c in r.commits():
697
704
  t = r.tagged(c)
@@ -720,7 +727,7 @@ async def build(version, no_test, no_commit, no_dirty, cache):
720
727
 
721
728
  dirty = set()
722
729
 
723
- check = check1 = True
730
+ check = True
724
731
 
725
732
  while check:
726
733
  check = False
@@ -752,17 +759,10 @@ async def build(version, no_test, no_commit, no_dirty, cache):
752
759
  for v in deps.values():
753
760
  work = fix_deps(v, tags) | work
754
761
 
755
- if check1:
756
- if r.is_dirty(
757
- index=True, working_tree=True, untracked_files=False, submodules=True
758
- ):
759
- for rr in r.subrepos(recurse=False):
760
- r.git.add(rr.working_dir)
761
- work = True
762
-
763
762
  if work:
764
763
  p.write_text(pr.as_string())
765
764
  r.index.add(p)
765
+ if work or r.is_dirty(index=False, working_tree=False, submodules=True):
766
766
  dirty.add(r)
767
767
  t = tags[r.moat_name]
768
768
  if not isinstance(t, str):
@@ -771,41 +771,27 @@ async def build(version, no_test, no_commit, no_dirty, cache):
771
771
  tags[r.moat_name] = t
772
772
  check = True
773
773
 
774
- check1 = False
775
-
776
774
  if bad:
777
775
  print("Partial work done. Fix and try again.")
778
776
  return
779
777
 
780
778
  if not no_commit:
781
- for r in dirty:
782
- r.index.commit("Update MoaT requirements")
783
-
784
- if repo.is_dirty(index=True, working_tree=True, untracked_files=False, submodules=True):
785
- for r in repo.subrepos():
786
- if r is repo:
787
- continue
788
- t = tags[r.moat_name]
789
- if isinstance(t, str):
790
- r.create_tag(t)
779
+ for r in repo.subrepos(depth=True):
780
+ if not r.is_dirty(
781
+ index=True, working_tree=True, untracked_files=False, submodules=True
782
+ ):
783
+ continue
791
784
 
792
- for r in repo.subrepos(recurse=False):
793
- repo.git.add(r.working_dir)
794
- repo.index.commit("Update")
785
+ if r in dirty:
786
+ r.index.commit("Update MoaT requirements")
795
787
 
796
- for c in repo.commits():
797
- t = repo.tagged(c)
798
- if t is not None:
799
- break
800
- else:
801
- print("NO TAG", repo.moat_name)
802
- return
803
-
804
- xt, t = t.name.rsplit(".", 1)
805
- t = f"{xt}.{int(t)+1}"
788
+ for rr in r.subrepos(recurse=False):
789
+ r.git.add(rr.working_dir)
790
+ r.index.commit("Submodule Update")
806
791
 
807
- print("New:", t)
808
- repo.create_tag(t)
792
+ t = tags[r.moat_name]
793
+ if isinstance(t, str):
794
+ r.create_tag(t)
809
795
 
810
796
 
811
797
  add_repr(tomlkit.items.String)
@@ -15,6 +15,8 @@ CODE ?= $(subst -,/,$(PACKAGE))
15
15
  BUILD_DIR ?= build
16
16
  INPUT_DIR ?= docs/source
17
17
 
18
+ RQ := grep -qs tool.ruff pyproject.toml
19
+
18
20
  # Sphinx options (are passed to build_docs, which passes them to sphinx-build)
19
21
  # -W : turn warning into errors
20
22
  # -a : write all files
@@ -60,16 +62,21 @@ cov:
60
62
 
61
63
  test: statictest pytest
62
64
  statictest:
63
- black --check $(CODE) $(TESTS) $(SETUP)
64
- python3 -misort --check $(CODE) $(TESTS) $(SETUP)
65
- flake8p $(CODE) $(TESTS) $(SETUP)
66
- pylint $(CODE) $(TESTS) $(SETUP)
65
+ ${RQ} || black --check $(CODE) $(TESTS) $(SETUP)
66
+ ${RQ} || python3 -misort --check $(CODE) $(TESTS) $(SETUP)
67
+ ${RQ} || flake8p $(CODE) $(TESTS) $(SETUP)
68
+ ${RQ} || pylint $(CODE) $(TESTS) $(SETUP)
69
+ ${RQ} && ruff format $(CODE) $(TESTS) $(SETUP)
70
+ ${RQ} && ruff check $(CODE) $(TESTS) $(SETUP)
71
+
67
72
  pytest:
68
73
  $(PYTEST) $(PYTEST_OPTIONS) $(TESTS)
69
74
 
70
75
  format:
71
- black $(CODE) $(TESTS) $(SETUP)
72
- python3 -misort $(CODE) $(TESTS) $(SETUP)
76
+ ${RQ} || black $(CODE) $(TESTS) $(SETUP)
77
+ ${RQ} || python3 -misort $(CODE) $(TESTS) $(SETUP)
78
+ ${RQ} && ruff format $(CODE) $(TESTS) $(SETUP)
79
+ ${RQ} && ruff check --fix $(CODE) $(TESTS) $(SETUP)
73
80
 
74
81
  precommit: format test
75
82
 
@@ -27,6 +27,75 @@ project:
27
27
  homepage: https://m-o-a-t.org
28
28
  repository: https://github.com/M-o-a-T/SUBNAME
29
29
  tool:
30
+ pytest:
31
+ ini_options:
32
+ log_cli_level: DEBUG
33
+ ruff:
34
+ select:
35
+ - ALL
36
+ ignore:
37
+ - ANN
38
+ - PTH
39
+ - PERF
40
+ - D105
41
+ - D107
42
+ - A003
43
+ - S101
44
+ - RUF001
45
+ - RUF002
46
+ - PLW1514
47
+ - D2
48
+ - D3
49
+ - D4
50
+ - T2
51
+ - FBT
52
+ - TRY003
53
+ - EM10
54
+ - PLR
55
+ - C
56
+ - RET50
57
+ - TD
58
+ - FIX
59
+ - N
60
+ - ERA
61
+ - BLE001
62
+ preview: true
63
+ explicit-preview-rules: true
64
+ line-length: 99
65
+ flake8-comprehensions:
66
+ allow-dict-calls-with-keyword-arguments: true
67
+ flake8-builtins:
68
+ builtins-ignorelist:
69
+ - id
70
+ - help
71
+ isort:
72
+ no-lines-before:
73
+ - future
74
+ required-imports:
75
+ - "from __future__ import annotations"
76
+ section-order:
77
+ - future
78
+ - typing
79
+ - standard-library
80
+ - first-party
81
+ - upy
82
+ - moat
83
+ - local-folder
84
+ - third-party
85
+ extra-standard-library:
86
+ - pytest
87
+ - anyio
88
+ force-to-top:
89
+ - moat.util
90
+ sections:
91
+ moat:
92
+ - moat
93
+ upy:
94
+ - micropython
95
+ - machine
96
+ - esp
97
+ typing:
98
+ - typing
30
99
  black:
31
100
  line-length: 99
32
101
  flake8:
@@ -5,6 +5,7 @@ import io
5
5
  import logging
6
6
  import shlex
7
7
  import sys
8
+ from contextlib import contextmanager
8
9
 
9
10
  from asyncscope import main_scope, scope
10
11
  from moat.util import OptCtx, attrdict, wrap_main # pylint:disable=no-name-in-module
@@ -41,6 +42,10 @@ async def run(*args, expect_exit=0, do_stdout=True):
41
42
  res = exc
42
43
  assert exc.code == expect_exit, exc.code
43
44
  return exc
45
+ except Exception as exc:
46
+ while isinstance(exc,ExceptionGroup) and len(exc.exceptions) == 1:
47
+ exc = exc.exceptions[0]
48
+ raise exc
44
49
  except BaseException as exc:
45
50
  res = exc
46
51
  raise
@@ -48,6 +53,35 @@ async def run(*args, expect_exit=0, do_stdout=True):
48
53
  assert expect_exit == 0
49
54
  return res
50
55
  finally:
56
+ if res is None:
57
+ res = attrdict()
51
58
  if do_stdout:
52
59
  res.stdout = out.getvalue()
53
60
  CFG["_stdout"] = sys.stdout
61
+
62
+
63
+ class DidNotRaise(Exception):
64
+ pass
65
+
66
+
67
+ @contextmanager
68
+ def raises(*exc):
69
+ """
70
+ Like pytest.raises, but handles exception groups
71
+ """
72
+ res = attrdict()
73
+ try:
74
+ yield res
75
+ except exc as e:
76
+ res.value = e
77
+ pass
78
+ except ExceptionGroup as e:
79
+ while isinstance(e,ExceptionGroup) and len(e.exceptions) == 1:
80
+ e = e.exceptions[0]
81
+ res.value = e
82
+ if isinstance(e,exc):
83
+ return
84
+ raise
85
+ else:
86
+ res.value = None
87
+ raise DidNotRaise(exc)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: moat-src
3
- Version: 0.3.1
3
+ Version: 0.5.2
4
4
  Summary: Tools for managing the MoaT sources
5
5
  Author-email: Matthias Urlichs <matthias@urlichs.de>
6
6
  Project-URL: homepage, https://m-o-a-t.org
@@ -3,6 +3,7 @@ Empty test file
3
3
  """
4
4
 
5
5
  import moat.src # pylint: disable=unused-import
6
+ from moat.src.test import raises
6
7
 
7
8
 
8
9
  def test_nothing():
@@ -10,3 +11,7 @@ def test_nothing():
10
11
  Empty test
11
12
  """
12
13
  pass # pylint: disable=unnecessary-pass
14
+ with raises(SyntaxError):
15
+ raise SyntaxError("foo")
16
+
17
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes