Skip to content

Commit 8449a86

Browse files
made project clean
1 parent d4dfcc3 commit 8449a86

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

pica/__pycache__/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Auto-generated package init for __pycache__

restructure_project.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
A one-time script to restructure the PICA project from a flat layout
3+
to a professional, installable Python package structure.
4+
"""
15
import os
26
import shutil
37
import subprocess
@@ -15,7 +19,7 @@
1519
"LCR_Keysight_E4980A": "pica/keysight",
1620
"Lock_in_amplifier": "pica/lockin",
1721
"Utilities": "pica/utils",
18-
"assets": "pica/assets" # Assets often go inside the package for GUI access
22+
"assets": "pica/assets" # Assets often go inside the package for GUI access
1923
}
2024

2125
ROOT_FILES_TO_MOVE = {
@@ -28,7 +32,7 @@ def run_command(command):
2832
try:
2933
subprocess.check_call(command, shell=True)
3034
except subprocess.CalledProcessError as e:
31-
print(f"Error running command: {command}")
35+
print(f"Error running command: {command}\n{e}")
3236
sys.exit(1)
3337

3438
def ensure_dir(path):
@@ -53,38 +57,32 @@ def update_imports(file_path):
5357

5458
original_content = content
5559

56-
# 1. Fix Utilities imports
57-
content = re.sub(r'from Utilities', 'from pica.utils', content)
58-
content = re.sub(r'import Utilities', 'import pica.utils', content)
59-
60-
# 2. Fix Keithley 2400 imports
61-
content = re.sub(r'from Keithley_2400', 'from pica.keithley.k2400', content)
62-
63-
# 3. Fix Lakeshore imports
64-
content = re.sub(r'from Lakeshore_350_340', 'from pica.lakeshore', content)
65-
66-
# 4. Fix Delta Mode imports
67-
content = re.sub(r'from Delta_mode_Keithley_6221_2182', 'from pica.keithley.delta_mode', content)
68-
69-
# 5. Fix Keysight imports
70-
content = re.sub(r'from LCR_Keysight_E4980A', 'from pica.keysight', content)
71-
72-
# 6. Fix generic "assets" paths in GUI code (assuming relative paths)
73-
# This replaces "assets/" with dynamic path logic, but for now let's just update the string
74-
# If the code uses strict relative paths, this might need manual checking.
75-
60+
# Generic import fixer based on the MAPPING dictionary
61+
# This makes the script more robust to future changes
62+
replacements = {
63+
"from Utilities": "from pica.utils",
64+
"import Utilities": "import pica.utils",
65+
"from Keithley_2400": "from pica.keithley.k2400",
66+
"from Lakeshore_350_340": "from pica.lakeshore",
67+
"from Delta_mode_Keithley_6221_2182": "from pica.keithley.delta_mode",
68+
"from LCR_Keysight_E4980A": "from pica.keysight",
69+
}
70+
71+
for old, new in replacements.items():
72+
content = re.sub(old, new, content)
73+
7674
if content != original_content:
7775
print(f" [Refactoring] Updated imports in {file_path}")
7876
with open(file_path, 'w', encoding='utf-8') as f:
7977
f.write(content)
8078

8179
def main():
8280
print("--- Starting Professional PICA Refactoring ---")
83-
81+
8482
# 1. Create Base Directories
8583
ensure_dir("pica")
8684
ensure_dir("scripts")
87-
85+
8886
# Check if this is a git repo
8987
is_git = os.path.exists(".git")
9088
if is_git:
@@ -98,7 +96,7 @@ def main():
9896
print(f"Moving {old_name} -> {new_path}")
9997
# Ensure parent dir exists
10098
ensure_dir(os.path.dirname(new_path))
101-
99+
102100
if is_git:
103101
# git mv expects the parent directory of destination to exist
104102
run_command(f'git mv "{old_name}" "{new_path}"')
@@ -126,7 +124,7 @@ def main():
126124
for filename in filenames:
127125
if filename.endswith(".py"):
128126
update_imports(os.path.join(dirpath, filename))
129-
127+
130128
# Also check tests
131129
if os.path.exists("tests"):
132130
for dirpath, _, filenames in os.walk("tests"):

run_pica.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Main entry point to launch the PICA application.
3+
"""
14
from pica.main import main
25

36
if __name__ == '__main__':

0 commit comments

Comments
 (0)