Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[skip-ci] new version #15

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ Create a `notgitmodules.yaml` file in your project's root directory.
```yaml
# directory_name: url (ssh or https)

# Example:
file_reader: https://github.com/Free-Apps-for-All/file_manager_git_module
# Example:
utils:
file_manager: https://github.com/not-gitmodules/notgitmodules-file-manager-py
file_encryptor: https://github.com/not-gitmodules/notgitmodules-file-encryptor-py

services:
forsaken_mail: https://github.com/malaohu/forsaken-mail
sim_mail: https://github.com/Webador/SlmMail
```

## 2. Usage Options
Expand Down Expand Up @@ -149,7 +155,7 @@ pip show not_gitmodules

- Example:
```text
not_gitmodules~=0.2
not_gitmodules~=0.0
```

---
Expand All @@ -158,7 +164,6 @@ pip show not_gitmodules

| Flag (all of them are optional) | Description | Example |
|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| `-d`, `--dir_name` | Specify the directory name where the modules will be saved. <br>By default, the modules will be saved in a directory named `my_gitmodules`. | • `not_gitmodules -d custom_folder`: Saves the repositories in `custom_folder` folder |
| `-y`, `--yaml-path` | Specify a custom path for the `notgitmodules.yaml` configuration file. <br>By default, it looks for `notgitmodules.yaml` in the current working directory. Naming it `notgitmodules` is a matter of best practices; you can name it as you want. | • `not_gitmodules -y /path/to/custom_notgitmodules.yaml`: Uses a custom YAML file located at `/path/to/custom_notgitmodules.yaml` |
| `-t`, `--threaded` | Enable threaded execution, where repositories are cloned in parallel (using threads). This flag is mutually exclusive with `-s`. <br> This is the default behavior if neither `-t` nor `-s` is specified. | • `not_gitmodules -t`: Clones repositories in parallel using threads <br> • `not_gitmodules --threaded`: Same as `-t`, using long form |
| `-s`, `--sequential` | Enable sequential execution, where repositories are cloned one by one in the order they appear in the YAML file. This flag is mutually exclusive with `-t`. | • `not_gitmodules -s`: Clones repositories one by one in order <br> • `not_gitmodules --sequential`: Same as `-s`, using long form |
Expand All @@ -177,13 +182,13 @@ not_gitmodules install
- ### Command pattern:

```bash
not_gitmodules install --yaml-path </path/to/notgitmodules.yaml> --dir_name <directory_name> --threaded
not_gitmodules install --yaml-path </path/to/notgitmodules.yaml> --threaded
```

or

```bash
not_gitmodules install -y </path/to/notgitmodules.yaml> -d <directory_name> -t
not_gitmodules install -y </path/to/notgitmodules.yaml> -t
```

---
Expand Down Expand Up @@ -223,7 +228,7 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY notgitmodules.yaml .

# install modules using not_gitmodules
RUN not_gitmodules install -y notgitmodules.yaml -d my_directory -t
RUN not_gitmodules install -y notgitmodules.yaml -t

