Skip to content

Commit de7228a

Browse files
author
Tom Softreck
committed
Release version 0.1.46
### Added - Changes in install/pyfunc2.sh
1 parent 6933524 commit de7228a

File tree

5 files changed

+132
-25
lines changed

5 files changed

+132
-25
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.1.46] - 2025-04-16
6+
7+
### Added
8+
- Changes in install/pyfunc2.sh
9+
510
## [0.1.45] - 2025-04-16
611

712
### Added

install/pyfunc2.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import sys
4+
import subprocess
5+
import platform
6+
7+
def run_command(command):
8+
"""Execute a shell command and return its output."""
9+
print(f"Running: {command}")
10+
try:
11+
result = subprocess.run(command, shell=True, check=True,
12+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
13+
universal_newlines=True)
14+
return result.stdout
15+
except subprocess.CalledProcessError as e:
16+
print(f"Error executing command: {e}")
17+
print(f"Error output: {e.stderr}")
18+
return None
19+
20+
def detect_distro():
21+
"""Detect the Linux distribution."""
22+
# Try to use /etc/os-release first
23+
if os.path.exists('/etc/os-release'):
24+
with open('/etc/os-release', 'r') as f:
25+
lines = f.readlines()
26+
for line in lines:
27+
if line.startswith('ID='):
28+
return line.split('=')[1].strip().strip('"').lower()
29+
30+
# Fallback to platform module
31+
return platform.linux_distribution()[0].lower()
32+
33+
def install_system_dependencies(distro):
34+
"""Install system dependencies based on the detected distribution."""
35+
print(f"Detected Linux distribution: {distro}")
36+
37+
# Debian-based systems (Ubuntu, Debian, etc.)
38+
if distro in ['debian', 'ubuntu', 'linuxmint', 'pop']:
39+
run_command("sudo apt-get update")
40+
run_command("sudo apt-get install -y imagemagick poppler-utils")
41+
42+
# Red Hat-based systems (RHEL, CentOS)
43+
elif distro in ['rhel', 'centos', 'fedora']:
44+
if distro == 'fedora':
45+
run_command("sudo dnf install -y ImageMagick poppler-utils")
46+
else:
47+
run_command("sudo yum install -y epel-release")
48+
run_command("sudo yum install -y ImageMagick poppler-utils")
49+
50+
# Arch Linux
51+
elif distro in ['arch', 'manjaro']:
52+
run_command("sudo pacman -Sy --noconfirm imagemagick poppler")
53+
54+
# openSUSE
55+
elif distro in ['opensuse', 'suse']:
56+
run_command("sudo zypper install -y ImageMagick poppler-tools")
57+
58+
else:
59+
print(f"Unsupported distribution: {distro}")
60+
print("Please install ImageMagick and Poppler manually.")
61+
return False
62+
63+
return True
64+
65+
def install_python_dependencies():
66+
"""Install required Python packages."""
67+
print("Installing Python dependencies...")
68+
run_command("pip install wand pdf2image pillow")
69+
70+
def main():
71+
"""Main function to install all dependencies."""
72+
print("Starting installation of pyfunc2 dependencies...")
73+
74+
# Check if running as root or with sudo
75+
if os.geteuid() != 0:
76+
print("Warning: Some commands may require sudo privileges.")
77+
78+
# Detect and install system dependencies
79+
distro = detect_distro()
80+
if install_system_dependencies(distro):
81+
print("System dependencies installed successfully.")
82+
83+
# Install Python dependencies
84+
install_python_dependencies()
85+
print("Python dependencies installed successfully.")
86+
87+
print("\nAll dependencies for pyfunc2 have been installed.")
88+
print("You can now use the pyfunc2 package in your projects.")
89+
90+
if __name__ == "__main__":
91+
main()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Configuration setup
1919
setup(
2020
name="pyfunc2",
21-
version="0.1.43",
21+
version="0.1.44",
2222
description="libs for cameramonit, ocr, fin-officer, cfo, and other projects",
2323
long_description=LONG_DESCRIPTION,
2424
long_description_content_type="text/markdown",

setup.py.bak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ except FileNotFoundError:
1818
# Configuration setup
1919
setup(
2020
name="pyfunc2",
21-
version="0.1.42",
21+
version="0.1.43",
2222
description="libs for cameramonit, ocr, fin-officer, cfo, and other projects",
2323
long_description=LONG_DESCRIPTION,
2424
long_description_content_type="text/markdown",

test/test_markdown_functions.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,57 @@ def tearDown(self):
2525
shutil.rmtree(self.test_dir)
2626

2727
def test_create_dir_structure(self):
28-
paths = ["test_docs/a", "test_docs/b"]
29-
create_dir_structure(paths)
30-
for path in paths:
31-
self.assertTrue(os.path.isdir(path))
28+
md_text = "A\nB"
29+
base_dir = self.test_dir
30+
create_dir_structure(md_text, base_dir)
31+
self.assertTrue(os.path.isdir(os.path.join(base_dir, "A")))
32+
self.assertTrue(os.path.isdir(os.path.join(base_dir, "B")))
3233

3334
def test_create_dir_structure_from_headers(self):
34-
headers = ["# A", "## B"]
35-
create_dir_structure_from_headers(headers, root=self.test_dir)
35+
# Prepare a markdown file
36+
md_path = os.path.join(self.test_dir, "headers.md")
37+
with open(md_path, "w") as f:
38+
f.write("# A\n## B\n")
39+
create_dir_structure_from_headers(md_path, path=self.test_dir)
3640
self.assertTrue(os.path.isdir(os.path.join(self.test_dir, "A")))
37-
self.assertTrue(os.path.isdir(os.path.join(self.test_dir, "A", "B")))
41+
self.assertTrue(os.path.isdir(os.path.join(self.test_dir, "B")))
3842

3943
def test_create_folders_files(self):
40-
structure = {self.test_dir: ["file1.md", "file2.md"]}
41-
create_folders_files(structure)
42-
for fname in structure[self.test_dir]:
43-
self.assertTrue(os.path.isfile(os.path.join(self.test_dir, fname)))
44+
# Prepare a markdown file
45+
md_path = os.path.join(self.test_dir, "files.md")
46+
with open(md_path, "w") as f:
47+
f.write("# Section\n```bash\necho hello\n```\n")
48+
create_folders_files(md_path, path=self.test_dir)
49+
self.assertTrue(os.path.isfile(os.path.join(self.test_dir, "Section", "1.bash")))
4450

4551
def test_get_code_extension_dict(self):
46-
ext_dict = get_code_extension_dict()
47-
self.assertIsInstance(ext_dict, dict)
48-
self.assertIn("py", ext_dict)
52+
content = """```python\nprint('hello')\n```"""
53+
ext_list = ["python"]
54+
ext_head_list = {"python": "#!/bin/python"}
55+
result = get_code_extension_dict(content, ext_list, ext_head_list)
56+
self.assertIsInstance(result, list)
57+
self.assertEqual(result[0]["extension"], "python")
4958

5059
def test_get_dictionary_structure_by_separator_list(self):
51-
paths = ["a/b/c.txt", "a/b/d.txt", "a/e.txt"]
52-
structure = get_dictionary_structure_by_separator_list(paths)
53-
self.assertIsInstance(structure, dict)
54-
self.assertIn("a", structure)
60+
markdown = """```bash\necho hello\n```\n```bash\necho world\n```"""
61+
blocks = get_dictionary_structure_by_separator_list(markdown)
62+
self.assertIsInstance(blocks, list)
63+
self.assertTrue(any("hello" in block for block in blocks))
5564

5665
def test_get_dictionary_structure_from_headers_content(self):
57-
headers = ["# A", "## B"]
58-
contents = ["desc A", "desc B"]
59-
structure = get_dictionary_structure_from_headers_content(headers, contents)
66+
# Prepare a markdown file
67+
md_path = os.path.join(self.test_dir, "headers_content.md")
68+
with open(md_path, "w") as f:
69+
f.write("# A\ndesc A\n## B\ndesc B\n")
70+
structure = get_dictionary_structure_from_headers_content(md_path)
6071
self.assertIsInstance(structure, dict)
6172
self.assertIn("A", structure)
6273

6374
def test_get_header_list(self):
6475
markdown_text = "# A\n## B"
6576
headers = get_header_list(markdown_text)
66-
self.assertIn("# A", headers)
67-
self.assertIn("## B", headers)
77+
self.assertIn("A", headers)
78+
self.assertIn("B", headers)
6879

6980
def test_get_url_list(self):
7081
markdown_text = "[OpenAI](https://openai.com)"

0 commit comments

Comments
 (0)