Skip to content

Commit 11196bd

Browse files
committed
First dev version of Jam.
1 parent a61ed7f commit 11196bd

23 files changed

Lines changed: 916 additions & 2 deletions

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1-
# jam
2-
Tool to ease development with rez.
1+
![Jam Logo](logo.png)
2+
3+
## Overview
4+
Tool to ease development with [rez](https://github.com/AcademySoftwareFoundation/rez).
5+
6+
## Install Guide
7+
8+
Jam requires two environment variables to be set to work:
9+
10+
Variable Name | Description
11+
----------------- |:--------------:
12+
`JAM_CONFIG_PATH` | Directory to store Jam configs.
13+
`JAM_BUILD_PATH` | Directory to store installed temp packages.
14+
15+
16+
```bash
17+
python setup.py --install
18+
```
19+
20+
## User Guide
21+
22+
Creating new config.
23+
```bash
24+
jam new <config name>
25+
```
26+
27+
Editing existing config.
28+
```bash
29+
jam edit <config name>
30+
```
31+
32+
Adding packages to config.
33+
```bash
34+
# Adding remote package.
35+
jam edit <config name>
36+
jam add "package-2.0.0"
37+
38+
# Adding local package.
39+
jam add /path/to/package.py
40+
41+
# You don't need to enter edit mode to add a package.
42+
jam add "python-2.7+<4" --config <config name>
43+
```
44+
45+
Running config
46+
```bash
47+
jam edit <config name>
48+
jam run
49+
50+
jam run -c <alias or executable>
51+
52+
# Example
53+
jam run --config maya2020 -c maya
54+
55+
```

bin/jam

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
from jam.cli import _main
3+
_main.run()

jam/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"

jam/cli/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from jam.cli.list import ListArgs
2+
from jam.cli.run import RunArgs
3+
from jam.cli.edit import EditArgs
4+
from jam.cli.add import AddArgs
5+
from jam.cli.edit import EditArgs
6+
from jam.cli.new import NewArgs
7+
from jam.cli.rm import RmArgs
8+
9+
CLI_ARG_OPTIONS = (ListArgs, RunArgs, AddArgs, EditArgs, NewArgs, RmArgs)

jam/cli/_main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Setup command line args."""
2+
import argparse
3+
import sys
4+
5+
from jam import cli
6+
from jam import common
7+
8+
9+
def enough_args():
10+
"""bool: Validate number of arguments."""
11+
return len(sys.argv) > 1
12+
13+
14+
def run() -> None:
15+
"""Run application."""
16+
parser = argparse.ArgumentParser(description="Develop tool for rez.")
17+
sub_parser = parser.add_subparsers(dest="cmd", metavar="COMMAND")
18+
19+
# Setup command line options.
20+
for arg_module in cli.CLI_ARG_OPTIONS:
21+
arg_module.build_args(sub_parser)
22+
23+
args = parser.parse_args()
24+
if not enough_args():
25+
parser.error("To few arguments provided.")
26+
return
27+
28+
if not common.validate_jam_env():
29+
return
30+
31+
for arg_module in cli.CLI_ARG_OPTIONS:
32+
if sys.argv[1] == arg_module.name:
33+
arg_module.execute(args)
34+
return

jam/cli/add.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import logging
2+
import os
3+
4+
from jam import common, config, rez_package
5+
6+
LOG = logging.getLogger(__name__)
7+
8+
9+
class AddArgs:
10+
"""Class to handle `add` flag."""
11+
12+
name = "add"
13+
14+
@staticmethod
15+
def build_args(sub_parser) -> None:
16+
"""Setup arg parser for `add` flag.
17+
18+
Args:
19+
sub_parser (argparse._SubParsersAction): Parser to add arguments to.
20+
21+
"""
22+
parser = sub_parser.add_parser("add", help="Add local or remote package as build dependency")
23+
parser.add_argument("package", help="Package name (optional version) or local directory")
24+
parser.add_argument("--config", default=os.getenv("JAM_ENV"), help="Jam config name.")
25+
26+
@staticmethod
27+
def execute(args) -> None:
28+
"""Execute command option.
29+
30+
Args:
31+
args (argparse.Namespace): Parsed argument flags.
32+
33+
"""
34+
if not args.config:
35+
common.no_config()
36+
return
37+
38+
package = rez_package.get_package_data(args.package)
39+
if not package:
40+
return
41+
42+
config_data = config.get_jam_config(args.config)
43+
config_data.update(package)
44+
45+
config.write_config(args.config, config_data)

jam/cli/edit.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import logging
2+
3+
from jam import config, shell
4+
5+
LOG = logging.getLogger(__name__)
6+
7+
8+
class EditArgs:
9+
"""Class to handle `edit` flag."""
10+
11+
name = "edit"
12+
13+
@staticmethod
14+
def build_args(sub_parser) -> None:
15+
"""Setup arg parser for `edit` flag.
16+
17+
Args:
18+
sub_parser (argparse._SubParsersAction): Parser to add arguments to.
19+
20+
"""
21+
parser = sub_parser.add_parser("edit", help="Edit Jam config")
22+
parser.add_argument("config", help="Package name (optional version) or local directory")
23+
24+
@staticmethod
25+
def execute(args) -> None:
26+
"""Execute command option.
27+
28+
Args:
29+
args (argparse.Namespace): Parsed argument flags.
30+
31+
"""
32+
if not config.config_exists(args.config):
33+
LOG.error(f'Config "{args.config}" does not exists.')
34+
return
35+
36+
shell.create_and_run_shell(args.config)

jam/cli/list.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import logging
2+
import os
3+
4+
from jam import common, config
5+
6+
LOG = logging.getLogger(__name__)
7+
8+
9+
class ListArgs:
10+
"""Class to handle `list` flag."""
11+
12+
name = "list"
13+
14+
@staticmethod
15+
def build_args(sub_parser) -> None:
16+
"""Setup arg parser for `list` flag.
17+
18+
Args:
19+
sub_parser (argparse._SubParsersAction): Parser to add arguments to.
20+
21+
"""
22+
parser = sub_parser.add_parser("list", help="List information from Jam config.")
23+
parser.add_argument("--all", action="store_true", help="List all packages in config.")
24+
parser.add_argument("--config", default=os.getenv("JAM_ENV"), help="Jam config name.")
25+
parser.add_argument("--configs", action="store_true", help="List existing Jam configs.")
26+
parser.add_argument("--package", help="Package name to query information from.")
27+
28+
@staticmethod
29+
def execute(args) -> None:
30+
"""Execute command option.
31+
32+
Args:
33+
args (argparse.Namespace): Parsed argument flags.
34+
35+
"""
36+
if args.configs:
37+
_print_configs()
38+
return
39+
40+
if not args.config:
41+
common.no_config()
42+
return
43+
44+
config_data = config.get_jam_config(args.config)
45+
if args.all:
46+
_print_table_of_content(config_data)
47+
elif args.package:
48+
_print_table_of_content({args.package: config_data.get(args.package, {})})
49+
50+
51+
def _print_configs() -> None:
52+
"""Print Existing jam config names."""
53+
for _conf in os.listdir(common.CONFIG_ROOT):
54+
if _conf.endswith(".jam"):
55+
print(_conf.replace(".jam", ""))
56+
57+
58+
def _print_table_of_content(_config: dict) -> None:
59+
"""Print data as table.
60+
61+
Args:
62+
_config (dict): Jam package or config dict to print as table.
63+
64+
"""
65+
columns = []
66+
length = len(_config) + 1 # Add extra space for header.
67+
68+
for column_key in ("name", "version", "path"):
69+
columns.append([column_key.capitalize()] + [v.get(column_key, "") for v in _config.values()])
70+
71+
splitter = ""
72+
for row in range(length):
73+
row_text = "|"
74+
splitter = "+"
75+
for column in columns:
76+
text_length = len(max(column, key=len))
77+
text = column[row]
78+
row_text += f" {text}" + " " * (text_length - len(text)) + " |"
79+
splitter += "-" * (text_length + 1) + "-+"
80+
81+
print(splitter)
82+
print(row_text)
83+
print(splitter)

jam/cli/new.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import logging
2+
3+
from jam import config, shell
4+
5+
LOG = logging.getLogger(__name__)
6+
7+
8+
class NewArgs:
9+
"""Class to handle `new` flag."""
10+
11+
name = "new"
12+
13+
@staticmethod
14+
def build_args(sub_parser) -> None:
15+
"""Setup arg parser for `new` flag.
16+
17+
Args:
18+
sub_parser (argparse._SubParsersAction): Parser to add arguments to.
19+
20+
"""
21+
parser = sub_parser.add_parser("new", help="New package name.")
22+
parser.add_argument("config", help="New Jam config name to create.")
23+
24+
@staticmethod
25+
def execute(args) -> None:
26+
"""Execute command option.
27+
28+
Args:
29+
args (argparse.Namespace): Parsed argument flags.
30+
31+
"""
32+
if config.config_exists(args.config):
33+
LOG.error(f'Config "{args.config}" already exists.')
34+
return
35+
36+
config.create_new_config(args.config)
37+
shell.create_and_run_shell(args.config)

jam/cli/rm.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
3+
from jam import common, config
4+
5+
6+
class RmArgs:
7+
"""Class to handle `rm` flag."""
8+
9+
name = "rm"
10+
11+
@staticmethod
12+
def build_args(sub_parser) -> None:
13+
"""Setup arg parser for `rm` flag.
14+
15+
Args:
16+
sub_parser (argparse._SubParsersAction): Parser to add arguments to.
17+
18+
"""
19+
parser = sub_parser.add_parser("rm", help="Remove dependency")
20+
parser.add_argument("package", help="Package name to remove as dependency")
21+
parser.add_argument("--config", default=os.getenv("JAM_ENV"), help="Jam config name.")
22+
23+
@staticmethod
24+
def execute(args) -> None:
25+
"""Execute command option.
26+
27+
Args:
28+
args (argparse.Namespace): Parsed argument flags.
29+
30+
"""
31+
if not args.config:
32+
common.no_config()
33+
return
34+
35+
config_data = config.get_jam_config(args.config)
36+
if config_data.get(args.package):
37+
del config_data[args.package]
38+
39+
config.write_config(args.config, config_data)

0 commit comments

Comments
 (0)