watch-import 0.0.2__tar.gz

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,7 @@
1
+ Copyright 2024 Daniel Sundberg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.1
2
+ Name: watch_import
3
+ Version: 0.0.2
4
+ Summary: Watch target file/folder for changes in python files and import/reimport
5
+ Author: Daniel Sundberg
6
+ License: Copyright 2024 Daniel Sundberg
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ Keywords: import,reimport,save
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: watchfiles
20
+
21
+ # watch_import
22
+ Watch_import uses `watchfiles` to observe a file or folder. When a file is saved it will re/import that file into the watch_import context.
23
+
24
+
25
+ # Using as a file/folder watcher
26
+ ```sh
27
+ > watch_import PATH/TO_PYTHON_FILES
28
+ ```
29
+
30
+ # Using as an import
31
+ ```python
32
+ from watch_import import watch_me
33
+
34
+ print('hello')
35
+ watch_me()
36
+ ```
37
+
38
+ # Example use-case OCP CAD Viewer
39
+
40
+ ```python
41
+ import cadquery as cq
42
+ from ocp_vscode import show
43
+ from watch_import import watch_me
44
+
45
+ body = cq.Workplane("XY").box(5, 10, 15)
46
+ show(body)
47
+
48
+ watch_me()
49
+ ```
50
+
51
+ Run this file once and it will start watching and "re-run" once saved.
@@ -0,0 +1,31 @@
1
+ # watch_import
2
+ Watch_import uses `watchfiles` to observe a file or folder. When a file is saved it will re/import that file into the watch_import context.
3
+
4
+
5
+ # Using as a file/folder watcher
6
+ ```sh
7
+ > watch_import PATH/TO_PYTHON_FILES
8
+ ```
9
+
10
+ # Using as an import
11
+ ```python
12
+ from watch_import import watch_me
13
+
14
+ print('hello')
15
+ watch_me()
16
+ ```
17
+
18
+ # Example use-case OCP CAD Viewer
19
+
20
+ ```python
21
+ import cadquery as cq
22
+ from ocp_vscode import show
23
+ from watch_import import watch_me
24
+
25
+ body = cq.Workplane("XY").box(5, 10, 15)
26
+ show(body)
27
+
28
+ watch_me()
29
+ ```
30
+
31
+ Run this file once and it will start watching and "re-run" once saved.
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "watch_import"
3
+ version = "0.0.2"
4
+ authors = [
5
+ {name = "Daniel Sundberg"}
6
+ ]
7
+ description = "Watch target file/folder for changes in python files and import/reimport"
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ keywords = ["import", "reimport", "save"]
11
+ license = {file = "LICENSE"}
12
+
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: MIT License",
16
+ ]
17
+
18
+ dependencies = [
19
+ "watchfiles"
20
+ ]
21
+
22
+ [build-system]
23
+ requires = ["setuptools"]
24
+ build-backend = "setuptools.build_meta"
25
+
26
+ [project.scripts]
27
+ watch_import = "watch_import.module:watch_args"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .module import watch_args, watch_me, watch
@@ -0,0 +1,79 @@
1
+ import os
2
+ import sys
3
+ import asyncio
4
+ import importlib
5
+ import importlib.abc
6
+ import traceback
7
+ from watchfiles import awatch, PythonFilter
8
+
9
+ import importlib.util
10
+ import sys
11
+
12
+ modules = {}
13
+ specs = {}
14
+
15
+ class myfinder(importlib.abc.MetaPathFinder):
16
+ def __init__(self):
17
+ pass
18
+
19
+ def find_spec(self, full, path, target=None):
20
+ if full in specs:
21
+ return specs[full]
22
+ return None
23
+
24
+ sys.meta_path.append(myfinder())
25
+
26
+ async def main(pwd):
27
+ print(f"Watching {pwd} for changes")
28
+ async for changes in awatch(pwd, watch_filter=PythonFilter()):
29
+ for c in changes:
30
+ fn = c[1]
31
+ rfn = os.path.relpath(fn, os.path.basename(pwd))
32
+
33
+ if fn == pwd:
34
+ name = 'current'
35
+ else:
36
+ name, _ = os.path.splitext(rfn)
37
+
38
+ print(f"Reloading: {name}")
39
+ if name in modules:
40
+ importlib.reload(modules[name])
41
+ else:
42
+ spec = importlib.util.spec_from_file_location(name, fn)
43
+ mod = importlib.util.module_from_spec(spec)
44
+ specs[name] = spec
45
+ spec.loader.exec_module(mod)
46
+ sys.modules[name] = mod
47
+ modules[name] = mod
48
+
49
+ def watch(f):
50
+ while True:
51
+ try:
52
+ asyncio.run(main(f))
53
+ except KeyboardInterrupt:
54
+ print("Exiting")
55
+ exit(0)
56
+ except Exception as e:
57
+ print(traceback.format_exc())
58
+ print("*"*80)
59
+ print("Something went horribly wrong!, trace above, quick summary:")
60
+ print(e)
61
+
62
+ loops = {}
63
+ def watch_me():
64
+ fn = sys.argv[0]
65
+ if not fn in loops:
66
+ loop = asyncio.new_event_loop()
67
+ loops[fn] = loop
68
+ asyncio.set_event_loop(loop)
69
+ watch(fn)
70
+
71
+ def watch_args():
72
+ try:
73
+ pwd = os.path.abspath(sys.argv[1])
74
+ except IndexError:
75
+ pwd = os.getcwd()
76
+ watch(pwd)
77
+
78
+ if __name__ == "__main__":
79
+ watch_args()
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.1
2
+ Name: watch_import
3
+ Version: 0.0.2
4
+ Summary: Watch target file/folder for changes in python files and import/reimport
5
+ Author: Daniel Sundberg
6
+ License: Copyright 2024 Daniel Sundberg
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ Keywords: import,reimport,save
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: watchfiles
20
+
21
+ # watch_import
22
+ Watch_import uses `watchfiles` to observe a file or folder. When a file is saved it will re/import that file into the watch_import context.
23
+
24
+
25
+ # Using as a file/folder watcher
26
+ ```sh
27
+ > watch_import PATH/TO_PYTHON_FILES
28
+ ```
29
+
30
+ # Using as an import
31
+ ```python
32
+ from watch_import import watch_me
33
+
34
+ print('hello')
35
+ watch_me()
36
+ ```
37
+
38
+ # Example use-case OCP CAD Viewer
39
+
40
+ ```python
41
+ import cadquery as cq
42
+ from ocp_vscode import show
43
+ from watch_import import watch_me
44
+
45
+ body = cq.Workplane("XY").box(5, 10, 15)
46
+ show(body)
47
+
48
+ watch_me()
49
+ ```
50
+
51
+ Run this file once and it will start watching and "re-run" once saved.
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/watch_import/__init__.py
5
+ src/watch_import/module.py
6
+ src/watch_import.egg-info/PKG-INFO
7
+ src/watch_import.egg-info/SOURCES.txt
8
+ src/watch_import.egg-info/dependency_links.txt
9
+ src/watch_import.egg-info/entry_points.txt
10
+ src/watch_import.egg-info/requires.txt
11
+ src/watch_import.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ watch_import = watch_import.module:watch_args
@@ -0,0 +1 @@
1
+ watchfiles
@@ -0,0 +1 @@
1
+ watch_import