types-remover 1.0.0__tar.gz → 1.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.
@@ -1,17 +1,15 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.2
2
2
  Name: types_remover
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: A small package that removes types from a file
5
+ Author-email: EasternFarmer <franek.banas1@gmail.com>
5
6
  Project-URL: Homepage, https://github.com/EasternFarmer/types_remover
6
7
  Project-URL: Issues, https://github.com/EasternFarmer/types_remover/issues
7
- Author-email: EasternFarmer <franek.banas1@gmail.com>
8
- License-Expression: GPL-3.0-or-later
9
- License-File: LICENSE
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
- Classifier: Operating System :: OS Independent
12
8
  Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
13
10
  Requires-Python: >=3.12
14
11
  Description-Content-Type: text/markdown
12
+ License-File: LICENSE
15
13
 
16
14
  # Types remover(s)
17
15
 
@@ -19,12 +17,12 @@ Description-Content-Type: text/markdown
19
17
 
20
18
 
21
19
  This packet has two available functions `remove_types_ast` and `remove_types_if`, that are doing almost the same thing
22
- with implementation. <br>
20
+ with different implementation. And one cmd command `remove-types` that uses argparse and `remove_types_ast`<br>
23
21
 
24
22
  From the tests I can tell you that `remove_types_ast` is on average 3,28 (average from 100 calls) times slower than
25
23
  `remove_types_if`
26
24
 
27
25
  ### IMPORTANT TO NOTE
28
26
 
29
- - The `remove_types_ast` function removes comments (not doc-strings)
30
- - Both functions turn multi-line data assignation into a one-line statement
27
+ - The `remove_types_ast` function and `remove-types` cmd command both remove comments (not doc-strings)
28
+ - Both functions turn multi-line data assignation into a one-line statement
@@ -4,12 +4,12 @@
4
4
 
5
5
 
6
6
  This packet has two available functions `remove_types_ast` and `remove_types_if`, that are doing almost the same thing
7
- with implementation. <br>
7
+ with different implementation. And one cmd command `remove-types` that uses argparse and `remove_types_ast`<br>
8
8
 
9
9
  From the tests I can tell you that `remove_types_ast` is on average 3,28 (average from 100 calls) times slower than
10
10
  `remove_types_if`
11
11
 
12
12
  ### IMPORTANT TO NOTE
13
13
 
14
- - The `remove_types_ast` function removes comments (not doc-strings)
14
+ - The `remove_types_ast` function and `remove-types` cmd command both remove comments (not doc-strings)
15
15
  - Both functions turn multi-line data assignation into a one-line statement
@@ -1,24 +1,26 @@
1
1
  [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "types_remover"
7
- version = "1.0.0"
7
+ version = "1.0.2"
8
8
  authors = [
9
9
  { name="EasternFarmer", email="franek.banas1@gmail.com" },
10
10
  ]
11
- license = "GPL-3.0-or-later"
11
+ #license = "GPL-3.0-or-later"
12
12
  description = "A small package that removes types from a file"
13
13
  readme = "README.md"
14
14
 
15
15
  requires-python = ">=3.12"
16
16
  classifiers = [
17
17
  "Programming Language :: Python :: 3",
18
- "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
19
18
  "Operating System :: OS Independent",
20
19
  ]
21
20
 
21
+ [project.scripts]
22
+ remove-types = "types_remover.cli:main"
23
+
22
24
  [project.urls]
23
25
  Homepage = "https://github.com/EasternFarmer/types_remover"
24
26
  Issues = "https://github.com/EasternFarmer/types_remover/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,32 @@
1
+ from typing import Optional, Literal
2
+
3
+ from ._types_remover_ast import remove_types_ast as remove_types_ast
4
+ from ._types_remover_if import remove_types as remove_types_if
5
+
6
+
7
+ __all__ = ['remove_types','remove_types_if', 'remove_types_ast']
8
+ __author__ = 'EasternFarmer'
9
+
10
+
11
+ def remove_types(
12
+ path: str,
13
+ *,
14
+ implementation: Literal['ast', 'if'] = 'ast',
15
+ return_str: bool = False,
16
+ output_file_path: Optional[str] = None
17
+ ) -> Optional[str]:
18
+
19
+ if implementation == 'ast':
20
+ return remove_types_ast(
21
+ path,
22
+ return_str = return_str,
23
+ output_file_path = output_file_path
24
+ )
25
+ elif implementation == 'if':
26
+ return remove_types_if(
27
+ path,
28
+ return_str = return_str,
29
+ output_file_path = output_file_path
30
+ )
31
+ else:
32
+ raise ValueError('Invalid implementation specified.')
@@ -1,24 +1,26 @@
1
1
  import ast
2
+ from typing import Optional
2
3
 
3
4
 
4
5
  class _DowngradeAnnAssign(ast.NodeTransformer):
5
6
  """Converts AnnAssign nodes (annotated assignment) to simpler Assign nodes."""
6
7
 
7
- def visit_AnnAssign(self, node: ast.AnnAssign) -> ast.Assign | None:
8
+ def visit_AnnAssign(self, node: ast.AnnAssign) -> Optional[ast.Assign]:
8
9
  if node.value is not None:
9
10
  return ast.Assign(targets = [node.target], value = node.value)
10
11
  return None # just so mypy can leave me alone
11
12
 
12
13
 
13
- def remove_types_ast(path: str, *, return_str: bool = False, output_file_path: str = 'output.py') -> None | str:
14
+ def remove_types_ast(path: str, *, return_str: bool = False, output_file_path: Optional[str] = None) -> Optional[str]:
14
15
  """
15
- Strips the types declared in the file at **path**
16
- Either one of return_str or output_file_path must be set
16
+ Strips the types declared in the file at **path** and outputs it to output_file_path
17
17
  :param path: Required parameter deciding what file to strip from types
18
- :param return_str: dictates if the function returns a str; can be mixed with output_file_path param
19
- :param output_file_path: dictates where the function saves the data; can be mixed with return_str param
18
+ :param return_str: dictates if the function returns a str
19
+ :param output_file_path: dictates where the function saves the data
20
20
  :return: str if return_str is True else None
21
21
  """
22
+ if output_file_path is None:
23
+ output_file_path = 'output.py'
22
24
 
23
25
  with open(path) as f:
24
26
  nodes = ast.parse(f.read())
@@ -35,8 +37,8 @@ def remove_types_ast(path: str, *, return_str: bool = False, output_file_path: s
35
37
  node.returns = None
36
38
  nodes = ast.fix_missing_locations(_DowngradeAnnAssign().visit(nodes))
37
39
 
38
- if return_str:
39
- return ast.unparse(nodes)
40
40
  with open(output_file_path, 'w') as f:
41
41
  f.writelines(ast.unparse(nodes))
42
+ if return_str:
43
+ return ast.unparse(nodes)
42
44
  return None # just so mypy can leave me alone
@@ -1,4 +1,5 @@
1
1
  import re
2
+ from typing import Optional
2
3
 
3
4
 
4
5
  def _parse_line(line: str) -> str | bool:
@@ -36,7 +37,17 @@ def _parse_def_statement(line: str) -> str:
36
37
  return f'{' ' * spaces}def {function_name}({', '.join(args2)}):'
37
38
 
38
39
 
39
- def remove_types(path: str, *, return_str: bool = False, output_file: str = 'output.py') -> None | str:
40
+ def remove_types(path: str, *, return_str: bool = False, output_file_path: Optional[str] = None) -> Optional[str]:
41
+ """
42
+ Strips the types declared in the file at **path** and outputs it to output_file_path
43
+ :param path: Required parameter deciding what file to strip from types
44
+ :param return_str: dictates if the function returns a str
45
+ :param output_file_path: dictates where the function saves the data. defaults to 'output.py'
46
+ :return: str if return_str is True else None
47
+ """
48
+ if output_file_path is None:
49
+ output_file_path = 'output.py'
50
+
40
51
  with open(path) as f:
41
52
  file = [line.rstrip('\n') for line in f.readlines()]
42
53
 
@@ -140,8 +151,8 @@ def remove_types(path: str, *, return_str: bool = False, output_file: str = 'out
140
151
  else: new_file.append(' ' * (len(tuple_line) - len(tuple_line.lstrip())) + ''.join(tuple_line.split()))
141
152
  tuple_line = ''
142
153
 
154
+ with open(output_file_path, 'w') as f:
155
+ f.writelines('\n'.join(new_file))
143
156
  if return_str:
144
157
  return '\n'.join(new_file)
145
- with open(output_file, 'w') as f:
146
- f.writelines('\n'.join(new_file))
147
158
  return None
@@ -0,0 +1,25 @@
1
+ """
2
+ The command-line interface for the ast version of the types remover
3
+ """
4
+ import argparse
5
+ from . import remove_types_ast
6
+
7
+
8
+ def main():
9
+ parser = argparse.ArgumentParser(
10
+ description="types remover"
11
+ )
12
+ parser.add_argument(
13
+ "path", type=str,
14
+ help="Path to a file that\' going to be stripped "
15
+ )
16
+ parser.add_argument(
17
+ "--output", "-o",
18
+ help="name of the output file. defaults to output.py"
19
+ )
20
+ args = parser.parse_args()
21
+ remove_types_ast(args.path, output_file_path=args.output)
22
+ print("types stripped successfully")
23
+
24
+ if __name__ == "__main__":
25
+ main()
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.2
2
+ Name: types_remover
3
+ Version: 1.0.2
4
+ Summary: A small package that removes types from a file
5
+ Author-email: EasternFarmer <franek.banas1@gmail.com>
6
+ Project-URL: Homepage, https://github.com/EasternFarmer/types_remover
7
+ Project-URL: Issues, https://github.com/EasternFarmer/types_remover/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+
14
+ # Types remover(s)
15
+
16
+ <!-- **My type removers I made taken from [The_Farmer_Was_Replaced](https://github.com/EasternFarmer/The-Farmer-Was-Replaced/) repo and updated as necessary** -->
17
+
18
+
19
+ This packet has two available functions `remove_types_ast` and `remove_types_if`, that are doing almost the same thing
20
+ with different implementation. And one cmd command `remove-types` that uses argparse and `remove_types_ast`<br>
21
+
22
+ From the tests I can tell you that `remove_types_ast` is on average 3,28 (average from 100 calls) times slower than
23
+ `remove_types_if`
24
+
25
+ ### IMPORTANT TO NOTE
26
+
27
+ - The `remove_types_ast` function and `remove-types` cmd command both remove comments (not doc-strings)
28
+ - Both functions turn multi-line data assignation into a one-line statement
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/types_remover/__init__.py
5
+ src/types_remover/_types_remover_ast.py
6
+ src/types_remover/_types_remover_if.py
7
+ src/types_remover/cli.py
8
+ src/types_remover.egg-info/PKG-INFO
9
+ src/types_remover.egg-info/SOURCES.txt
10
+ src/types_remover.egg-info/dependency_links.txt
11
+ src/types_remover.egg-info/entry_points.txt
12
+ src/types_remover.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ remove-types = types_remover.cli:main
@@ -0,0 +1 @@
1
+ types_remover
@@ -1,52 +0,0 @@
1
- name: Publish Python 🐍 distribution 📦 to PyPI
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- build:
10
- name: build
11
- runs-on: ubuntu-latest
12
-
13
- steps:
14
- - uses: actions/checkout@v4
15
- with:
16
- persist-credentials: false
17
- - name: Set up Python
18
- uses: actions/setup-python@v5
19
- with:
20
- python-version: "3.x"
21
- - name: Install pypa/build
22
- run: >-
23
- python3 -m
24
- pip install
25
- build
26
- --user
27
- - name: Build a binary wheel and a source tarball
28
- run: python3 -m build
29
- - name: Store the distribution packages
30
- uses: actions/upload-artifact@v4
31
- with:
32
- name: python-package-distributions
33
- path: dist/
34
- publish-to-pypi:
35
- name: >-
36
- publish-to-pypi
37
- needs:
38
- - build
39
- runs-on: ubuntu-latest
40
- environment:
41
- name: release
42
- url: https://pypi.org/p/types_remover
43
- permissions:
44
- id-token: write # IMPORTANT: mandatory for trusted publishing
45
- steps:
46
- - name: Download all the dists
47
- uses: actions/download-artifact@v4
48
- with:
49
- name: python-package-distributions
50
- path: dist/
51
- - name: Publish distribution 📦 to PyPI
52
- uses: pypa/gh-action-pypi-publish@v1.12.3
@@ -1,3 +0,0 @@
1
- .idea/
2
- dist/
3
- __pycache__/
@@ -1,6 +0,0 @@
1
- from ._types_remover_ast import remove_types_ast as remove_types_ast
2
- from ._types_remover_if import remove_types as remove_types_if
3
-
4
-
5
- __all__ = ['remove_types_if', 'remove_types_ast']
6
- __author__ = 'EasternFarmer'
File without changes