Skip to content

Commit

Permalink
Merge pull request #18 from claui/redport
Browse files Browse the repository at this point in the history
Sync with upstream project template
  • Loading branch information
claui authored Oct 6, 2024
2 parents 0d033de + 9e7f74d commit 7511176
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .redport/manifest.rpt.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"upstream": {
"type": "cookiecutter-template",
"source": "https://github.com/claui/cookiecutter-python-package.git",
"commit": "19a56135ea0701203ef263f14d0c95a4de542501",
"commit": "d9f839e34864cbd0c38f9bfd53e9d81aa1c2a2d1",
"replay": "cookiecutter_replay/cookiecutter-python-package.json",
"patches": [
"patches/disable-install-step.patch"
Expand Down
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Itchcraft: Debug list of attached USB bite healers",
"type": "debugpy",
"request": "launch",
"module": "poethepoet",
"args": [
"cli",
"info"
],
"justMyCode": false,
"console": "integratedTerminal"
}
]
}
13 changes: 6 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
"[json][jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features",
// Built-in formatter disrespects insert_final_newline in .editorconfig
"editor.formatOnSave": false
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
Expand All @@ -15,10 +14,11 @@
},
"code-runner.clearPreviousOutput": true,
"code-runner.executorMap": {
"python": "poetry run python",
"python": "poetry run python"
},
"code-runner.ignoreSelection": true,
"code-runner.saveFileBeforeRun": true,
"editor.formatOnSave": true,
"editor.rulers": [
68,
72
Expand All @@ -27,7 +27,6 @@
"**/.git": true,
"**/.mypy_cache": true,
"**/.pytest_cache": true,
"**/.shims": true,
"**/.venv": true,
"**/*.egg-info": true,
"**/__pycache__": true
Expand Down
22 changes: 3 additions & 19 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
}
},
{
"label": "Itchcraft: Run hello",
"label": "Itchcraft: Show list of attached USB bite healers",
"type": "shell",
"command": "poetry",
"args": [
"run",
"poe",
"hello"
"cli",
"info"
],
"problemMatcher": [],
"group": {
Expand All @@ -38,23 +39,6 @@
"showReuseMessage": false
}
},
{
"label": "Itchcraft: Run hello 'Claudia Pellegrino'",
"type": "shell",
"command": "poetry",
"args": [
"run",
"poe",
"hello",
"Claudia Pellegrino"
],
"problemMatcher": [],
"group": "build",
"presentation": {
"clear": true,
"showReuseMessage": false
}
},
{
"label": "Itchcraft: Install/update local dependencies",
"type": "shell",
Expand Down
34 changes: 16 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ at [github.com/pyenv/pyenv](https://github.com/pyenv/pyenv#basic-github-checkout

To verify your `pyenv` is working, run:

```
```shell
pyenv --version
```

### Checking your system-wide Python installation

Make sure you have Python 3.7 or higher installed on your system
Make sure you have Python 3.8 or higher installed on your system
and available in your PATH.

To check, run:

```
```shell
python --version
```

If that fails, try:

```
```shell
python3 --version
```

Expand All @@ -62,7 +62,7 @@ described in Poetry’s documentation.

To verify Poetry is working, run:

```
```shell
poetry --version
```

Expand All @@ -86,43 +86,41 @@ To update your dependencies after a `git pull`, run `poetry update`.

To see a list of available tasks, run: `poetry run poe tasks`

## Running Itchcraft
### Running Itchcraft

To execute Itchcraft, run:

```
```shell
poetry run poe cli
```

## Contributing to Itchcraft

### Running the tests

To execute the tests, run:

```
```shell
poetry run poe tests
```

To execute a single test, run e. g.:

```
```shell
poetry run poe tests -vv tests/test_api.py::test_hello
```

### Running the linter

To execute the linter, run:

```
```shell
poetry run poe linter
```

### Running the static type check

To execute the static type check, run:

```
```shell
poetry run poe typecheck
```

Expand All @@ -131,15 +129,15 @@ poetry run poe typecheck
If you have [act](https://github.com/nektos/act) installed and a
Docker daemon active, run:

```sh
```shell
act
```

### Generating project documentation

To generate project documentation and open it in your browser, run:

```
```shell
poetry run poe doc
```

Expand All @@ -149,7 +147,7 @@ poetry run poe doc

If you get errors after a Git pull, refresh your dependencies:

```
```shell
poetry update
```

Expand All @@ -158,14 +156,14 @@ poetry update
If you’ve run `poetry update` and you still get errors, rebuild
the virtual environment:

```
```shell
poetry install
```

### Checking Itchcraft’s dependencies for compatible updates

To check Itchcraft’s dependencies for compatible updates, run:

```
```shell
poetry update --dry-run
```
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ itchcraft (0.4.1) UNRELEASED; urgency=medium
* Add typing stubs for pyusb
* Fix regression for drivers with no detach support

-- Claudia Pellegrino <deb@cpellegrino.de> Wed, 4 Sep 2024 20:14:16 +0200
-- Claudia Pellegrino <clau@tiqua.de> Sun, 06 Oct 2024 23:28:22 +0200
37 changes: 22 additions & 15 deletions itchcraft/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Entry point for the command line interface."""

from collections.abc import Generator
from contextlib import contextmanager
import os
import sys
from typing import NoReturn
Expand All @@ -15,31 +17,36 @@
logger = get_logger(__name__)


def _version_text() -> str:
if __version__ is None:
return 'Itchcraft (unknown version)'
if os.path.exists(PYPROJECT_TOML):
return (
f'Itchcraft v{__version__}'
+ f' (in development at {PROJECT_ROOT})'
)
return f'Itchcraft v{__version__}'


def run(*args: str) -> NoReturn:
# pylint: disable=magic-value-comparison
def run(*args: str) -> None:
"""Runs the command line interface."""
with _cli_context(*args) as combined_args:
fire.Fire(api.Api, command=combined_args)


if sys.argv[1:] and sys.argv[1:][0] in {'-V', '--version'}:
@contextmanager
def _cli_context(*args: str) -> Generator[list[str], None, NoReturn]:
combined_args = list(args) + sys.argv[1:]
if combined_args and combined_args[0] in {'-V', '--version'}:
print(_version_text())
sys.exit(0)

fire_workarounds.apply()
try:
fire.Fire(api.Api, command=list(args) + sys.argv[1:])
yield combined_args
except CliError as e:
if debugMode:
raise e
logger.error(e)
sys.exit(1)
sys.exit(0)


def _version_text() -> str:
if __version__ is None:
return 'Itchcraft (unknown version)'
if os.path.exists(PYPROJECT_TOML):
return (
f'Itchcraft v{__version__}'
+ f' (in development at {PROJECT_ROOT})'
)
return f'Itchcraft v{__version__}'

0 comments on commit 7511176

Please sign in to comment.