splent-cli 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ import os
2
+ import subprocess
3
+ import click
4
+
5
+ from splent_cli.utils.path_utils import PathUtils
6
+
7
+
8
+ @click.command(
9
+ "selenium", help="Executes Selenium tests based on the environment."
10
+ )
11
+ @click.argument("module", required=False)
12
+ def selenium(module):
13
+ # Absolute paths
14
+ working_dir = PathUtils.get_working_dir()
15
+ modules_dir = PathUtils.get_modules_dir()
16
+
17
+ def validate_module(module):
18
+ """Check if the module exists."""
19
+ if module:
20
+ module_path = os.path.join(modules_dir, module)
21
+ if not os.path.exists(module_path):
22
+ raise click.UsageError(f"Module '{module}' does not exist.")
23
+ selenium_test_path = os.path.join(
24
+ module_path, "tests", "test_selenium.py"
25
+ )
26
+ if not os.path.exists(selenium_test_path):
27
+ raise click.UsageError(
28
+ f"Selenium test for module '{module}' does not exist at path "
29
+ f"'{selenium_test_path}'."
30
+ )
31
+
32
+ def run_selenium_tests_in_local(module):
33
+ """Run the Selenium tests."""
34
+ if module:
35
+ selenium_test_path = os.path.join(
36
+ modules_dir, module, "tests", "test_selenium.py"
37
+ )
38
+ test_command = ["python", selenium_test_path]
39
+ else:
40
+ selenium_test_paths = []
41
+ for module in os.listdir(modules_dir):
42
+ tests_dir = os.path.join(modules_dir, module, "tests")
43
+ selenium_test_path = os.path.join(
44
+ tests_dir, "test_selenium.py"
45
+ )
46
+ if os.path.exists(selenium_test_path):
47
+ selenium_test_paths.append(selenium_test_path)
48
+ test_command = ["python"] + selenium_test_paths
49
+
50
+ click.echo(
51
+ f"Running Selenium tests with command: {' '.join(test_command)}"
52
+ )
53
+ subprocess.run(test_command, check=True)
54
+
55
+ # Validate module if provided
56
+ if module:
57
+ validate_module(module)
58
+
59
+ if working_dir == "/app/":
60
+
61
+ click.echo(
62
+ click.style(
63
+ "Currently it is not possible to run this "
64
+ "command from a Docker environment, do you want to implement it yourself? ^^",
65
+ fg="red",
66
+ )
67
+ )
68
+
69
+ elif working_dir == "":
70
+ run_selenium_tests_in_local(module)
71
+
72
+ elif working_dir == "/vagrant/":
73
+
74
+ click.echo(
75
+ click.style(
76
+ "Currently it is not possible to run this "
77
+ "command from a Vagrant environment, do you want to implement it yourself? ^^",
78
+ fg="red",
79
+ )
80
+ )
81
+
82
+ else:
83
+ click.echo(
84
+ click.style(f"Unrecognized WORKING_DIR: {working_dir}", fg="red")
85
+ )
@@ -0,0 +1,45 @@
1
+ import click
2
+ import subprocess
3
+ import os
4
+
5
+
6
+ @click.command(
7
+ "test",
8
+ help="Runs pytest on the blueprints directory or a specific module.",
9
+ )
10
+ @click.argument("module_name", required=False)
11
+ @click.option(
12
+ "-k",
13
+ "keyword",
14
+ help="Only run tests that match the given substring expression.",
15
+ )
16
+ def test(module_name, keyword):
17
+ base_path = os.path.join(os.getenv("WORKING_DIR", ""), "app/modules")
18
+ test_path = base_path
19
+
20
+ if module_name:
21
+ test_path = os.path.join(base_path, module_name)
22
+ if not os.path.exists(test_path):
23
+ click.echo(
24
+ click.style(
25
+ f"Module '{module_name}' does not exist.", fg="red"
26
+ )
27
+ )
28
+ return
29
+ click.echo(f"Running tests for the '{module_name}' module...")
30
+ else:
31
+ click.echo("Running tests for all modules...")
32
+
33
+ pytest_cmd = ["pytest", "-v", "--ignore-glob=*selenium*", test_path]
34
+
35
+ if keyword:
36
+ pytest_cmd.extend(["-k", keyword])
37
+
38
+ try:
39
+ subprocess.run(pytest_cmd, check=True)
40
+ except subprocess.CalledProcessError as e:
41
+ click.echo(click.style(f"Error running tests: {e}", fg="red"))
42
+
43
+
44
+ if __name__ == "__main__":
45
+ test()
@@ -0,0 +1,159 @@
1
+ import click
2
+ import os
3
+ import subprocess
4
+
5
+
6
+ def create_temp_requirements(requirements_path, temp_requirements_path):
7
+ """Create a temporary requirements file without versions and handle editable sources."""
8
+ editable_package = None
9
+ with (
10
+ open(requirements_path) as f,
11
+ open(temp_requirements_path, "w") as temp_f,
12
+ ):
13
+ for line in f:
14
+ if line.startswith("-e"):
15
+ editable_package = line.strip() # Store the editable package
16
+ elif line.strip():
17
+ package = line.split("==")[
18
+ 0
19
+ ].strip() # Remove version information
20
+ temp_f.write(package + "\n")
21
+ return editable_package
22
+
23
+
24
+ def uninstall_packages():
25
+ """Uninstall all non-editable packages."""
26
+ installed_packages = (
27
+ subprocess.check_output(["pip", "freeze"]).decode("utf-8").splitlines()
28
+ )
29
+ non_editable_packages = [
30
+ pkg for pkg in installed_packages if not pkg.startswith("-e")
31
+ ]
32
+ if non_editable_packages:
33
+ subprocess.run(
34
+ ["pip", "uninstall", "-y"]
35
+ + [pkg.split("==")[0] for pkg in non_editable_packages]
36
+ )
37
+
38
+
39
+ def install_packages(requirements_file):
40
+ """Install packages from a requirements file."""
41
+ subprocess.run(["pip", "install", "-r", requirements_file])
42
+
43
+
44
+ def regenerate_requirements(requirements_path):
45
+ """Regenerate requirements.txt with resolved versions."""
46
+ freeze_output = subprocess.check_output(["pip", "freeze"]).decode("utf-8")
47
+ with open(requirements_path, "w") as f:
48
+ f.write(freeze_output)
49
+
50
+
51
+ def reinstall_editable_package(editable_package):
52
+ """Reinstall the editable package."""
53
+ if editable_package:
54
+ editable_path = editable_package.split()[
55
+ 1
56
+ ] # Extract the path from '-e ./app'
57
+ subprocess.run(
58
+ ["pip", "install", "-e", editable_path],
59
+ stdout=subprocess.DEVNULL, # Suppress output
60
+ stderr=subprocess.DEVNULL, # Suppress errors
61
+ )
62
+
63
+
64
+ def clean_up(temp_requirements_path):
65
+ """Remove the temporary requirements file."""
66
+ if os.path.exists(temp_requirements_path):
67
+ os.remove(temp_requirements_path)
68
+
69
+
70
+ def update_pip():
71
+ """Update pip dependencies."""
72
+ requirements_path = os.path.join(
73
+ os.getenv("WORKING_DIR", ""), "requirements.txt"
74
+ )
75
+ temp_requirements_path = os.path.join(
76
+ os.getenv("WORKING_DIR", ""), "temp_requirements.txt"
77
+ )
78
+
79
+ editable_package = create_temp_requirements(
80
+ requirements_path, temp_requirements_path
81
+ )
82
+ uninstall_packages()
83
+ install_packages(temp_requirements_path)
84
+ regenerate_requirements(requirements_path)
85
+ reinstall_editable_package(editable_package)
86
+ clean_up(temp_requirements_path)
87
+
88
+
89
+ def update_npm():
90
+ """Update npm dependencies."""
91
+ working_dir = os.getenv("WORKING_DIR", "")
92
+ package_json_path = os.path.join(working_dir, "package.json")
93
+
94
+ if not os.path.exists(package_json_path):
95
+ click.echo(
96
+ click.style(
97
+ "No package.json found. Skipping npm update.", fg="yellow"
98
+ )
99
+ )
100
+ return
101
+
102
+ try:
103
+ # Step 1: Update package.json to latest versions
104
+ subprocess.run(["npx", "npm-check-updates", "-u"], cwd=working_dir)
105
+
106
+ # Step 2: Install updated dependencies
107
+ subprocess.run(["npm", "install"], cwd=working_dir)
108
+
109
+ click.echo(
110
+ click.style("NPM dependencies updated successfully!", fg="green")
111
+ )
112
+ except subprocess.CalledProcessError as e:
113
+ click.echo(click.style(f"Error during npm update: {e}", fg="red"))
114
+
115
+
116
+
117
+ @click.command("update", help="Upload all pip dependencies.")
118
+ def update():
119
+ """Update both pip and npm dependencies."""
120
+ try:
121
+ click.echo("Updating pip dependencies...")
122
+ update_pip()
123
+ click.echo("Updating npm dependencies...")
124
+ update_npm()
125
+ click.echo(
126
+ click.style("All dependencies updated successfully!", fg="green")
127
+ )
128
+ except Exception as e:
129
+ click.echo(click.style(f"Error during update: {e}", fg="red"))
130
+
131
+
132
+ @click.command("update:pip", help="Upload all pip dependencies.")
133
+ def update_pip_cmd():
134
+ """Update only pip dependencies."""
135
+ try:
136
+ click.echo("Updating pip dependencies...")
137
+ update_pip()
138
+ click.echo(
139
+ click.style("Pip dependencies updated successfully!", fg="green")
140
+ )
141
+ except Exception as e:
142
+ click.echo(click.style(f"Error during pip update: {e}", fg="red"))
143
+
144
+
145
+ @click.command("update:npm", help="Upload all npm dependencies.")
146
+ def update_npm_cmd():
147
+ """Update only npm dependencies."""
148
+ try:
149
+ click.echo("Updating npm dependencies...")
150
+ update_npm()
151
+ click.echo(
152
+ click.style("NPM dependencies updated successfully!", fg="green")
153
+ )
154
+ except Exception as e:
155
+ click.echo(click.style(f"Error during npm update: {e}", fg="red"))
156
+
157
+
158
+ if __name__ == "__main__":
159
+ cli()
@@ -0,0 +1,68 @@
1
+ import logging
2
+ import click
3
+ import os
4
+ import subprocess
5
+
6
+ from splent_cli.utils.path_utils import PathUtils
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+ MODULES_DIR = PathUtils.get_modules_dir()
11
+ EXCLUDED_MODULES = {".pytest_cache", "__pycache__"}
12
+
13
+
14
+ def load_excluded_modules():
15
+ """Load additional excluded modules from .moduleignore file."""
16
+ moduleignore_path = os.path.join(os.getenv("WORKING_DIR", ""), ".moduleignore")
17
+ if os.path.exists(moduleignore_path):
18
+ with open(moduleignore_path) as f:
19
+ EXCLUDED_MODULES.update(filter(None, map(str.strip, f)))
20
+ return EXCLUDED_MODULES
21
+
22
+
23
+ EXCLUDED_MODULES = load_excluded_modules()
24
+
25
+
26
+ @click.command("webpack:compile", help="Compile webpack for one or all modules.")
27
+ @click.argument("module_name", required=False)
28
+ @click.option("--watch", is_flag=True, help="Enable watch mode for development.")
29
+ def webpack_compile(module_name, watch):
30
+ """Run webpack for a specific module or all modules."""
31
+ production = os.getenv("FLASK_ENV", "develop") == "production"
32
+
33
+ modules = (
34
+ [module_name]
35
+ if module_name
36
+ else [m for m in os.listdir(MODULES_DIR) if os.path.isdir(os.path.join(MODULES_DIR, m)) and m not in EXCLUDED_MODULES]
37
+ )
38
+
39
+ for module in modules:
40
+ compile_module(module, watch, production)
41
+
42
+
43
+ def compile_module(module, watch, production):
44
+ """Compile a single module using webpack."""
45
+ module_path = os.path.join(MODULES_DIR, module)
46
+ webpack_file = os.path.join(module_path, "assets", "js", "webpack.config.js")
47
+
48
+ if not os.path.exists(webpack_file):
49
+ click.echo(click.style(f"⚠ No webpack.config.js found in {module}, skipping...", fg="yellow"))
50
+ return
51
+
52
+ click.echo(click.style(f"🚀 Compiling {module}...", fg="cyan"))
53
+
54
+ mode = "production" if production else "development"
55
+ extra_flags = "--devtool source-map --no-cache" if not production else ""
56
+ watch_flag = "--watch" if watch and not production else ""
57
+
58
+ webpack_command = f"npx webpack --config {webpack_file} --mode {mode} {watch_flag} {extra_flags} --color"
59
+
60
+ try:
61
+ if watch:
62
+ subprocess.Popen(webpack_command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
63
+ click.echo(click.style(f"👀 Watching {module} in {mode} mode...", fg="blue"))
64
+ else:
65
+ subprocess.run(webpack_command, shell=True, check=True)
66
+ click.echo(click.style(f"✅ Successfully compiled {module} in {mode} mode!", fg="green"))
67
+ except subprocess.CalledProcessError as e:
68
+ click.echo(click.style(f"❌ Error compiling {module}: {e}", fg="red"))
File without changes
@@ -0,0 +1,116 @@
1
+ import os
2
+ import importlib.util
3
+ from dotenv import load_dotenv
4
+ from splent_framework.core.configuration.configuration import uploads_folder_name
5
+
6
+ load_dotenv()
7
+
8
+
9
+ class PathUtils:
10
+
11
+ @staticmethod
12
+ def get_working_dir():
13
+ return os.getenv("WORKING_DIR", "")
14
+
15
+ @staticmethod
16
+ def get_app_dir():
17
+ working_dir = PathUtils.get_working_dir()
18
+ SPLENT = os.getenv("SPLENT", "false").lower() in (
19
+ "true",
20
+ "1",
21
+ "yes",
22
+ )
23
+
24
+ if SPLENT:
25
+ # Git submodules mode
26
+ return os.path.join(working_dir, "splent_app", "splent_app")
27
+
28
+ # PyPi mode
29
+ package = importlib.util.find_spec("splent_app")
30
+ if package and package.origin:
31
+ return os.path.dirname(package.origin)
32
+
33
+ raise FileNotFoundError(
34
+ "Could not find 'splent_app'. Check the installation."
35
+ )
36
+
37
+ @staticmethod
38
+ def get_modules_dir():
39
+ return os.path.join(PathUtils.get_app_dir(), "modules")
40
+
41
+ @staticmethod
42
+ def get_splent_cli_dir():
43
+ SPLENT = os.getenv("SPLENT", "false").lower() in (
44
+ "true",
45
+ "1",
46
+ "yes",
47
+ )
48
+
49
+ base_dir = os.getcwd()
50
+ if SPLENT:
51
+ return os.path.join(base_dir, "splent_cli", "splent_cli")
52
+
53
+ return os.path.join(base_dir, "splent_cli")
54
+
55
+ @staticmethod
56
+ def get_splent_cli_templates_dir():
57
+ return os.path.join(PathUtils.get_splent_cli_dir(), "templates")
58
+
59
+ @staticmethod
60
+ def get_commands_dir():
61
+ return os.path.join(PathUtils.get_splent_cli_dir(), "commands")
62
+
63
+ @staticmethod
64
+ def get_commands_path():
65
+ return os.path.abspath(PathUtils.get_commands_dir())
66
+
67
+ @staticmethod
68
+ def get_splent_framework_dir():
69
+ working_dir = PathUtils.get_working_dir()
70
+ SPLENT = os.getenv("SPLENT", "false").lower() in (
71
+ "true",
72
+ "1",
73
+ "yes",
74
+ )
75
+
76
+ if SPLENT:
77
+ # Git submodules mode
78
+ return os.path.join(working_dir, "splent_framework", "splent_framework")
79
+
80
+ # PyPi mode
81
+ package = importlib.util.find_spec("splent_framework")
82
+ if package and package.origin:
83
+ return os.path.dirname(package.origin)
84
+
85
+ @staticmethod
86
+ def get_core_dir():
87
+ return os.path.join(PathUtils.get_splent_framework_dir(), "core")
88
+
89
+ @staticmethod
90
+ def get_env_dir():
91
+ return os.path.join(PathUtils.get_working_dir(), ".env")
92
+
93
+ @staticmethod
94
+ def get_app_log_dir():
95
+ return os.path.join(PathUtils.get_working_dir(), "app.log")
96
+
97
+ def get_uploads_dir():
98
+ working_dir = PathUtils.get_working_dir()
99
+ SPLENT = os.getenv("SPLENT", "false").lower() in (
100
+ "true",
101
+ "1",
102
+ "yes",
103
+ )
104
+
105
+ if SPLENT:
106
+ # Git submodules mode
107
+ return os.path.join(
108
+ working_dir, "splent_app", uploads_folder_name()
109
+ )
110
+
111
+ # PyPi mode
112
+ package = importlib.util.find_spec("splent_app")
113
+ if package and package.origin:
114
+ return os.path.join(
115
+ os.path.dirname(package.origin), uploads_folder_name()
116
+ )
@@ -0,0 +1,113 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc.
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of protecting
53
+ users' freedom to change the software. The systematic pattern of such
54
+ abuse occurs in the area of products for individuals to use, which is
55
+ precisely where it is most unacceptable. Therefore, we have designed
56
+ this version of the GPL to prohibit the practice for those products. If
57
+ such problems arise substantially in other domains, we stand ready to
58
+ extend this provision to those domains in future versions of the GPL, as
59
+ needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds
78
+ of works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ (El texto completo es largo, puedes encontrarlo en https://www.gnu.org/licenses/gpl-3.0.txt)
113
+