Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starbase migration #22

Merged
merged 209 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
209 commits
Select commit Hold shift + click to select a range
b36b88c
Initial commit
lengau Jan 20, 2023
23aa1a7
base: Initial specification for the base repository (#2)
lengau Jan 25, 2023
552c132
tools: Update tox and setuptools to fix breakages (#4)
lengau Jan 25, 2023
9a0cae5
tools: Split unit and integration tests
lengau Jan 25, 2023
f676cdc
tools: Make renovate cleaner. (#5)
lengau Jan 25, 2023
70a1551
Better comment
lengau Jan 25, 2023
229ee11
tools: Configure mypy (#6)
lengau Jan 26, 2023
63fc646
tools: Split unit and integration tests (#7)
lengau Jan 26, 2023
605bec2
docs: Basic sphinx docs
lengau Jan 26, 2023
28bb9d8
tests: coverage has per-env files
lengau Jan 26, 2023
4d76e9f
Merge remote-tracking branch 'origin/integration-test' into integrati…
lengau Jan 26, 2023
a59bb4d
tools: Make typing use an editable install
lengau Jan 26, 2023
b715342
Merge pull request #14 from lengau/pyright
lengau Jan 26, 2023
7e30bab
Merge pull request #13 from lengau/integration-test
lengau Jan 26, 2023
77b955b
Configure sphinx-lint
lengau Jan 26, 2023
08a1e8d
Merge pull request #12 from lengau/sphinx
lengau Jan 26, 2023
f2f804d
chore(tools): Make pyproject.toml exclude rather than include
lengau Jan 26, 2023
283c21e
Merge pull request #15 from lengau/auto-find
lengau Jan 26, 2023
067df32
chore(deps): update release-drafter/release-drafter action to v5.22.0
renovate[bot] Jan 28, 2023
f3e23e3
chore(deps): update dependency pytest to v7.2.1
renovate[bot] Jan 28, 2023
bcadedb
chore(deps): update dependency tox to v4.4.2
renovate[bot] Jan 28, 2023
84cc930
Merge pull request #19 from canonical/renovate/tox-4.x
lengau Jan 28, 2023
97ca903
Merge pull request #17 from canonical/renovate/github-actions
lengau Jan 28, 2023
1a08aca
chore(deps): update dependency tox-ignore-env-name-mismatch to v0.2.0…
renovate[bot] Jan 28, 2023
cc3957c
Merge pull request #16 from canonical/renovate/patch-updates
lengau Jan 28, 2023
eb5a438
Merge pull request #18 from canonical/renovate/pytest-7.x
lengau Jan 30, 2023
0f3d7d0
lint: specify a single ruff version (#21)
lengau Feb 1, 2023
5a0d09f
tools: add yamllint (#11)
lengau Feb 1, 2023
9c1ea2a
readme: update name (#23)
sergiusens Feb 1, 2023
f3d35a6
chore(lint): update ruff and config (#22)
lengau Feb 1, 2023
cd2832b
tools: add sphinx-lint to regular linting
tigarmo Feb 3, 2023
130845c
docs: use Ubuntu font
tigarmo Feb 3, 2023
ec396df
docs: treat warnings as errors in build
tigarmo Feb 3, 2023
34e0222
tools: add sphinx-autobuild
tigarmo Feb 3, 2023
dbd1b1d
tools: rename sphinx-build and rundocs
tigarmo Feb 3, 2023
8abb221
chore(deps): update dependency setuptools to v67 (#26)
renovate[bot] Feb 5, 2023
4b3781b
chore(deps): update patch updates (#25)
renovate[bot] Feb 5, 2023
679c20f
tools: Add editorconfig (#9)
lengau Feb 6, 2023
2aaed7e
tools: improve coverage support in the tox test environments (#32)
lengau Feb 13, 2023
f4774ed
tools: fix the PR template name (#31)
lengau Feb 13, 2023
3ea924f
chore(deps): update dependency setuptools to v67.2.0 (#30)
renovate[bot] Feb 13, 2023
2c6d0ba
chore(deps): update patch updates (#29)
renovate[bot] Feb 14, 2023
a0e2622
lint(shellcheck): replace `find` with `git ls-files` (#33)
mr-cal Feb 17, 2023
2390266
lint: freeze the linter versions (#27)
lengau Feb 17, 2023
ee3c053
lint: skip more commonly ignored files and directories with codespell…
mr-cal Feb 17, 2023
d9c79f0
chore(deps): update dependency mypy to v1 (#39)
renovate[bot] Feb 19, 2023
867bb8f
chore(deps): update dependency ruff to v0.0.247 (#37)
renovate[bot] Feb 19, 2023
821339b
chore(deps): update dependency black to v23 (#38)
renovate[bot] Feb 19, 2023
6b9719a
chore(deps): update dependency setuptools to v67.3.2 (#36)
renovate[bot] Feb 19, 2023
cf1d018
deps: group major dev dependency versions (#28)
lengau Feb 19, 2023
c99b12b
chore(deps): update patch updates (#40)
renovate[bot] Feb 28, 2023
ffa1dec
chore(deps): update dependency coverage to v7.2.1 (#42)
renovate[bot] Feb 28, 2023
6c1a196
chore(deps): update dependency setuptools to v67.4.0 (#43)
renovate[bot] Feb 28, 2023
c0ccfda
chore(deps): update release-drafter/release-drafter action to v5.23.0…
renovate[bot] Feb 28, 2023
7f8ff19
docs: Tox environments and labels (#44)
lengau Mar 1, 2023
e1a7c75
ci: don't upload test results when cancelling the workflow #46
lengau Mar 9, 2023
4cd5f91
chore(deps): update patch updates (#45)
renovate[bot] Mar 19, 2023
a4a079a
chore(deps): update dependency setuptools to v67.6.0 (#48)
renovate[bot] Mar 20, 2023
2206424
chore(deps): update dependency mypy to v1.1.1 (#47)
renovate[bot] Mar 28, 2023
fe58f83
chore(deps): update dependency black to v23.3.0 (#49)
renovate[bot] May 10, 2023
3f6896c
chore(deps): update dependency mypy to v1.2.0 (#50)
renovate[bot] May 10, 2023
263a302
chore(deps): update dependency furo to v2023 (#52)
renovate[bot] May 10, 2023
9de5c85
chore(deps): update dependency yamllint to v1.31.0 (#51)
renovate[bot] May 10, 2023
4adb069
tox: move deps from tox.ini into pyproject.toml (#53)
lengau May 10, 2023
eaa6714
deps: fix renovate automerge schedule
lengau May 10, 2023
c6464d4
tools: further improve renovate
lengau May 10, 2023
39c3a7f
chore(deps): update dependency setuptools to v67.7.2 (#57)
renovate[bot] May 18, 2023
22ec1ca
chore(deps): update dependency types/mypy to v1.3.0 (#58)
renovate[bot] May 18, 2023
8d2bbf7
chore(deps): update dependency dev/pytest to v7.3.1 (#59)
renovate[bot] May 18, 2023
eae3d8a
chore(deps): update dependency docs/sphinx-design to v0.4.1 (#60)
renovate[bot] May 18, 2023
dba8423
chore(deps): update dependency lint/yamllint to v1.31.0 (#61)
renovate[bot] May 18, 2023
8cc8d44
chore(deps): update dependency sphinx-copybutton to v0.5.2 (#63)
renovate[bot] May 18, 2023
ff2ac00
chore(deps): update dependency coverage to v7.2.5 (#64)
renovate[bot] May 18, 2023
1949d4c
chore(deps): update bugfixes (#62)
renovate[bot] May 18, 2023
cc4c430
ci: add documentation build (#65)
lengau May 19, 2023
189835b
tools: fix ruff linting command in tox (#66)
lengau May 19, 2023
ffe9887
chore(deps): update dependency ruff to v0.0.269 (#69)
renovate[bot] May 19, 2023
3fd96e9
chore(deps): update bugfixes (#70)
renovate[bot] May 19, 2023
f4f5541
docs: update sphinx to 6
lengau May 19, 2023
06c70ba
meta: dynamic version info (#67)
lengau May 19, 2023
78f1252
tools: improve renovate config (#72)
lengau May 19, 2023
7a22e93
tools: add pre-commit (#68)
lengau May 19, 2023
01be79d
.gitignore: ignore direnv's .envrc file (#75)
mr-cal May 19, 2023
d6c7315
chore(deps): update dependency docs/furo to v2023.5.20 (#76)
renovate[bot] May 22, 2023
4477363
chore(deps): update dependency lint/yamllint to v1.32.0 (#77)
renovate[bot] May 22, 2023
82c2f3f
ci: fix release-drafter config (#78)
lengau May 22, 2023
e64e1e0
ci: fix name of release-drafter config file (#79)
tigarmo May 24, 2023
d38e78c
meta: dynamic versioning (#80)
lengau May 25, 2023
ba60c11
chore(deps): update development dependencies (non-major) (#83)
renovate[bot] Jun 6, 2023
b5cda0d
lint: stricter ruff rules (#55)
lengau Jun 6, 2023
43f86da
tests: move starbase tests to sub-directories (#85)
mr-cal Jun 7, 2023
e150fe2
ci: configure tox to disable listing dependencies (#87)
lengau Jun 8, 2023
7ab2ef4
ci: cache pip packages (#88)
lengau Jun 9, 2023
201327e
tox/ci: update Python versions tested (#89)
lengau Jun 9, 2023
f3c4f88
lint: ignore ruff SIM117 (#90)
mr-cal Jun 9, 2023
afc4246
chore(deps): update dependency tox-gh to v1.2.0 (#92)
renovate[bot] Jun 11, 2023
f40aae9
chore(deps): update dependency lint/ruff to v0.0.272 (#91)
renovate[bot] Jun 11, 2023
0b9e9cf
meta: update versioning scheme (#86)
mr-cal Jun 13, 2023
296c5dd
lint: fix mypy config to 'recurse' (#94)
tigarmo Jun 14, 2023
72c7781
chore(deps): update development dependencies (non-major) (#95)
renovate[bot] Jun 14, 2023
8c64fc4
meta: add dirty flag to versioning scheme (#96)
mr-cal Jun 16, 2023
0f6657d
ci: lint docs in all directories (#98)
mr-cal Jun 20, 2023
9985d46
tools: fix 'setuptools.package.find' directive (#97)
tigarmo Jun 20, 2023
25d1c10
tests: provide a fixture with the project's 'main' module (#99)
tigarmo Jun 21, 2023
61afd7e
coverage: automatically exclude type checking blocks (#100)
lengau Jun 22, 2023
ab5e737
ruff: remove type-checking guard blocks (#101)
lengau Jun 22, 2023
3f7c6fa
tox: pass CI environment variable (#102)
lengau Jun 22, 2023
6363b31
tools: Add release GH action (#103)
lengau Jun 23, 2023
3769823
pyproject: only include the actual package in wheel file (#108)
lengau Jun 26, 2023
8b8fed8
tox: improve UX (#106)
lengau Jun 29, 2023
3244cc2
ci: separate unit and integration tests (#107)
lengau Jun 29, 2023
41f0124
ci: make release publisher workflow fetch correct tags (#110)
lengau Jul 3, 2023
c634986
renovate: fix scheduling (#113)
lengau Jul 6, 2023
6a8bb7f
chore(deps): update development dependencies (non-major) (#115)
renovate[bot] Jul 11, 2023
5faae73
chore(deps): update release-drafter/release-drafter action to v5.24.0…
renovate[bot] Aug 15, 2023
be3ae62
chore(deps): update dependency lint/ruff to v0.0.284 (#119)
renovate[bot] Aug 15, 2023
366e466
chore(deps): update dependency tox-gh to v1.3.1 (#121)
renovate[bot] Aug 15, 2023
2a28541
chore(deps): update documentation dependencies (#120)
renovate[bot] Aug 15, 2023
3fca437
chore(deps): update dependency docs/sphinx to v7
renovate[bot] Aug 15, 2023
841c322
Update pyproject.toml
lengau Aug 15, 2023
9d017f3
chore(deps): update dependency docs/furo to v2023.8.19 (#122)
renovate[bot] Aug 23, 2023
25c3c1d
chore(deps): update dependency lint/ruff to v0.0.285 (#123)
renovate[bot] Aug 23, 2023
a913629
chore(deps): update development dependencies (non-major) (#124)
renovate[bot] Aug 23, 2023
8322768
docs: add conventional commits as part of the style
sergiusens Aug 24, 2023
fe1f9b0
ci: check for conventional commits
sergiusens Aug 24, 2023
6577523
ci(renovate): allow more branches (#126)
mr-cal Sep 11, 2023
de65e53
ci(renovate): run tests on renovate branches (#127)
mr-cal Sep 19, 2023
edf7d5a
chore: skip typing checkers in "_version.py" (#128)
mr-cal Sep 21, 2023
04f5a63
chore(deps): update dependency docs/furo to v2023.9.10 (#129)
renovate[bot] Sep 22, 2023
4e97b3f
chore(deps): update dependency lint/ruff to v0.0.290 (#130)
renovate[bot] Sep 22, 2023
3d09653
style: ensure ruff picks up pydantic.validator for class methods (#134)
lengau Oct 2, 2023
aa095b1
chore(deps): update actions/checkout action to v4 (#132)
renovate[bot] Oct 3, 2023
c3c3313
chore(deps): update dependency lint/ruff to v0.0.291 (#131)
renovate[bot] Oct 3, 2023
a8e334e
chore(deps): update dependency lint/ruff to v0.1.0 (#138)
renovate[bot] Oct 20, 2023
e668f36
chore(deps): update release-drafter/release-drafter action to v5.25.0…
renovate[bot] Oct 21, 2023
62cafda
chore(deps): update dependency docs/sphinx-lint to v0.8.1 (#141)
renovate[bot] Oct 21, 2023
6f1c345
chore(deps): update development dependencies (non-major) (#137)
renovate[bot] Oct 21, 2023
6b79ebe
chore(deps): update dependency lint/ruff to v0.1.1 (#142)
renovate[bot] Oct 22, 2023
eae2528
ci: colorize tox (#145)
mr-cal Nov 5, 2023
f78477e
feat(ruff): allow use Any in star args and kwargs (#144)
syu-w Nov 5, 2023
bd97d83
chore(deps): include ruff in dev updates (#146)
lengau Nov 5, 2023
406c056
chore: update renovate config (#143)
lengau Nov 5, 2023
624e393
build: run Renovate immediately on craft-* patch releases (#147)
lengau Nov 9, 2023
4ca930b
style(lint): bump max function args to 8 (#149)
lengau Nov 10, 2023
b58ed6f
style(lint): private member access (#150)
lengau Nov 10, 2023
073e450
style(lint): disable magic value check in tests (#151)
lengau Nov 17, 2023
a48d590
style: stricter ruff linters (#139)
lengau Nov 20, 2023
cc5a039
chore(deps): update development dependencies (non-major) (#153)
renovate[bot] Nov 27, 2023
0eead76
chore(deps): update dependency docs/sphinx-lint to v0.9.0 (#152)
renovate[bot] Nov 27, 2023
36a4cbf
chore(deps): update dependency types/pyright to v1.1.338 (#155)
renovate[bot] Dec 4, 2023
54ea9f5
chore(deps): update webiny/action-conventional-commits action to v1.2…
renovate[bot] Dec 4, 2023
46e9d22
chore: make renovate update pre-commit-config (#156)
lengau Dec 5, 2023
86b7568
chore: use new mypy config `extra_checks` (#158)
mr-cal Dec 7, 2023
5d46027
chore(deps): update actions/setup-python action to v5 (#161)
renovate[bot] Dec 11, 2023
0d328c4
style: ignore docstring requirements for overrides (#159)
lengau Dec 12, 2023
4b2c78e
docs(HACKING): update commit message guidelines (#162)
mr-cal Dec 15, 2023
ade6eba
ci(deps): update artifact actions (#164)
lengau Jan 4, 2024
8931c9a
chore(deps): update actions/download-artifact action to v4 (#163)
renovate[bot] Jan 4, 2024
d6130fd
ci(deps): make renovate update pyright separately. (#165)
lengau Jan 4, 2024
48adeaf
chore(deps): update dependency docs/sphinx-lint to v0.9.1 (#166)
renovate[bot] Jan 6, 2024
cf0b86c
chore(deps): update dependency setuptools to v67.8.0 (#167)
renovate[bot] Jan 10, 2024
a1c10a7
chore(deps): update dependency setuptools to v69 (#168)
renovate[bot] Jan 11, 2024
621a105
chore(deps): update dependency lint/black to v24 (#169)
renovate[bot] Jan 30, 2024
f460547
chore(deps): update dependency docs/furo to v2024 (#173)
renovate[bot] Jan 31, 2024
2d56dce
chore(deps): update webiny/action-conventional-commits action to v1.3.0
renovate[bot] Jan 31, 2024
20eb129
build(deps): update pyright (#170)
lengau Jan 31, 2024
3feb312
chore(deps): update development dependencies (non-major) (#174)
renovate[bot] Jan 31, 2024
ceb64e2
ci: fix regex for pre-commit-config.yaml (#175)
tigarmo Jan 31, 2024
d79b26b
chore(deps): update dependency dev/pytest to v8 (#172)
renovate[bot] Jan 31, 2024
9815d93
chore(deps): update dependency black to v24 (#176)
renovate[bot] Feb 1, 2024
c6d29c3
chore(deps): update dependency ruff to v0.1.15 (#177)
renovate[bot] Feb 1, 2024
0cfc30a
chore(deps): update dependency yamllint to v1.33.0 (#178)
renovate[bot] Feb 1, 2024
5a0b0ea
chore(deps): update dependency lint/ruff to v0.2.0 (#181)
renovate[bot] Feb 5, 2024
4d11ec4
chore(deps): update github actions
renovate[bot] Feb 5, 2024
f6db1eb
chore: make pre-commit linters use lint group for renovate (#183)
lengau Feb 5, 2024
234b360
docs(HACKING): clarify commit header for merges (#184)
mr-cal Feb 5, 2024
5b1422b
ci(renovate): fix pre-commit dependency manager (#185)
lengau Feb 6, 2024
64dc591
chore(deps): update dependency docs/sphinx-autobuild to v2024 (#187)
renovate[bot] Feb 11, 2024
455aa11
chore(deps): update development dependencies (non-major) (#186)
renovate[bot] Feb 11, 2024
9d271a7
build: loosen requirements (#190)
lengau Feb 16, 2024
826a08e
chore(deps): update dependency types/pyright to v1.1.351 (#189)
renovate[bot] Feb 20, 2024
2130cd0
chore(deps): update development dependencies (non-major) (#191)
renovate[bot] Mar 3, 2024
d319ea9
chore: update ruff settings (#192)
mr-cal Mar 5, 2024
c9c4de1
chore(deps): update development dependencies (non-major) (#193)
renovate[bot] Mar 25, 2024
ef54940
chore(deps): update softprops/action-gh-release action to v2 (#194)
renovate[bot] Mar 25, 2024
bf22cfe
chore(deps): update dependency dev/pytest-cov to v5 (#195)
renovate[bot] Mar 28, 2024
5d10b2a
chore(deps): update dependency types/pyright to v1.1.356 (#196)
renovate[bot] Apr 1, 2024
955f445
chore(deps): update dependency types/pyright to v1.1.357 (#198)
renovate[bot] Apr 10, 2024
56b1e71
chore(deps): update dependency types/pyright to v1.1.358 (#202)
renovate[bot] Apr 12, 2024
960f108
chore: merge 'starbase/main'
tigarmo Apr 19, 2024
11bd983
chore: rename star[base,craft] -> craft-grammar
tigarmo Apr 19, 2024
be0681c
chore: migrate to pyproject.toml
tigarmo Apr 19, 2024
57b50fa
chore: run `tox run -m format`
tigarmo Apr 19, 2024
005747d
chore: run `tox run -e format-black`
tigarmo Apr 19, 2024
c322eb6
chore: bump Python version for linting to 3.10
tigarmo Apr 19, 2024
e13088b
chore: move docs reqs to pyproject.toml
tigarmo Apr 19, 2024
b582af8
chore: fix mypy issues
tigarmo Apr 19, 2024
bef8a04
chore: fix many ruff linting issues
tigarmo Apr 19, 2024
97e581d
chore: fix new mypy issues
tigarmo Apr 19, 2024
126c15d
chore: fix new pyright issues
tigarmo Apr 19, 2024
c9f63f9
chore: drop python 3.8 from tox.ini
tigarmo Apr 19, 2024
e5f1caf
ci: don't fail on conventional commits check
tigarmo Apr 19, 2024
158acd4
test: update tests with Python 3.10 baseline
tigarmo Apr 19, 2024
e013c9f
refactor: add a base processor class
tigarmo Apr 19, 2024
8b37a15
docs: drop diataxis 4-box structure for now
tigarmo Apr 19, 2024
46e2a8f
style: better annotate ruff exceptions
tigarmo Apr 26, 2024
b914a3d
chore: minor fixes from starbase integration
tigarmo Apr 26, 2024
a721b62
style: block specific linters in test_create
tigarmo Apr 26, 2024
7b8bf84
chore: remove old Makefile
tigarmo Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions craft_grammar/_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ def __init__(

@overrides
def check(self) -> bool:
for statement in self.statements:
if not statement.check():
return False

return True
return all(statement.check() for statement in self.statements)

def __eq__(self, other: object) -> bool:
if type(other) is type(self):
Expand Down
7 changes: 4 additions & 3 deletions craft_grammar/_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
self._transformer = transformer
else:
# By default, no transformation
self._transformer = lambda s, p, o: p
self._transformer = lambda _s, p, _o: p

def process(
self,
Expand Down Expand Up @@ -165,11 +165,12 @@ def _parse_section_dictionary(
call_stack: CallStack,
) -> tuple[Statement | None, Statement | None]:
finalized_statement: Statement | None = None
for key, value in section.items():
for key, value_ in section.items():
# Grammar is always written as a list of selectors but the value
# can be a list or a string. In the latter case we wrap it so no
# special care needs to be taken when fetching the result from the
# primitive.
value = value_
if not isinstance(value, list):
value = [value]

Expand Down Expand Up @@ -221,7 +222,7 @@ def _parse_section_dictionary(
call_stack=call_stack,
)

# TODO remove support for to without on (this statement)
# to-do: remove support for to without on (this statement)
elif _TO_CLAUSE_PATTERN.match(key):
# We've come across the beginning of a 'to' statement.
# That means any previous statement we found is complete.
Expand Down
12 changes: 2 additions & 10 deletions craft_grammar/_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ def process(self) -> list[str]:
:return: Primitives as determined by evaluating the statement or its
else clauses.
"""
if self.check():
primitives = self._process_body()
else:
primitives = self._process_else()

return primitives
return self._process_body() if self.check() else self._process_else()

def _process_body(self) -> list[str]:
"""Process the main body of this statement.
Expand Down Expand Up @@ -136,10 +131,7 @@ def _validate_primitives(self, primitives: Iterable[str]) -> bool:
:return: Whether or not all primitives are valid.
:rtype: bool
"""
for primitive in primitives:
if not self._processor.checker(primitive):
return False
return True
return all(self._processor.checker(primitive) for primitive in primitives)

def _call_stack(self, *, include_self: bool = False) -> CallStack:
"""Return call stack when processing this statement.
Expand Down
17 changes: 6 additions & 11 deletions craft_grammar/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ def create_grammar_model(model_class: type[BaseModel]) -> str:

attributes.append(attr_decl)

lines = [class_decl] + CONFIG_TEMPLATE.split("\n")
for attr in attributes:
lines.append(f" {attr}")
lines = [class_decl, *CONFIG_TEMPLATE.split("\n")]
lines.extend(f" {attr}" for attr in attributes)
lines.append("") # Final newline

return "\n".join(lines)


def _get_grammar_type_for(model_type: type) -> str | None:
def _get_grammar_type_for(model_type: type) -> str | None: # noqa: PLR0911
"""Get the "grammar" type for ``model_type``.

Returns None if we don't know how to "grammify" ``model_type``.
Expand All @@ -105,7 +104,7 @@ def _get_grammar_type_for(model_type: type) -> str | None:

case typing.Union:
# Type is either a Union[] or an Optional[]
if len(args) == 2 and type(None) in args:
if len(args) == 2 and type(None) in args: # noqa: PLR2004
# Type is an Optional[]
# Optional[T] -> Optional[Grammar[T]]
other_type = [t for t in args if t is not type(None)][0]
Expand All @@ -116,11 +115,7 @@ def _get_grammar_type_for(model_type: type) -> str | None:
union_args = []
for arg in typing.get_args(model_type):
if typing.get_origin(arg) is None:
if arg is type(None):
name = "None"
else:
# print int as "int"
name = arg.__name__
name = "None" if arg is type(None) else arg.__name__
union_args.append(name)
else:
# print dict[k, v] as "dict[k,v]"
Expand All @@ -142,7 +137,7 @@ def _get_grammar_type_for(model_type: type) -> str | None:

case typing.Literal:
# Literal["a", "b"] -> Grammar[str]
arg_types = set(type(a) for a in typing.get_args(model_type))
arg_types = {type(a) for a in typing.get_args(model_type)}
if len(arg_types) == 1:
# For now only handle the case where all possible literal values
# have the same type
Expand Down
6 changes: 3 additions & 3 deletions craft_grammar/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, message: str) -> None:
class OnStatementSyntaxError(GrammarSyntaxError):
"""Error raised on on statement syntax errors."""

def __init__(self, on_statement: str, *, message: str | None = None):
def __init__(self, on_statement: str, *, message: str | None = None) -> None:
components = [f"{on_statement!r} is not a valid 'on' clause"]
if message:
components.append(message)
Expand All @@ -41,7 +41,7 @@ def __init__(self, on_statement: str, *, message: str | None = None):
class ToStatementSyntaxError(GrammarSyntaxError):
"""Error raised on to statement syntax errors."""

def __init__(self, to_statement: str, *, message: str | None = None):
def __init__(self, to_statement: str, *, message: str | None = None) -> None:
components = [f"{to_statement!r} is not a valid 'to' clause"]
if message:
components.append(message)
Expand All @@ -51,5 +51,5 @@ def __init__(self, to_statement: str, *, message: str | None = None):
class UnsatisfiedStatementError(CraftGrammarError):
"""Error raised when a statement cannot be satisfied."""

def __init__(self, statement: str):
def __init__(self, statement: str) -> None:
super().__init__(f"Unable to satisfy {statement!r}, failure forced.")
6 changes: 4 additions & 2 deletions craft_grammar/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

"""Pydantic models for grammar."""

# ruff: noqa: ANN401 (lots of Anys in this module)

import abc
import re
from collections.abc import Callable, Iterator
Expand Down Expand Up @@ -71,7 +73,7 @@ def _format_type_error(type_: type, entry: Any) -> str:
return f"value must be a list: {entry!r}"

if issubclass(origin, dict):
if len(args) == 2:
if len(args) == 2: # noqa: PLR2004
return f"value must be a dict of {args[0].__name__} to {args[1].__name__}: {entry!r}"
return f"value must be a dict: {entry!r}"

Expand Down Expand Up @@ -163,7 +165,7 @@ def _ensure_selector_valid(selector: str, *, clause: str) -> None:
raise ValueError(f"syntax error in {clause!r} selector")


def _is_grammar_clause(item: Any) -> bool: # pylint: disable=too-many-return-statements
def _is_grammar_clause(item: Any) -> bool: # noqa: PLR0911
"""Check if the given item is a valid grammar clause."""
# The 'else fail' clause is a string.
if item == _ELSE_FAIL:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_compound_statement(scenario):

@pytest.mark.parametrize("scenario", error_scenarios)
def test_errors(scenario):
with pytest.raises(scenario["expected_exception"]) as grammar_error:
with pytest.raises(scenario["expected_exception"]) as grammar_error: # noqa: PT012
processor = GrammarProcessor(
arch="amd64",
target_arch="armhf",
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class GrammarValidation(pydantic.BaseModel):
x: Grammar[str]

with pytest.raises(pydantic.ValidationError) as raised:
GrammarValidation(x=value) # type: ignore
GrammarValidation(x=value)

err = raised.value.errors()
assert len(err) == 1
Expand All @@ -346,7 +346,7 @@ class GrammarValidation(pydantic.BaseModel):
x: Grammar[list[str]]

with pytest.raises(pydantic.ValidationError) as raised:
GrammarValidation(x=value) # type: ignore
GrammarValidation(x=value)

err = raised.value.errors()
assert len(err) == 1
Expand All @@ -365,7 +365,7 @@ class GrammarValidation(pydantic.BaseModel):
GrammarValidation(
x=[
{"on arm64,amd64": [{"on arm64": "foo"}, {"else": [35]}]},
], # type: ignore
],
)
err = raised.value.errors()
assert len(err) == 1
Expand All @@ -380,7 +380,7 @@ class GrammarValidation(pydantic.BaseModel):

x: Grammar[str]

GrammarValidation(x=[{"on arch": "foo"}, "else fail"]) # type: ignore
GrammarValidation(x=[{"on arch": "foo"}, "else fail"])


def test_grammar_strlist_elsefail():
Expand All @@ -389,7 +389,7 @@ class GrammarValidation(pydantic.BaseModel):

x: Grammar[list[str]]

GrammarValidation(x=[{"on arch": ["foo"]}, "else fail"]) # type: ignore
GrammarValidation(x=[{"on arch": ["foo"]}, "else fail"])


def test_grammar_try():
Expand All @@ -399,7 +399,7 @@ class GrammarValidation(pydantic.BaseModel):
x: Grammar[str]

with pytest.raises(pydantic.ValidationError) as raised:
GrammarValidation(x=[{"try": "foo"}]) # type: ignore
GrammarValidation(x=[{"try": "foo"}])

err = raised.value.errors()
assert len(err) == 1
Expand All @@ -409,7 +409,7 @@ class GrammarValidation(pydantic.BaseModel):


@pytest.mark.parametrize(
"clause,err_msg",
("clause", "err_msg"),
[
("on", "value must be a str: [{'on': 'foo'}]"),
("on ,", "syntax error in 'on' selector"),
Expand Down Expand Up @@ -442,7 +442,7 @@ class GrammarValidation(pydantic.BaseModel):
x: Grammar[str]

with pytest.raises(pydantic.ValidationError) as raised:
GrammarValidation(x=[{clause: "foo"}]) # type: ignore
GrammarValidation(x=[{clause: "foo"}])

err = raised.value.errors()
assert len(err) == 1
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_on_missing():

@pytest.mark.parametrize("scenario", error_scenarios)
def test_errors(scenario):
with pytest.raises(errors.OnStatementSyntaxError) as syntax_error:
with pytest.raises(errors.OnStatementSyntaxError) as syntax_error: # noqa: PT012
processor = GrammarProcessor(
arch="amd64",
target_arch="amd64",
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,11 @@ def test_basic_grammar(scenario):
def test_grammar_with_transformer(scenario):
# Transform all 'to' statements to include arch
def transformer(call_stack, package_name, target_arch):
if any(isinstance(s, ToStatement) for s in call_stack):
if ":" not in package_name:
package_name = f"{package_name}:{target_arch}"
if (
any(isinstance(s, ToStatement) for s in call_stack)
and ":" not in package_name
):
package_name = f"{package_name}:{target_arch}"

return package_name

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_on_missing():

@pytest.mark.parametrize("scenario", error_scenarios)
def test_errors(scenario):
with pytest.raises(errors.ToStatementSyntaxError) as syntax_error:
with pytest.raises(errors.ToStatementSyntaxError) as syntax_error: # noqa: PT012
processor = GrammarProcessor(
arch="amd64",
target_arch="amd64",
Expand Down