Skip to content

Commit

Permalink
Merge pull request #12 from HushmKun/development
Browse files Browse the repository at this point in the history
v0.3.1
  • Loading branch information
HushmKun authored Apr 14, 2024
2 parents 4ff13d4 + 34841ad commit 779f245
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 193 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,3 @@ venv/
# vscodium
*vscode/

# JetBrains
.idea/
14 changes: 14 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Unused normalize.css file
- Identical links assigned in each translation file -->

## [0.3.1] - 2024-04-14

### Added
- Easier way to add templates.
- New templates : Data Science

### Fixed
- Error on listing templates.

### Changed
- Refactoring to introduce the TUI (interactive mode)


## [0.3.0] - 2023-08-05

### Added
Expand Down Expand Up @@ -71,6 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved error reporting

### Fixed

- Fixed Issue [#8](https://github.com/HushmKun/Artec/issues/8)
- Fixed error building structure if the source starts with a file.

Expand Down
163 changes: 20 additions & 143 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ Create a JSON file to match the folder structure you desire
$ vim structure.json
# Paste the below into your file and modify as you desire
[
{"folder": "{}"}, # Use '{}' to be replaced with project name.
{"file": "{}/__init__.py"},
{"folder": "test"},
{"file": "test/__init__.py"},
{"file": "README.md"},
{"file": "LICENSE"},
{"file": "setup.py"},
{"file": "setup.cfg"},
{"file": "pyproject.toml"},
]
{
"folders": [
"{}",
"test"
],
"files": [
"{}/__init__.py",
"test/__init__.py",
"README.md",
"LICENSE",
"setup.py",
"pyproject.toml"
]
}
```
How to execute
```
Expand Down Expand Up @@ -64,141 +68,14 @@ Examples:
```

## Templates
<details>
<summary> Python </summary>

Project Named Artec
```
artec
├── artec
│ └── __main__.py
├── test
│ └── __init__.py
├── LICENSE
├── pyproject.toml
├── README.md
├── setup.cfg
└── setup.py
2 directories, 7 files
```
</details>

<details>
<summary> Flask </summary>

Project Named flaskr
```
flaskr
.
├── flaskr
│ ├── auth.py
│ ├── blog
│ │ ├── create.html
│ │ ├── index.html
│ │ └── update.html
│ ├── blog.py
│ ├── db.py
│ ├── __init__.py
│ ├── schema.py
│ ├── static
│ │ └── style.css
│ └── templates
│ ├── auth
│ │ ├── login.html
│ │ └── register.html
│ └── base.html
├── LICENSE
├── pyproject.toml
├── README.md
├── setup.py
└── test
├── conftest.py
├── data.sql
├── __init__.py
├── test_auth.py
├── test_blog.py
└── test_db.py
7 directories, 22 files
```
</details>
<details>
<summary> Node.Js </summary>

Project Named Node
```
Node
├── LICENSE
├── package.json
├── package-lock.json
├── README.md
└── src
├── api
│ ├── controllers
│ │ └── user
│ │ ├── auth
│ │ │ ├── forgot-password.js
│ │ │ ├── login.js
│ │ │ ├── logout.js
│ │ │ ├── refresh-token.js
│ │ │ ├── register.js
│ │ │ ├── send-verification-code.js
│ │ │ └── verify-email.js
│ │ ├── delete-user.js
│ │ ├── edit
│ │ │ ├── change-password.js
│ │ │ └── edit-user.js
│ │ ├── get-user.js
│ │ └── index.js
│ ├── middlewares
│ │ ├── auth
│ │ │ ├── check-auth.js
│ │ │ └── check-authority.js
│ │ ├── image-upload.js
│ │ ├── index.js
│ │ ├── object-id-control.js
│ │ └── rate-limiter.js
│ ├── routes
│ │ ├── index.js
│ │ └── user.js
│ └── validators
│ ├── index.js
│ └── user.validator.js
├── app.js
├── config
│ └── index.js
├── loaders
│ ├── express.js
│ ├── index.js
│ └── mongoose.js
├── models
│ ├── index.js
│ ├── log.js
│ ├── token.js
│ └── user.js
└── utils
├── helpers
│ ├── error-helper.js
│ ├── generate-random-code.js
│ ├── ip-helper.js
│ ├── jwt-token-helper.js
│ └── local-text-helper.js
├── index.js
├── lang
│ ├── en.json
│ ├── get-text.json
│ └── tr.json
├── logger.js
└── send-code-to-email.js
17 directories, 46 files
```
</details>
- Python
- Flask
- Node.Js
- Data_Science

## Version

0.3.0
0.3.1

## Contributing
Please refer to [Here](CONTRIBUTING.md) for contributing.
Expand Down
5 changes: 3 additions & 2 deletions artec/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from . import argparser as parser
from . import boiler
from . import logging, console_handler
from .temp import *

__app_name__ = "Artec"
__version__ = "0.3.0"
__version__ = "0.3.1"
__desc__ = "Creates a configurable python project \
template in a given directory."

Expand All @@ -19,7 +20,6 @@ def main():
args = parser.main_args(__version__)

console_handler.setLevel(ERROR_LOGING[args.verbose])

builder = boiler.boiler_builder(
args.source, args.target, args.template, args.git
)
Expand All @@ -29,3 +29,4 @@ def main():

if __name__ == "__main__":
main()

28 changes: 21 additions & 7 deletions artec/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
RawTextHelpFormatter,
_VersionAction,
)
from .templates import templates
from .temp import *
import sys


class list_templates(_VersionAction):
def __call__(self, parser: ArgumentParser, *args, **kwargs) -> None:
formatter = parser._get_formatter()
formatter.add_text(
"".join(
"Available templates\n\n",
"\n".join([f"> {key.title()}\t" for key in templates.keys()]),
)
list_available_templates()
)
parser._print_message(formatter.format_help(), sys.stdout)
parser.exit()
Expand All @@ -43,6 +40,7 @@ def __init__(self, appVersion):

def setup(self):
group = self.add_mutually_exclusive_group()

group.add_argument(
"-s",
"--source-file",
Expand All @@ -60,13 +58,21 @@ def setup(self):
required=False,
)


self.add_argument(
"-o",
"--output-directory",
dest="target",
help="Target output path where the structure will be created",
type=str,
required=True,
)

self.add_argument(
"-i",
"--interactuve",
dest="interactive",
help="Runs artec in interactive mode.",
action="store_true",
)

self.add_argument(
Expand Down Expand Up @@ -107,7 +113,15 @@ def setup(self):
def main_args(appVersion) -> Namespace:
parser = Parser(appVersion)
parser.setup()
return parser.parse_args()
args = parser.parse_args()

if args.interactive:
print("Running Artec in interactive mode ....")
else:
if not args.target:
parser.error("The '-o' argument is required when not in interactive mode.")

return args


if __name__ == "__main__":
Expand Down
38 changes: 18 additions & 20 deletions artec/boiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import os
from pathlib import Path
from . import exceptions as ex
from . import templates as temps
from .temp import *
from . import repo
from . import logger


class boiler_builder:
def __init__(
self,
Expand All @@ -29,13 +30,14 @@ def __init__(

def _source_temp(self, template) -> list[dict[str, str]]:
try:
if template in temps.templates:
structure = temps.templates[template].format(self.target)
if template in templates:
structure = format_project_structure(templates[template], self.target)

else:
raise ex.InValidTemplate()

except ex.InValidTemplate:
structure = temps.templates["python"].format(self.target)
structure = format_project_structure(templates["python"], self.target)
return structure

def _source(self, source) -> list[dict[str, str]]:
Expand All @@ -44,33 +46,30 @@ def _source(self, source) -> list[dict[str, str]]:
raise ex.NoSource()
if os.path.isfile(source) and source.endswith(".json"):
with open(source, "rt", encoding="utf-8") as file_data:
structure = temps.static_list(json.load(file_data)).format(
structure = format_project_structure(json.load(file_data),
self.target
)
else:
raise ex.NotJsonFile()

except Exception:
structure = temps.templates["python"].format(self.target)
structure = format_project_structure(templates["python"], self.target)

return structure

def build(self):
print("> Creating folder structure: {}\n".format(self.target))

for entry in self.structure:
for _type, name in entry.items():
try:
joined = Path(os.path.join(self.target, name))
if "folder" in _type:
self._make_folder(joined)
elif "file" in _type:
self._make_file(joined)
else:
raise ex.NotValidJson()
print("Created: %s" % joined)
except Exception:
pass
for folder in self.structure['folders']:
folder_path = os.path.join(self.target, folder)
self._make_folder(folder_path)
print("Created: {}".format(folder_path))

for file_path in self.structure['files']:
file_path = os.path.join(self.target, file_path)
self._make_file(file_path)
print("Created: {}".format(file_path))

print()

if self.git:
Expand All @@ -83,7 +82,6 @@ def build(self):

def _make_file(self, path):
"""Create an empty file in a given directory"""
path.parent.mkdir(parents=True, exist_ok=True)
open(path, "a").close()

def _make_folder(self, path):
Expand Down
Loading

0 comments on commit 779f245

Please sign in to comment.