Skip to content

Commit 61eb5d0

Browse files
committed
README.md file updated, test bug fixed
1 parent 2ba92a3 commit 61eb5d0

File tree

5 files changed

+77
-104
lines changed

5 files changed

+77
-104
lines changed

README.md

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,77 @@
55
**CodeMage** is a tool that translates a source file written in one programming language into another language.
66
The translation will be done by Large Language Model AI(such as ChatGPT)
77

8-
## Release 1.0.0
98

10-
### Features
9+
10+
## Features (Release 1.1.2)
1111

1212
1. Supported Languages: Javascript, Python, C++, Java
1313
2. Default target Language is Python
1414
3. Supported LLM model: openrouter, groq
1515
4. Default LLM model is openrouter(sao10k/l3-euryale-70b)
1616

17-
# Getting Started with `PyPI`
17+
18+
19+
<br>
20+
<br>
21+
22+
# Getting started
23+
24+
### Prerequisite
25+
26+
27+
1. Python
28+
- You need python 3.12 or later version to use this tool
29+
- Install Python : https://www.python.org/downloads/
30+
31+
32+
33+
<br>
34+
<br>
35+
36+
## Start with `PyPI`
1837

1938
### 1. Download the package using PyPI
2039
```bash
40+
# for window user
2141
pip install code-mage
42+
43+
# for mac user
44+
pip3 install code-mage
2245
```
2346

47+
<br>
48+
2449
### 2. Create your API_KEY at [openrouter](https://openrouter.ai/docs/api-keys) Or [Groq](https://console.groq.com/keys)
2550

2651
It's free with sign-up. You can easily sign-up with your google account
2752

53+
<br>
54+
2855
### 3.a Set-up the API_KEY using `Variable` (option 1)
2956

3057
```bash
31-
export API_KEY=YOUR-API-KEY
58+
export GROQ_API_KEY=YOUR-API-KEY # if you use groq model
59+
export OPENROUTER_API_KEY=YOUR-API-KEY # if you use openrouter model
3260
```
3361

62+
<br>
63+
3464
### 3.b Set-up with `.toml` file (option 2)
3565

36-
With this option, you can also set other tool options.
66+
With this option, you can also set other tool options more easily
3767

3868
- Start by creating a `.codemage-config.toml` in your home directory.
3969

4070
```bash
41-
mkdir ~/.codemage-config.toml
71+
vi ~/.codemage-config.toml
4272
```
4373

44-
- Add the following information to the file:
74+
- Add the following environment settings in the file:
4575

4676
```toml
77+
# the double quotes for string values are necessary.
78+
4779
model="groq" # if you wish to use OPEN ROUTER you can just delete this line
4880
GROQ_API_KEY="<YOUR-GROQ-API-KEY>"
4981
OPENROUTER_API_KEY="<YOUR-OPEN-ROUTER-API-KEY>"
@@ -53,37 +85,42 @@ token_usage=false # if you wish to get token_usage info, set it `true`
5385
output="result" # type any name for the output file without the extension
5486
```
5587

88+
<br>
89+
5690
### 4. Run the tool
5791

5892
```bash
5993
codemage <file-you-want-to-convert>
94+
6095
# For example,
6196
codemage test.js
97+
codemage test.js -s
98+
codemage test.js -m openrouter # specify your model, or the default model is "groq"
6299
```
63100

64-
# Getting Started by cloning the github repo
101+
<br>
65102

66-
### 1. Install Python : https://www.python.org/downloads/
103+
# Start by cloning the github repo
67104

68-
<br>
105+
If you are using the tool by cloning the repo, you need poetry package manager.
69106

70-
### 2. Install Poetry
107+
### 1. Install Poetry (if not installed yet)
71108

72109
```console
73110
curl -sSL https://install.python-poetry.org | python3 -
74111
```
75112

76113
**OR** if you have `pipx` installed on your local machine, you can use the following commend
77114

