CORE-GATECH-GROUP / serpent-tools

A suite of parsers designed to make interacting with SERPENT output files simple and flawless
http://serpent-tools.readthedocs.io/en/latest/
MIT License
52 stars 33 forks source link

ENH `version` defined multiple times #488

Closed rzehumat closed 1 year ago

rzehumat commented 1 year ago

Is your feature request related to a problem? Please describe. Defining one variable multiple times is bad for code maintainability (DRY principle). The version or __version__ is defined 3 or something times.

Of course, sometimes it is inevitable, but I think elegant solution exists here.

Describe the solution you'd like I would follow this StackOverflow idea. I did not get (yet) the idea about not defining version in code at all. Out of the suggested, point (1) looks like a natural solution to this, but there is the issue with minimal Python 3.8.

Describe alternatives you've considered

Additional context I could do a PR implementing it.

rzehumat commented 1 year ago

EDIT: using the versioneer tool is an alternative that implements the neither option

drewejohnson commented 1 year ago

@rzehumat agree, having the same thing defined in multiple places is burdensome. For a while, there weren't great tools to avoid this.

There are three primary places where it's defined and where it should be removed

  1. build config files (e.g., pyproject.toml, historically setup.py or setup.cfg)
  2. project module file serpentTools/__init__.py, and
  3. docs configuration file (docs/conf.py)

I've used versioneer in the past with good success, and lately am more partial to setuptools-scm, both of which grab version data based on commits and tags. seutptools-scm might provide the "neither" option of not having the package version as a settable attribute (fetching from package metadata instead) but I would need to investigate.

My preference would be the following

  1. setuptools-scm for handling determining version based off git history.
  2. serpentTools.__version__ is set based off some package metadata fetching routine, not a string attribute
  3. docs/conf.py imports serpentTools.__version__ for it's versioning needs

If you are able to pick this up. let me know. Otherwise I will try and get around to this after the next release