Skip to content

Commit

Permalink
ruff: address TRY and T201 (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Apr 29, 2023
1 parent 4382c1b commit ce693b1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 13 deletions.
19 changes: 19 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"recommendations": [
"Tyriar.sort-lines",
"charliermarsh.ruff",
"esbenp.prettier-vscode",
"hbenl.vscode-test-explorer",
"ms-python.isort",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.live-server",
"redhat.ansible",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"shardulm94.trailing-spaces",
"tamasfe.even-better-toml",
"timonwong.shellcheck",
"znck.grammarly"
]
}
41 changes: 41 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
}
},
"editor.formatOnSave": true,
"evenBetterToml.formatter.alignComments": false,
"evenBetterToml.formatter.allowedBlankLines": 2,
"files.exclude": {
"*.egg-info": true,
".pytest_cache": true,
".tox": true,
"__pycache__": true,
"build": true
},
"git.ignoreLimitWarning": true,
"grammarly.domain": "technical",
"grammarly.files.include": ["**/*.txt", "**/*.md"],
"grammarly.hideUnavailablePremiumAlerts": true,
"grammarly.showExamples": true,
"python.analysis.exclude": ["build"],
"python.formatting.provider": "black",
"python.linting.flake8Args": ["--ignore=E501,W503"],
"python.linting.flake8Enabled": false,
"python.linting.mypyCategorySeverity.error": "Warning",
"python.linting.mypyEnabled": true,
"python.linting.pylintEnabled": true,
"python.terminal.activateEnvironment": true,
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"sortLines.filterBlankLines": true,
"yaml.completion": true,
"yaml.customTags": ["!encrypted/pkcs1-oaep scalar", "!vault scalar"],
"yaml.format.enable": false,
"yaml.validate": true
}
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ ignore = [
"S506", # Probable use of unsafe loader `FullLoader`
"SIM108",
"SLF001",
"T201",
"TRY",
]
target-version = "py39"

Expand Down
7 changes: 0 additions & 7 deletions src/ansible_compat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,6 @@ def __deepcopy__(self, memo: object) -> "AnsibleConfig":
"""Allow users to run deeepcopy on Config."""
return AnsibleConfig(data=self.data)

def _dump_config_attrs(self) -> None: # pragma: no cover
"""Dump config attributes using pytest typed format."""
for item in sorted(self.data):
name = item.lower()
kind = self.data[item].__class__.__name__
print(f"{name}: {kind}")


__all__ = [
"ansible_collections_path",
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_compat/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def validate(
try:
if not isinstance(schema, Mapping):
msg = "Invalid schema, must be a mapping"
raise jsonschema.SchemaError(msg)
raise jsonschema.SchemaError(msg) # noqa: TRY301
validator = validator_for(schema)
validator.check_schema(schema)
except jsonschema.SchemaError as exc:
Expand Down
2 changes: 1 addition & 1 deletion test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_config() -> None:
assert config.data["ACTION_WARNINGS"] == config.ACTION_WARNINGS

with pytest.raises(AttributeError):
print(config.THIS_DOES_NOT_EXIST)
_ = config.THIS_DOES_NOT_EXIST


def test_config_with_dump() -> None:
Expand Down
4 changes: 2 additions & 2 deletions test/test_runtime_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def test_runtime_example() -> None:
runtime = Runtime(isolated=True, max_retries=3)

# Print Ansible core version
print(runtime.version) # 2.9.10 (Version object)
_ = runtime.version # 2.9.10 (Version object)
# Get configuration info from runtime
print(runtime.config.collections_path)
_ = runtime.config.collections_path

# Detect if current project is a collection and install its requirements
runtime.prepare_environment(install_local=True) # will retry 3 times if needed
Expand Down

0 comments on commit ce693b1

Please sign in to comment.