78-
[How to download `pipx`](https://github.com/pypa/pipx)
79-
80115
```console
81116
pipx install poetry
82117
```
83118

119+
Refer to [How to download pipx](https://github.com/pypa/pipx)
120+
84121
<br>
85122

86-
### 3. Clone the repository
123+
### 2. Clone the repository
87124

88125
```console
89126
git clone https://github.com/gitdevjin/code-mage.git
@@ -92,35 +129,44 @@ cd code_mage
92129

93130
<br>
94131

95-
### 4. Install Poetry Package
132+
### 3. Install Poetry Dependencies
96133

97134
```console
98135
poetry install
99136
```
100137

101138
<br>
102139

103-
### 5. Create your API_KEY at [openrouter](https://openrouter.ai/docs/api-keys) Or [Groq](https://console.groq.com/keys)
140+
### 4. Create your API_KEY at [openrouter](https://openrouter.ai/docs/api-keys) Or [Groq](https://console.groq.com/keys)
104141

105142
It's free with sign-up. You can easily sign-up with your google account
106143

107144
<br>
108145

109-
### 6. Create `.env` file in the root directory and save the following:
146+
### 5-a Create `.env` file in the root directory and save the following:
110147

111148
```
112149
OPENROUTER_API_KEY=your_open_router_api_key
113150
GROQ_API_KEY=your_groq_api_key
114151
```
152+
<br>
153+
154+
### 5-b Using TOML files
155+
156+
You can also use `.toml` file with this method
157+
Refer to [this](#3b-set-up-with-toml-file-option-2)
115158

116159
Now you are ready to use the tool!
117160

118161
<br>
119162

120163
# Usage
121164

165+
- Run the command
166+
122167
```console
123168
poetry run codemage <source_file>
169+
poetry run codemage ./example/test.js
124170
```
125171

126172
## Examples
@@ -155,34 +201,6 @@ You can stream out the result onto `stdout` with `-s, --stream` flag:
155201
poetry run codemage ./example/test.js -s
156202
```
157203

158-
### Using TOML files
159-
160-
If you wish, you can specify all of your options in a TOML formatted configuration.
161-
162-
- Start by creating a `.codemage-config.toml` in your home directory.
163-
164-
```bash
165-
mkdir ~/.codemage-config.toml
166-
```
167-
168-
- Add the following information to the file:
169-
170-
```toml
171-
model="groq" # if you wish to use OPEN ROUTER you can just delete this line
172-
GROQ_API_KEY="<YOUR-GROQ-API-KEY>"
173-
OPENROUTER_API_KEY="<YOUR-OPEN-ROUTER-API-KEY>"
174-
language="java" # you can use any of the supported languages
175-
stream=false/true
176-
token_usage=false/true
177-
output="result" # type any name for the output file without the extension
178-
```
179-
180-
- Run the command
181-
182-
```
183-
poetry run codemage ./example/test.js
184-
```
185-
186204
## Options
187205

188206
-h, --help : display help message and exit

code_mage/argsParser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def arg_parser(config):
5-
VERSION = config.get("version")
5+
VERSION = "1.1.2"
66

77
parser = argparse.ArgumentParser(
88
description="This Tool translates a source file into another programming language."

code_mage/loadConfig.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,4 @@ def load_config():
1010
else:
1111
config = {}
1212

13-
config["version"] = __get_version_from_pyproject()
14-
1513
return config
16-
17-
18-
def __get_version_from_pyproject():
19-
with open("pyproject.toml", "r") as f:
20-
pyproject_data = toml.load(f)
21-
return pyproject_data["tool"]["poetry"]["version"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "code-mage"
3-
version = "1.0.0"
3+
version = "1.1.2"
44
description = ""
55
authors = ["gitdevjin <[email protected]>"]
66
readme = "README.md"

tests/test_loadConfig.py

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,37 @@
11
import os
2-
from unittest.mock import patch, mock_open
2+
from unittest.mock import patch
33
from code_mage.loadConfig import load_config # Adjust the import path accordingly
44

55

66
class TestLoadConfig:
77
@patch("os.path.exists")
88
@patch("toml.load")
9-
@patch("builtins.open", new_callable=mock_open)
10-
def test_load_config_file_exists(self, mock_file, mock_toml_load, mock_os_exists):
11-
# Simulate that the config file exists
9+
def test_load_config_file_exists(self, mock_toml_load, mock_os_exists):
10+
# Simulate that the file exists
1211
mock_os_exists.return_value = True
1312

14-
# Simulate the contents of the config file
15-
mock_toml_load.side_effect = [
16-
{
17-
"language": "Python",
18-
"OPENROUTER_API_KEY": "mock_openrouter_api_key",
19-
}, # First call (config file)
20-
{"tool": {"poetry": {"version": "0.9.0"}}}, # Second call (pyproject.toml)
21-
]
22-
23-
# Call load_config function
24-
config = load_config()
25-
26-
# Assertions
27-
mock_os_exists.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
28-
mock_file.assert_called_once_with("pyproject.toml", "r")
29-
assert config == {
13+
# Simulate the contents of the file
14+
mock_toml_load.return_value = {
3015
"language": "Python",
3116
"OPENROUTER_API_KEY": "mock_openrouter_api_key",
32-
"version": "0.9.0",
3317
}
3418

35-
@patch("os.path.exists")
36-
@patch("toml.load")
37-
@patch("builtins.open", new_callable=mock_open)
38-
def test_load_config_file_with_no_content(self, mock_file, mock_toml_load, mock_os_exists):
39-
# Simulate that the file does not exist
40-
mock_os_exists.return_value = True
41-
42-
# Call the function under test
43-
44-
mock_toml_load.side_effect = [
45-
{},
46-
{"tool": {"poetry": {"version": "0.9.0"}}}, # Second call (pyproject.toml)
47-
]
48-
19+
# Call load_config function
4920
config = load_config()
5021

5122
# Assertions
5223
mock_os_exists.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
53-
mock_file.assert_called_once_with("pyproject.toml", "r")
24+
mock_toml_load.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
25+
assert config == {"language": "Python", "OPENROUTER_API_KEY": "mock_openrouter_api_key"}
5426

55-
# Assert the default config with version added
56-
assert config == {"version": "0.9.0"}
57-
58-
@patch("os.path.exists") # Third argument
59-
@patch("builtins.open") # Second argument
60-
@patch("toml.load") # First argument
61-
def test_load_config_file_not_exists(self, mock_toml_load, mock_file, mock_os_exists):
62-
# Simulate that the config file does not exist
27+
@patch("os.path.exists")
28+
def test_load_config_file_not_exists(self, mock_os_exists):
29+
# Simulate that the file does not exist
6330
mock_os_exists.return_value = False
6431

65-
# Simulate the content of the pyproject.toml file
66-
mock_toml_load.return_value = {"tool": {"poetry": {"version": "0.9.0"}}}
67-
6832
# Call the function under test
6933
config = load_config()
7034

7135
# Assertions
7236
mock_os_exists.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
73-
mock_file.assert_called_once_with("pyproject.toml", "r")
74-
assert config == {"version": "0.9.0"}
37+
assert config == {}

0 commit comments

Comments
 (0)