Skip to content

Commit

Permalink
Add subcommand to install GNAT Studio plugin
Browse files Browse the repository at this point in the history
Closes #795
  • Loading branch information
senier committed Sep 1, 2022
1 parent 5d120ac commit 0d80d6d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

CLI:

- `rflx setup_ide` subcommand for installing IDE integration (#795)

## [0.6.0] - 2022-08-31

### Added
Expand Down
1 change: 1 addition & 0 deletions doc/development_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Make targets for common development tasks are:
- ``upgrade_devel`` Upgrade all development dependencies (note: ``install_devel`` must be executed before changes in ``setup.py`` take effect)
- ``doc`` Generate HTML documentation
- ``dist`` Create Python package
- ``setup_ide`` Install files required for RecordFlux IDE integration

Additional tools can be found in ``tools/``.

Expand Down
Empty file added ide/__init__.py
Empty file.
17 changes: 16 additions & 1 deletion rflx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import json
import logging
import os
import shutil
import traceback
from multiprocessing import cpu_count
from pathlib import Path
from typing import Dict, List, Optional, Sequence, Tuple, Union

import librflxlang
from pkg_resources import get_distribution
from pkg_resources import get_distribution, resource_filename

from rflx import __version__
from rflx.error import ERROR_CONFIG, FatalError, RecordFluxError, Severity, Subsystem, fail
Expand Down Expand Up @@ -190,6 +191,11 @@ def main(argv: List[str]) -> Union[int, str]: # pylint: disable = too-many-stat
)
parser_validate.set_defaults(func=validate)

parser_setup = subparsers.add_parser(
"setup_ide", help="set up RecordFlux IDE integration (GNAT Studio)"
)
parser_setup.set_defaults(func=setup)

args = parser.parse_args(argv[1:])

if args.version:
Expand Down Expand Up @@ -383,3 +389,12 @@ def validate(args: argparse.Namespace) -> None:
fatal_error = FatalError()
fatal_error.extend(e)
raise fatal_error from e


def setup(_args: argparse.Namespace) -> None:
gnatstudio_dir = resource_filename("ide", "gnatstudio/")
plugins_dir = Path.home() / ".gnatstudio/plug-ins"
if not plugins_dir.exists():
plugins_dir.mkdir(parents=True, exist_ok=True)
print(f'Installing RecordFlux plugin into "{plugins_dir}"')
shutil.copy(Path(gnatstudio_dir) / "recordflux.py", plugins_dir)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"Topic :: System :: Networking",
],
packages=find_packages(include=("rflx", "rflx.*")),
package_data={"rflx": ["py.typed", "templates/*"]},
package_data={"rflx": ["py.typed", "templates/*"], "ide": ["gnatstudio/*"]},
python_requires=">=3.8",
install_requires=[
"attrs >=20, <22",
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,17 @@ def test_fail_fast() -> None:
)
== 10
)


def test_setup_gnat_studio_plugin() -> None:
cli.main(["rflx", "setup_ide"])
plugin = Path.home() / ".gnatstudio/plug-ins/recordflux.py"
assert plugin.exists()
assert plugin.is_file()

# Install with plugin dir already present
plugin.unlink()
cli.main(["rflx", "setup_ide"])
plugin = Path.home() / ".gnatstudio/plug-ins/recordflux.py"
assert plugin.exists()
assert plugin.is_file()

0 comments on commit 0d80d6d

Please sign in to comment.