getsources 0.0.1__py3-none-any.whl

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.
getsources/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ from getsources.base import getsource as getsource
2
+ from getsources.clear import getclearsource as getclearsource
getsources/base.py ADDED
@@ -0,0 +1,11 @@
1
+ from inspect import getsource as original_getsource
2
+ from typing import Any, Callable
3
+
4
+ from dill.source import getsource as dill_getsource # type: ignore[import-untyped]
5
+
6
+
7
+ def getsource(function: Callable[..., Any]) -> str:
8
+ try:
9
+ return original_getsource(function)
10
+ except OSError: # pragma: no cover
11
+ return dill_getsource(function) # type: ignore[no-any-return]
getsources/clear.py ADDED
@@ -0,0 +1,20 @@
1
+ from typing import Any, Callable
2
+
3
+ from getsources import getsource
4
+
5
+
6
+ def getclearsource(function: Callable[..., Any]) -> str:
7
+ source_code = getsource(function)
8
+
9
+ splitted_source_code = source_code.split('\n')
10
+
11
+ indent = 0
12
+ for letter in splitted_source_code[0]: # pragma: no branch
13
+ if letter.isspace():
14
+ indent += 1
15
+ else:
16
+ break
17
+
18
+ new_splitted_source_code = [x[indent:] for x in splitted_source_code]
19
+
20
+ return '\n'.join(new_splitted_source_code).rstrip('\n')
getsources/py.typed ADDED
File without changes
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The Mutating Company
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.1
2
+ Name: getsources
3
+ Version: 0.0.1
4
+ Summary: A way to get the source code of functions
5
+ Author-email: Evgeniy Blinov <zheni-b@yandex.ru>
6
+ Project-URL: Source, https://github.com/mutating/getsources
7
+ Project-URL: Tracker, https://github.com/mutating/getsources/issues
8
+ Keywords: inspect
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Operating System :: MacOS :: MacOS X
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Classifier: Operating System :: POSIX
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Programming Language :: Python :: Free Threading
23
+ Classifier: Programming Language :: Python :: Free Threading :: 3 - Stable
24
+ Classifier: License :: OSI Approved :: MIT License
25
+ Classifier: Intended Audience :: Developers
26
+ Classifier: Topic :: Software Development :: Libraries
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: dill==0.4.0
31
+
32
+ <details>
33
+ <summary>ⓘ</summary>
34
+
35
+ [![Downloads](https://static.pepy.tech/badge/getsources/month)](https://pepy.tech/project/getsources)
36
+ [![Downloads](https://static.pepy.tech/badge/getsources)](https://pepy.tech/project/getsources)
37
+ [![Coverage Status](https://coveralls.io/repos/github/mutating/getsources/badge.svg?branch=main)](https://coveralls.io/github/mutating/getsources?branch=main)
38
+ [![Lines of code](https://sloc.xyz/github/mutating/getsources/?category=code)](https://github.com/boyter/scc/)
39
+ [![Hits-of-Code](https://hitsofcode.com/github/mutating/getsources?branch=main)](https://hitsofcode.com/github/mutating/getsources/view?branch=main)
40
+ [![Test-Package](https://github.com/mutating/getsources/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/mutating/getsources/actions/workflows/tests_and_coverage.yml)
41
+ [![Python versions](https://img.shields.io/pypi/pyversions/getsources.svg)](https://pypi.python.org/pypi/getsources)
42
+ [![PyPI version](https://badge.fury.io/py/getsources.svg)](https://badge.fury.io/py/getsources)
43
+ [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
44
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
45
+ [![DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/mutating/getsources)
46
+
47
+ </details>
48
+
49
+ ![logo](https://raw.githubusercontent.com/mutating/getsources/develop/docs/assets/logo_1.svg)
50
+
51
+
52
+ This library is needed to obtain the source code of functions at runtime. It can be used, for example, as a basis for libraries that work with [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) on the fly. In fact, it is a thin layer built around [`inspect.getsource`](https://docs.python.org/3/library/inspect.html#inspect.getsource) and [`dill.source.getsource`](https://dill.readthedocs.io/en/latest/dill.html#dill.source.getsource).
53
+
54
+
55
+ ## Installation
56
+
57
+ You can install [`getsources`](https://pypi.python.org/pypi/getsources) using pip:
58
+
59
+ ```bash
60
+ pip install getsources
61
+ ```
62
+
63
+ You can also quickly try out this and other packages without having to install using [instld](https://github.com/pomponchik/instld).
64
+
65
+
66
+ ## Usage
67
+
68
+ The basic function of the library is `getsource`, which works similarly to the function of the same name from the standard library:
69
+
70
+ ```python
71
+ from getsources import getsource
72
+
73
+ def function():
74
+ ...
75
+
76
+ print(getsource(function))
77
+ #> def function():
78
+ #> ...
79
+ ```
80
+
81
+ Unlike its counterpart from the standard library, this thing can also work:
82
+
83
+ - With lambda functions
84
+ - With functions defined inside REPL
85
+
86
+ We also often need to trim excess indentation from a function object to make it easier to further process the resulting code. To do this, use the `getclearsource` function:
87
+
88
+ ```python
89
+ from getsources import getclearsource
90
+
91
+ class SomeClass:
92
+ @staticmethod
93
+ def method():
94
+ ...
95
+
96
+ print(getclearsource(SomeClass.method))
97
+ #> def method():
98
+ #> ...
99
+ ```
100
+
101
+ As you can see, the resulting source code text has no extra indentation, but in all other respects this function is completely identical to the usual `getsource`.
@@ -0,0 +1,9 @@
1
+ getsources/__init__.py,sha256=Ko3yOyc8g7eVdHLu1hGx1Ie238rTohhu0KVYWIY5joc,113
2
+ getsources/base.py,sha256=x-gLU6aCksooM5ppySO2d2J79qa1GkK2_abf5hrHSsQ,388
3
+ getsources/clear.py,sha256=oatYIvj38kgd-vgMwdZ-ynVz9FYv3C4gyiX6h9ogKmk,517
4
+ getsources/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ getsources-0.0.1.dist-info/LICENSE,sha256=CgGm6IfD4q2LC7FBpn8bCauae9gfb1SZRdtaJ_X7dmk,1077
6
+ getsources-0.0.1.dist-info/METADATA,sha256=kFpFOUq-g3_J1o_-GoKyjPz1biYO2o4NeZO5Uv5IcYA,4491
7
+ getsources-0.0.1.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
8
+ getsources-0.0.1.dist-info/top_level.txt,sha256=etO6cCATcVRlw_B0TINeqoabyfrkdWgxkBKYOhaTvOw,11
9
+ getsources-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.46.3)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ getsources