albertas / deadcode

Find and fix unused Python code using command line.
GNU Affero General Public License v3.0
76 stars 3 forks source link

Tag versions, add pre-commit example #16

Open Bouni opened 1 month ago

Bouni commented 1 month ago

Hi, nice project, I really like it!

A few things that should be added:

Tag versions as you release them

.pre-commit-config.yaml expects a rev which is either

Add an pre-commit-config.yaml example

  - repo: https://github.com/albertas/deadcode
    rev: 2706a6c1a4f3fd2d0c40daf066c681858cacd181
    hooks:
      - id: deadcode

As mentioned above, the rev should ideally be the tag of the released version. At the time of opening this issue that would be 2.4.0

Add a --version or -V argument

After installing its hard to figure out which version is installed.


Finally some questions 😄

I run deadcode.exe . locally and get: Well done! ✨ 🚀 ✨

pip freeze | grep deadcode
deadcode==2.4.0

If I add deadcode to my pre-commit-config.yaml like this

  - repo: https://github.com/albertas/deadcode
    rev: 2706a6c1a4f3fd2d0c40daf066c681858cacd181
    hooks:
      - id: deadcode

and run it manually with pre-commit, I get this:

deadcode.................................................................Failed
- hook id: deadcode
- exit code: 1

datamodel.py:11:0: DC03 Class `PartListDataModel` is never used
datamodel.py:50:8: DC05 Attribute `logger` is never used
datamodel.py:108:4: DC04 Method `SetValue` is never used
datamodel.py:148:4: DC04 Method `AddEntry` is never used
datamodel.py:162:4: DC04 Method `RemoveAll` is never used
datamodel.py:167:4: DC04 Method `get_all` is never used
datamodel.py:171:4: DC04 Method `get_reference` is never used
datamodel.py:175:4: DC04 Method `get_value` is never used
datamodel.py:179:4: DC04 Method `get_lcsc` is never used
datamodel.py:183:4: DC04 Method `get_footprint` is never used
datamodel.py:187:4: DC04 Method `select_alike` is never used
datamodel.py:196:4: DC04 Method `set_lcsc` is never used
datamodel.py:206:4: DC04 Method `remove_lcsc_number` is never used
datamodel.py:232:4: DC04 Method `toggle_bom_pos` is never used

The sha sum 2706a6c1a4f3fd2d0c40daf066c681858cacd181 is the one with the commit message "Bump version to 2.4.0". So I guess that should be the code released, right!? Why do they behave differently?

albertas commented 1 month ago

Thank you for your feedback! I appreciate your effort!

I have added --version option in 2.4.1 version and started using tags.

I will try to address remaining issues when I find a moment.

Bouni commented 3 weeks ago

I just tried but ran into another issue.

When I run deadcode.exe . from the terminal, everything works fine

grafik

But if I run the pre-commit hook I get a UnicodeEncodeError

deadcode.................................................................Failed
- hook id: deadcode
- exit code: 1

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\user\.cache\pre-commit\repoavu4w616\py_env-python3.12\Scripts\deadcode.EXE\__main__.py", line 7, in <module>
  File "C:\Users\user\.cache\pre-commit\repoavu4w616\py_env-python3.12\Lib\site-packages\deadcode\cli.py", line 41, in print_main
    if result := main():
                 ^^^^^^
  File "C:\Users\user\.cache\pre-commit\repoavu4w616\py_env-python3.12\Lib\site-packages\deadcode\cli.py", line 36, in main
    print('\033[1mWell done!\033[0m \u2728 \U0001f680 \u2728')
  File "C:\Users\user\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u2728' in position 19: character maps to <undefined>

I run Windows 11 + python 3.12

Do you have an idea what's the problem?