CMD ["python", "main.py"]
```
Expand Down
14 changes: 7 additions & 7 deletions not_gitmodules/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def cli():
help="Path to the custom YAML configuration file. By default it's notgitmodules.yaml."
)

arg_parser.add_argument(
"-d", "--dir_name",
nargs="?", # optional
default="my_gitmodules",
help="The name of the directory the modules will be saved in. By default it's my_gitmodules."
)
# arg_parser.add_argument(
# "-d", "--dir_name",
# nargs="?", # optional
# default="my_gitmodules",
# help="The name of the directory the modules will be saved in. By default it's my_gitmodules."
# )

# modes
mode_group = arg_parser.add_mutually_exclusive_group()
Expand All @@ -40,6 +40,6 @@ def cli():

initializer(
yaml_config_path=args.yaml_path,
root_dir_name=args.dir_name,
# root_dir_name=args.dir_name,
download_in_threads=download_in_threads
)
48 changes: 21 additions & 27 deletions not_gitmodules/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
from concurrent.futures import ThreadPoolExecutor


def execute_sequentially(root_dir_name: str, yaml_content: dict):
for directory, repo_url in yaml_content.items():
clone_repo(root_dir_name=root_dir_name, directory_name=directory, url=repo_url)
def proceed_task(root_dir_name, directory_name, repo_url):
"""Packed-up collection of actions, to run in a separate thread."""
ensure_dir_exists(root_dir_name)

module_path = os.path.join(root_dir_name, directory)
if clone_repo(root_dir_name=root_dir_name, directory_name=directory_name, url=repo_url):
module_path = os.path.join(root_dir_name, directory_name)
delete_git_folder(module_path)
clean_github_leftovers(module_path)
# skipping else to not perform clean-up on skipped directories


def execute_in_threads(root_dir_name: str, yaml_content: dict):
def proceed_task(root_dir_name, directory, repo_url):
"""Packed-up collection of actions, to run in a separate thread."""
clone_repo(root_dir_name=root_dir_name, directory_name=directory, url=repo_url)
def execute_sequentially(root_dir_name: str, repo_dict: dict):
for directory_name, repo_url in repo_dict.items():
proceed_task(root_dir_name, directory_name, repo_url)

module_path = os.path.join(root_dir_name, directory)
delete_git_folder(module_path)
clean_github_leftovers(module_path)

def execute_in_threads(root_dir_name: str, repo_dict: dict):
with ThreadPoolExecutor() as executor:
futures = [
executor.submit(proceed_task, root_dir_name, directory, repo_url)
for directory, repo_url in yaml_content.items()
executor.submit(proceed_task, root_dir_name, directory_name, repo_url)
for directory_name, repo_url in repo_dict.items()
]

for future in futures:
Expand All @@ -33,25 +32,20 @@ def proceed_task(root_dir_name, directory, repo_url):

def initializer(
yaml_config_path: str = 'notgitmodules.yaml',
root_dir_name="my_gitmodules",
download_in_threads: bool = True,
):
# Read yaml
# Ensure root_dir exists
# Clone the repo to root dir
# Clean-up

"""
Initializes the download and clean-up process.

:param yaml_config_path: The path to notgitmodules.yaml file
:param root_dir_name: The name of directory where modules will be downloaded to.
:param download_in_threads: If you want to clone repos simultaneously or one at a time
# :param max_threads: Maximum amount of allowed threads
:return:
"""
yaml_content = read_yaml(yaml_config_path)
ensure_dir_exists(root_dir_name)

if download_in_threads:
execute_in_threads(root_dir_name, yaml_content)
else:
execute_sequentially(root_dir_name, yaml_content)
for root_dir_name, repo_dict in yaml_content.items():
ensure_dir_exists(root_dir_name)

if download_in_threads:
execute_in_threads(root_dir_name, repo_dict)
else:
execute_sequentially(root_dir_name, repo_dict)
4 changes: 3 additions & 1 deletion not_gitmodules/parts/clone_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess


def clone_repo(root_dir_name, directory_name, url):
def clone_repo(root_dir_name, directory_name, url) -> bool | None:
"""Clone the repository into the specified directory."""
target_path = os.path.join(root_dir_name, directory_name)

Expand All @@ -27,3 +27,5 @@ def clone_repo(root_dir_name, directory_name, url):
print(f"Failed to clone {url}: {e.stderr}")
except FileExistsError:
print(f"Target path {target_path} already exists.")
else:
return True
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from setuptools import setup, find_packages

__version__ = "0.4.3"
__version__ = "0.4.4"

setup(
name='not_gitmodules',
version='0.4.3',
version='0.4.4',
packages=find_packages(),
license='Custom License',
entry_points={
Expand Down
2 changes: 0 additions & 2 deletions speed_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def test_sequentially(root_dir_name):
initializer(
yaml_config_path='dev/config.yaml',
download_in_threads=False,
root_dir_name=root_dir_name
)


Expand All @@ -36,7 +35,6 @@ def test_parallely(root_dir_name):
initializer(
yaml_config_path='dev/config.yaml',
download_in_threads=True,
root_dir_name=root_dir_name
)


Expand Down
Loading