Skip to content
Snippets Groups Projects
Commit 9de63262 authored by Alain Klotz's avatar Alain Klotz
Browse files

update imports

parent c1105c1d
No related branches found
No related tags found
No related merge requests found
......@@ -8,8 +8,56 @@ guitastro_device_siemensae02.device_siemensae02
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import glob
import os
__version__ = "20240702"
from .device_siemensae02 import Device_Siemensae02
import os, sys, pathlib
# --- Get the module name
# __file__ = 'C:\\d\\python\\gestion_packages\\mymodule\\src\\mymodule\\__init__.py'
modulename = pathlib.Path(__file__).parts[-2]
# --- Special for Sphinx in mymodule/docs
path = os.path.abspath(os.path.join(__file__, "..", "..", modulename))
sys.path.append(path) if path not in sys.path else None
# --- Switch on True to update the list of imports
if False:
import glob, os
import importlib
pyfiles = glob.glob(os.path.abspath(os.path.join(__file__, "..", "*.py")))
files = []
imps = []
for pyfile in pyfiles:
if os.path.basename(pyfile)[0] != "_" and os.path.isfile(pyfile):
file = os.path.splitext(os.path.basename(pyfile))[0]
#print(f"{file=}")
with open(pyfile, "rt") as fid:
lines = fid.readlines()
for line in lines:
# 0123456789
# class O(
if len(line) < 8:
continue
if line[0:6] == "class ":
k = line.find("(")
if k > 6:
obj = line[6:k].strip()
imp = f"from .{file} import {obj}"
imps.append(imp)
files.append(file)
#importlib.__import__(modulename, fromlist=files)
print("="*40)
for file in files:
print(f"import {file}")
print()
for imp in imps:
print(f"{imp}")
print("="*40)
del pyfiles, pyfile, file, files, os, glob, importlib, fid, lines, line, k, obj, imp, imps
# --- All imports generated by the switch = True
import component_electrical_relay_siemensae02
import device_siemensae02
from .component_electrical_relay_siemensae02 import ComponentElectricalRelaySiemensae02
from .device_siemensae02 import Device_Siemensae02
......@@ -4,21 +4,10 @@ import sys
import traceback
import time
try:
# guitastro is installed with setup.py
from guitastro import ComponentElectricalRelay, ComponentException, Communication
except:
# guitastro is installed with only requirements.in
# guitastro_camera_* folders must be copied at the same root folder than guitastro
pwd = os.getcwd()
short_paths = ['../../../guitastro/src']
for short_path in short_paths:
path = os.path.abspath(os.path.join(pwd, short_path))
if path not in sys.path:
sys.path.insert(0, path)
from guitastro.component import ComponentException
from guitastro.component_electrical_relay import ComponentElectricalRelay
from guitastro.communications import Communication
# --- import guitastro
path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src"))
sys.path.append(path) if path not in sys.path else None
from guitastro import *
# #####################################################################
# #####################################################################
......
......@@ -6,38 +6,17 @@ import glob
import shutil
import traceback
try:
from .component_electrical_relay_siemensae02 import ComponentElectricalRelaySiemensae02
except:
from component_electrical_relay_siemensae02 import ComponentElectricalRelaySiemensae02
try:
# guitastro is installed with setup.py
from guitastro import Ephemeris, Device, Communication, GuitastroTools
except:
# guitastro is installed with only requirements.in
# --- add resource files in the current path directory
fic_inps = []
fic_inps.append("../../resources/solar_system/*.bsp")
for fic_inp in fic_inps:
fic_ins = glob.glob(os.path.abspath(os.path.join(os.getcwd(), fic_inp)))
for fic_in in fic_ins:
fic_out = os.path.join(os.getcwd(), os.path.basename(fic_in))
if not os.path.exists(fic_out):
shutil.copy(fic_in, fic_out)
# guitastro_camera_* folders must be copied at the same root folder than guitastro
pwd = os.getcwd()
short_paths = ['../../../guitastro/src']
for short_path in short_paths:
path = os.path.abspath(os.path.join(pwd, short_path))
if path not in sys.path:
sys.path.insert(0, path)
from guitastro.device import Device
from guitastro.ephemeris import Ephemeris
from guitastro.communications import Communication
from guitastro.guitastrotools import GuitastroTools
# --- import guitastro
path = os.path.abspath(os.path.join(__file__, "..", "..", "..", "..", "guitastro", "src"))
sys.path.append(path) if path not in sys.path else None
from guitastro import *
import __init__
# --- import guitastro_device_siemensae02
path = os.path.abspath(os.path.join(__file__, "..", ".."))
sys.path.append(path) if path not in sys.path else None
from guitastro_device_siemensae02 import *
# #####################################################################
# #####################################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment