guilatrova / tryceratops

A linter to prevent exception handling antipatterns in Python (limited only for those who like dinosaurs).
MIT License
432 stars 26 forks source link

fix: Use 'tomli' package instead of 'toml' package. #70

Closed emcd closed 4 months ago

emcd commented 4 months ago

The 'toml' package breaks on valid 'pyproject.toml' files which prevents Tryceratops from being integrated properly.

The 'tomli' package provides TOML 1.0 and 'tomllib' compatibility. Had a similar patch accepted by the YAPF project in 2022.

Example of breakage with toml:

$ hatch --env develop run tryceratops
Traceback (most recent call last):
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/bin/tryceratops", line 8, in <module>
    sys.exit(main())
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/tryceratops/__main__.py", line 66, in main
    entrypoint(prog_name="tryceratops")
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/tryceratops/__main__.py", line 48, in entrypoint
    pyproj_config = load_config(dir)
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/tryceratops/files/discovery.py", line 118, in load_config
    config = toml.load(toml_file)
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/toml/decoder.py", line 134, in load
    return loads(ffile.read(), _dict, decoder)
  File "/home/me/.local/share/hatch/env/virtual/accretive/5On6b-gH/develop/lib/python3.8/site-packages/toml/decoder.py", line 362, in loads
    raise TomlDecodeError("Unterminated string found."
toml.decoder.TomlDecodeError: Unterminated string found. Reached end of file. (line 292 column 1 char 8542)

Successful run after switch to tomllib:

$ hatch --env develop run tryceratops
Done processing!
Nothing to check!
$ hatch --env develop run tryceratops sources
Done processing!
Processed 36 files
Everything clean!
$ hatch --env develop run pip freeze | grep tryceratops
tryceratops @ git+https://github.com/emcd/tryceratops@e1c57b6a1ea54b5b6e24b39bdfddb6b9d1ff51a4
guilatrova commented 4 months ago

@emcd Your PR looks good and feels ready to be merged. I just need to update/fix the GHA to ensure all tests are still passing (which I believe will be).

I'm planning on doing it later today, so expect a release today.