__init__.py
2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
guitastro_device_ascomcam.device_ascomcam
-------------------------------------------
.. automodule:: guitastro_device_ascomcam.device_ascomcam
:members:
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
__version__ = "20240702"
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_detector_shutter_ascomcam
import component_detector_timer_ascomcam
import component_sensor_detector_ascomcam
import device_ascomcam
from .component_detector_shutter_ascomcam import ComponentDetectorShutterAscomcam
from .component_detector_timer_ascomcam import ComponentDetectorTimerAscomcam
from .component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcamDoAcq
from .component_sensor_detector_ascomcam import ComponentSensorDetectorAscomcam
from .device_ascomcam import Device_Ascomcam