Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite other parts of the punch_version.py file #41

Open
tjanez opened this issue Aug 11, 2020 · 3 comments
Open

Don't overwrite other parts of the punch_version.py file #41

tjanez opened this issue Aug 11, 2020 · 3 comments

Comments

@tjanez
Copy link

tjanez commented Aug 11, 2020

Hey!

First of all, thanks for creating this great tool. I've been successfully using it for a while.

I have a small request, namely, to stop overwriting the whole punch_version.py file after performing a version bump.

The reason I would like this is that I would like to have a comment at the top of punch_version.py explaining what this file is and where to find more information since this file is usually in a repository's top-level directory and developers/users will frequently see it and wonder what it is and what it does.

Here is an example punch_version.py I would like to have (and retain after bumping):

# Punch version file.

# It contains the current version of the project.

# For more information, see: https://punch.readthedocs.io/.

major = 0
minor = 4
patch = 0

Full example/reproducer:

punch --version
cat << EOF > punch_config.py
# Punch configuration file.

# For more information, see: https://punch.readthedocs.io/.

__config_version__ = 1

GLOBALS = {
    'serializer': {
        'semver': '{{ major }}.{{ minor }}.{{ patch }}',
     }
}

# NOTE: The FILES list is not allowed to be empty, so we need to pass it at
# least a single valid file.
FILES = ["README.md"]

VERSION = ['major', 'minor', 'patch']

EOF
touch README.md
cat << EOF > punch_version.py
# Punch version file.

# It contains the current version of the project.

# For more information, see: https://punch.readthedocs.io/.

major = 0
minor = 4
patch = 0
EOF
punch --part minor
cat punch_version.py

And the output I get:

punch [tadej@toronto Punch]$ punch --version
Punch version 2.0.0
Copyright (C) 2016 Leonardo Giordani
This is free software, see the LICENSE file.
Source: https://github.com/lgiordani/punch
Documentation: http://punch.readthedocs.io/en/latest/
punch [tadej@toronto Punch]$ cat << EOF > punch_config.py
> # Punch configuration file.
> 
> # For more information, see: https://punch.readthedocs.io/.
> 
> __config_version__ = 1
> 
> GLOBALS = {
>     'serializer': {
>         'semver': '{{ major }}.{{ minor }}.{{ patch }}',
>      }
> }
> 
> # NOTE: The FILES list is not allowed to be empty, so we need to pass it at
> # least a single valid file.
> FILES = ["README.md"]
> 
> VERSION = ['major', 'minor', 'patch']
> 
> EOF
punch [tadej@toronto Punch]$ touch README.md
punch [tadej@toronto Punch]$ cat << EOF > punch_version.py
> # Punch version file.
> 
> # It contains the current version of the project.
> 
> # For more information, see: https://punch.readthedocs.io/.
> 
> major = 0
> minor = 4
> patch = 0
> EOF
punch [tadej@toronto Punch]$ punch --part minor
Warning: Cannot find any match for version {'major': 0, 'minor': 4, 'patch': 0} in file README.md
punch [tadej@toronto Punch]$ cat punch_version.py
major = 0
minor = 5
patch = 0
@lgiordani
Copy link
Owner

Hey @tjanez, thanks for using Punch. Your request makes a lot of sense to me, let me think about it, and I will add the feature

@tjanez
Copy link
Author

tjanez commented Aug 11, 2020

Hey @tjanez, thanks for using Punch. Your request makes a lot of sense to me, let me think about it, and I will add the feature

@lgiordani, thanks for such a quick response and thanks for considering this!

@lgiordani
Copy link
Owner

Hi @tjanez. I worked a bit on this request, and found out that it can't be easily implemented. The problem is that in Python you can't load a module, change it, and save it back to the disk. Indeed, the current way I use to create the file punch_version.py is

        with open(version_filepath, 'w') as f:
            for key, part in self.parts.items():
                f.write("{0} = {1}\n".format(key, repr(part.value)))

There might be a simple solution, though. I might add a configuration value that is the text content of the file punch_version.py, something like (punch_config.py)

HEADER = """
# Punch version file.

# It contains the current version of the project.

# For more information, see: https://punch.readthedocs.io/.
"""

and add that text to the file punch_version.py every time I recreate it. What do you think about this? It might solve your issue without requiring too much code. Let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants