Skip to content

Commit

Permalink
Merge pull request #2 from Nikikuzi/remove-clean-py
Browse files Browse the repository at this point in the history
clean-py replaced with autoflake, isort and black
  • Loading branch information
Nikikuzi authored Oct 7, 2024
2 parents 78eaa24 + 65ecf81 commit 854b2b8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This document contains a quick overview of the functionalities, for more details

* [Code Generation](https://github.com/nikikuzi/graphql-dataclass/blob/develop/codegen/README.MD)

The package using [clean-py](https://github.com/samhardyhey/clean-py) library for generateed code formatting and also python 3 (3.10+) standard libraries.
The package using [autoflake](https://github.com/PyCQA/autoflake), [black](https://github.com/psf/black), [isort](https://github.com/pycqa/isort) libraries for generateed code formatting and also python 3 (3.10+) standard libraries.


## Usage in a nutshell
Expand Down
8 changes: 8 additions & 0 deletions RELEASE_NOTES.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# graphql-dataclass Release Update

## Release notes version: 1.0.5

Release date: Oct. 7, 2024

Changes

* clean-py replaced with autoflake, isort and black

## Release notes version: 1.0.0

Release date: Mar. 19, 2024
Expand Down
2 changes: 1 addition & 1 deletion codegen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@ def extract_schema_obj(arguments, verbose):
return None

if __name__ == '__main__':
print('graphql-dataclass code generator 1.0.0')
print('graphql-dataclass code generator 1.0.5')
main()
24 changes: 21 additions & 3 deletions codegen/src/printer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import contextlib
import pathlib
from os.path import join

from clean_py.clean_py import clean_python_code
import isort.parse
from autoflake import fix_code
from black import FileMode, DEFAULT_LINE_LENGTH, NothingChanged, format_file_contents

from .utils import get_valid_folder, to_snake_case, to_camel_case
from .consts import PY_EXTENSION, TYPE_REFS_NAME, ENUMS_NAME, MUTATIONS_NAME, QUERIES_NAME, SCALARS_NAME, \
Expand Down Expand Up @@ -106,9 +109,24 @@ def __clean_code(self, folder):
for name in os.listdir(folder):
# Open file
with open(os.path.join(folder, name)) as f:
fixed_file = clean_python_code(f.read())
formatted_source = fix_code(
f.read(),
expand_star_imports=True,
remove_all_unused_imports=True,
remove_duplicate_keys=True,
remove_unused_variables=True,
)
formatted_source = isort.code(formatted_source)

mode = FileMode(
line_length=DEFAULT_LINE_LENGTH,
is_pyi=False,
string_normalization=True,
)
with contextlib.suppress(NothingChanged):
formatted_source = format_file_contents(formatted_source, fast=True, mode=mode)
with open(os.path.join(folder, name), 'w') as f:
f.write(fixed_file)
f.write(formatted_source)

def __save_forward_reference(self, folder, create_forward_reference: bool):
if create_forward_reference:
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.MD"
keywords = ["python", "graphql", "mapping", "dataclass"]
license = { file = "LICENSE" }
requires-python = ">=3.10"
dependencies = ['anyio==3.1.0', 'clean-py==0.5']
dependencies = ['anyio==3.1.0', 'autoflake==2.3.1', 'black==24.8.0', 'isort==5.13.2']
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand All @@ -25,6 +25,6 @@ gqldataclass = "codegen.__main__:main"

[project.urls]
"Homepage" = "https://github.com/nikikuzi/graphql-dataclass/"
"Source Code" = "https://github.com/nikikuzi/graphql-dataclass/tree/1.0.0"
"Source Code" = "https://github.com/nikikuzi/graphql-dataclass/tree/1.0.5"
"Bug Tracker" = "https://github.com/nikikuzi/graphql-dataclass/issues"
"Release Notes" = "https://github.com/nikikuzi/graphql-dataclass/tree/1.0.0/RELEASE_NOTES.MD"
"Release Notes" = "https://github.com/nikikuzi/graphql-dataclass/tree/1.0.5/RELEASE_NOTES.MD"
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

setup(
name='gqldataclass',
version='1.0.4',
url='https://github.com/nikikuzi/graphql-dataclass/tree/1.0.0',
version='1.0.5',
url='https://github.com/nikikuzi/graphql-dataclass',
author='Mikita Kuzniatsou, Alex Dap',
author_email='[email protected], [email protected]',
description='A python library to generate dataclasses for GraphQL types',
Expand Down

0 comments on commit 854b2b8

Please sign in to comment.