"""Rename audio files from metadata tags."""

import sys

from .args import fields, parse_args
from .batch import Batch
from .job import Job
from .message import job_info, stats

fields

__version__: str = '0.0.0'


def execute(*argv: str):
    """Main function

    :param list argv: The command line arguments specified as a list: e. g
        :code:`['--dry-run', '.']`
    """

    job = None

    try:
        args = parse_args(argv)
        job = Job(args)
        job.stats.counter.reset()
        job.stats.timer.start()
        if job.cli_output.job_info:
            job_info(job)
        if job.rename.dry_run:
            job.msg.output('Dry run')
        batch = Batch(job)
        batch.execute()
        job.stats.timer.stop()
        if job.cli_output.stats:
            stats(job)
    except KeyboardInterrupt:
        if job:
            job.stats.timer.stop()
            if job.cli_output.stats:
                stats(job)
        sys.exit(0)

"""Rename audio files from metadata tags."""

import sys
from importlib import metadata

from .args import fields, parse_args
from .batch import Batch
from .job import Job
from .message import job_info, stats

fields

__version__: str = metadata.version('audiorename')


def execute(*argv: str):
    """Main function

    :param list argv: The command line arguments specified as a list: e. g
        :code:`['--dry-run', '.']`
    """

    job = None

    try:
        args = parse_args(argv)
        job = Job(args)
        job.stats.counter.reset()
        job.stats.timer.start()
        if job.cli_output.job_info:
            job_info(job)
        if job.rename.dry_run:
            job.msg.output('Dry run')
        batch = Batch(job)
        batch.execute()
        job.stats.timer.stop()
        if job.cli_output.stats:
            stats(job)
    except KeyboardInterrupt:
        if job:
            job.stats.timer.stop()
            if job.cli_output.stats:
                stats(job)
        sys.exit(0)

Use the version number in pyproject.toml as the single source of truth
Use the version number in pyproject.toml as the single source of truth

From Python 3.8 on we can use importlib.metadata.version('package_name')
to get the current version.

  """Rename audio files from metadata tags."""
  
  import sys
+ from importlib import metadata
  
  from .args import fields, parse_args
  from .batch import Batch
  from .job import Job
  from .message import job_info, stats
  
  fields
  
- __version__: str = '0.0.0'
+ __version__: str = metadata.version('audiorename')
  
  
  def execute(*argv: str):
      """Main function
  
      :param list argv: The command line arguments specified as a list: e. g
          :code:`['--dry-run', '.']`
      """
  
      job = None
  
      try:
          args = parse_args(argv)
          job = Job(args)
          job.stats.counter.reset()
          job.stats.timer.start()
          if job.cli_output.job_info:
              job_info(job)
          if job.rename.dry_run:
              job.msg.output('Dry run')
          batch = Batch(job)
          batch.execute()
          job.stats.timer.stop()
          if job.cli_output.stats:
              stats(job)
      except KeyboardInterrupt:
          if job:
              job.stats.timer.stop()
              if job.cli_output.stats:
                  stats(job)
          sys.exit(0)
  
Use the version number in pyproject.toml as the single source of truth
## Code Before:
"""Rename audio files from metadata tags."""

import sys

from .args import fields, parse_args
from .batch import Batch
from .job import Job
from .message import job_info, stats

fields

__version__: str = '0.0.0'


def execute(*argv: str):
    """Main function

    :param list argv: The command line arguments specified as a list: e. g
        :code:`['--dry-run', '.']`
    """

    job = None

    try:
        args = parse_args(argv)
        job = Job(args)
        job.stats.counter.reset()
        job.stats.timer.start()
        if job.cli_output.job_info:
            job_info(job)
        if job.rename.dry_run:
            job.msg.output('Dry run')
        batch = Batch(job)
        batch.execute()
        job.stats.timer.stop()
        if job.cli_output.stats:
            stats(job)
    except KeyboardInterrupt:
        if job:
            job.stats.timer.stop()
            if job.cli_output.stats:
                stats(job)
        sys.exit(0)

## Instruction:
Use the version number in pyproject.toml as the single source of truth
## Code After:
"""Rename audio files from metadata tags."""

import sys
from importlib import metadata

from .args import fields, parse_args
from .batch import Batch
from .job import Job
from .message import job_info, stats

fields

__version__: str = metadata.version('audiorename')


def execute(*argv: str):
    """Main function

    :param list argv: The command line arguments specified as a list: e. g
        :code:`['--dry-run', '.']`
    """

    job = None

    try:
        args = parse_args(argv)
        job = Job(args)
        job.stats.counter.reset()
        job.stats.timer.start()
        if job.cli_output.job_info:
            job_info(job)
        if job.rename.dry_run:
            job.msg.output('Dry run')
        batch = Batch(job)
        batch.execute()
        job.stats.timer.stop()
        if job.cli_output.stats:
            stats(job)
    except KeyboardInterrupt:
        if job:
            job.stats.timer.stop()
            if job.cli_output.stats:
                stats(job)
        sys.exit(0)
