-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a61ed7f
commit 11196bd
Showing
23 changed files
with
916 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,55 @@ | ||
# jam | ||
Tool to ease development with rez. | ||
![Jam Logo](logo.png) | ||
|
||
## Overview | ||
Tool to ease development with [rez](https://github.com/AcademySoftwareFoundation/rez). | ||
|
||
## Install Guide | ||
|
||
Jam requires two environment variables to be set to work: | ||
|
||
Variable Name | Description | ||
----------------- |:--------------: | ||
`JAM_CONFIG_PATH` | Directory to store Jam configs. | ||
`JAM_BUILD_PATH` | Directory to store installed temp packages. | ||
|
||
|
||
```bash | ||
python setup.py --install | ||
``` | ||
|
||
## User Guide | ||
|
||
Creating new config. | ||
```bash | ||
jam new <config name> | ||
``` | ||
|
||
Editing existing config. | ||
```bash | ||
jam edit <config name> | ||
``` | ||
|
||
Adding packages to config. | ||
```bash | ||
# Adding remote package. | ||
jam edit <config name> | ||
jam add "package-2.0.0" | ||
|
||
# Adding local package. | ||
jam add /path/to/package.py | ||
|
||
# You don't need to enter edit mode to add a package. | ||
jam add "python-2.7+<4" --config <config name> | ||
``` | ||
|
||
Running config | ||
```bash | ||
jam edit <config name> | ||
jam run | ||
|
||
jam run -c <alias or executable> | ||
|
||
# Example | ||
jam run --config maya2020 -c maya | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env python | ||
from jam.cli import _main | ||
_main.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from jam.cli.list import ListArgs | ||
from jam.cli.run import RunArgs | ||
from jam.cli.edit import EditArgs | ||
from jam.cli.add import AddArgs | ||
from jam.cli.edit import EditArgs | ||
from jam.cli.new import NewArgs | ||
from jam.cli.rm import RmArgs | ||
|
||
CLI_ARG_OPTIONS = (ListArgs, RunArgs, AddArgs, EditArgs, NewArgs, RmArgs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Setup command line args.""" | ||
import argparse | ||
import sys | ||
|
||
from jam import cli | ||
from jam import common | ||
|
||
|
||
def enough_args(): | ||
"""bool: Validate number of arguments.""" | ||
return len(sys.argv) > 1 | ||
|
||
|
||
def run() -> None: | ||
"""Run application.""" | ||
parser = argparse.ArgumentParser(description="Develop tool for rez.") | ||
sub_parser = parser.add_subparsers(dest="cmd", metavar="COMMAND") | ||
|
||
# Setup command line options. | ||
for arg_module in cli.CLI_ARG_OPTIONS: | ||
arg_module.build_args(sub_parser) | ||
|
||
args = parser.parse_args() | ||
if not enough_args(): | ||
parser.error("To few arguments provided.") | ||
return | ||
|
||
if not common.validate_jam_env(): | ||
return | ||
|
||
for arg_module in cli.CLI_ARG_OPTIONS: | ||
if sys.argv[1] == arg_module.name: | ||
arg_module.execute(args) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
import os | ||
|
||
from jam import common, config, rez_package | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class AddArgs: | ||
"""Class to handle `add` flag.""" | ||
|
||
name = "add" | ||
|
||
@staticmethod | ||
def build_args(sub_parser) -> None: | ||
"""Setup arg parser for `add` flag. | ||
Args: | ||
sub_parser (argparse._SubParsersAction): Parser to add arguments to. | ||
""" | ||
parser = sub_parser.add_parser("add", help="Add local or remote package as build dependency") | ||
parser.add_argument("package", help="Package name (optional version) or local directory") | ||
parser.add_argument("--config", default=os.getenv("JAM_ENV"), help="Jam config name.") | ||
|
||
@staticmethod | ||
def execute(args) -> None: | ||
"""Execute command option. | ||
Args: | ||
args (argparse.Namespace): Parsed argument flags. | ||
""" | ||
if not args.config: | ||
common.no_config() | ||
return | ||
|
||
package = rez_package.get_package_data(args.package) | ||
if not package: | ||
return | ||
|
||
config_data = config.get_jam_config(args.config) | ||
config_data.update(package) | ||
|
||
config.write_config(args.config, config_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
|
||
from jam import config, shell | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class EditArgs: | ||
"""Class to handle `edit` flag.""" | ||
|
||
name = "edit" | ||
|
||
@staticmethod | ||
def build_args(sub_parser) -> None: | ||
"""Setup arg parser for `edit` flag. | ||
Args: | ||
sub_parser (argparse._SubParsersAction): Parser to add arguments to. | ||
""" | ||
parser = sub_parser.add_parser("edit", help="Edit Jam config") | ||
parser.add_argument("config", help="Package name (optional version) or local directory") | ||
|
||
@staticmethod | ||
def execute(args) -> None: | ||
"""Execute command option. | ||
Args: | ||
args (argparse.Namespace): Parsed argument flags. | ||
""" | ||
if not config.config_exists(args.config): | ||
LOG.error(f'Config "{args.config}" does not exists.') | ||
return | ||
|
||
shell.create_and_run_shell(args.config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import logging | ||
import os | ||
|
||
from jam import common, config | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class ListArgs: | ||
"""Class to handle `list` flag.""" | ||
|
||
name = "list" | ||
|
||
@staticmethod | ||
def build_args(sub_parser) -> None: | ||
"""Setup arg parser for `list` flag. | ||
Args: | ||
sub_parser (argparse._SubParsersAction): Parser to add arguments to. | ||
""" | ||
parser = sub_parser.add_parser("list", help="List information from Jam config.") | ||
parser.add_argument("--all", action="store_true", help="List all packages in config.") | ||
parser.add_argument("--config", default=os.getenv("JAM_ENV"), help="Jam config name.") | ||
parser.add_argument("--configs", action="store_true", help="List existing Jam configs.") | ||
parser.add_argument("--package", help="Package name to query information from.") | ||
|
||
@staticmethod | ||
def execute(args) -> None: | ||
"""Execute command option. | ||
Args: | ||
args (argparse.Namespace): Parsed argument flags. | ||
""" | ||
if args.configs: | ||
_print_configs() | ||
return | ||
|
||
if not args.config: | ||
common.no_config() | ||
return | ||
|
||
config_data = config.get_jam_config(args.config) | ||
if args.all: | ||
_print_table_of_content(config_data) | ||
elif args.package: | ||
_print_table_of_content({args.package: config_data.get(args.package, {})}) | ||
|
||
|
||
def _print_configs() -> None: | ||
"""Print Existing jam config names.""" | ||
for _conf in os.listdir(common.CONFIG_ROOT): | ||
if _conf.endswith(".jam"): | ||
print(_conf.replace(".jam", "")) | ||
|
||
|
||
def _print_table_of_content(_config: dict) -> None: | ||
"""Print data as table. | ||
Args: | ||
_config (dict): Jam package or config dict to print as table. | ||
""" | ||
columns = [] | ||
length = len(_config) + 1 # Add extra space for header. | ||
|
||
for column_key in ("name", "version", "path"): | ||
columns.append([column_key.capitalize()] + [v.get(column_key, "") for v in _config.values()]) | ||
|
||
splitter = "" | ||
for row in range(length): | ||
row_text = "|" | ||
splitter = "+" | ||
for column in columns: | ||
text_length = len(max(column, key=len)) | ||
text = column[row] | ||
row_text += f" {text}" + " " * (text_length - len(text)) + " |" | ||
splitter += "-" * (text_length + 1) + "-+" | ||
|
||
print(splitter) | ||
print(row_text) | ||
print(splitter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
from jam import config, shell | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class NewArgs: | ||
"""Class to handle `new` flag.""" | ||
|
||
name = "new" | ||
|
||
@staticmethod | ||
def build_args(sub_parser) -> None: | ||
"""Setup arg parser for `new` flag. | ||
Args: | ||
sub_parser (argparse._SubParsersAction): Parser to add arguments to. | ||
""" | ||
parser = sub_parser.add_parser("new", help="New package name.") | ||
parser.add_argument("config", help="New Jam config name to create.") | ||
|
||
@staticmethod | ||
def execute(args) -> None: | ||
"""Execute command option. | ||
Args: | ||
args (argparse.Namespace): Parsed argument flags. | ||
""" | ||
if config.config_exists(args.config): | ||
LOG.error(f'Config "{args.config}" already exists.') | ||
return | ||
|
||
config.create_new_config(args.config) | ||
shell.create_and_run_shell(args.config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
|
||
from jam import common, config | ||
|
||
|
||
class RmArgs: | ||
"""Class to handle `rm` flag.""" | ||
|
||
name = "rm" | ||
|
||
@staticmethod | ||
def build_args(sub_parser) -> None: | ||
"""Setup arg parser for `rm` flag. | ||
Args: | ||
sub_parser (argparse._SubParsersAction): Parser to add arguments to. | ||
""" | ||
parser = sub_parser.add_parser("rm", help="Remove dependency") | ||
parser.add_argument("package", help="Package name to remove as dependency") | ||
parser.add_argument("--config", default=os.getenv("JAM_ENV"), help="Jam config name.") | ||
|
||
@staticmethod | ||
def execute(args) -> None: | ||
"""Execute command option. | ||
Args: | ||
args (argparse.Namespace): Parsed argument flags. | ||
""" | ||
if not args.config: | ||
common.no_config() | ||
return | ||
|
||
config_data = config.get_jam_config(args.config) | ||
if config_data.get(args.package): | ||
del config_data[args.package] | ||
|
||
config.write_config(args.config, config_data) |
Oops, something went wrong.