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

adding version.txt file #1293

Merged
merged 3 commits into from
Apr 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -18,19 +18,19 @@ def read(*names, **kwargs):


def _get_version():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 'BUILD_VERSION' in os.environ:
    version = os.environ('BUILD_VERSION')
else:
    with open(...) as f:
        version = f.readline().strip()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe if you want to do what you propose, you will need to handle the extra corner-cases of adding or not the sha which is done on line 35. So you might end up requiring a general code refactoring of this method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more concretely

def _get_version():
    try:
        cmd = ['git', 'rev-parse', 'HEAD']
        sha = subprocess.check_output(cmd, cwd=str(ROOT_DIR)).decode('ascii').strip()
    except Exception:
        sha = None

    if 'BUILD_VERSION' in os.environ:
        version = os.environ('BUILD_VERSION')
    else:
        with open(...) as f:
            version = f.readline().strip()
        if sha is not None:
            version += '+' + sha[:7]

    if sha is None:
        sha = 'Unknown'
    return version, sha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mthrok Thanks for suggestion, just to make sure this is just a refactoring of the code right? the end result is same except in once case we always end up reading the file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it is more for the readability / maintainability for the release process.
In fact, introducing version.txt forces us to define the version number in multiple sources, (env var / version.txt) but the release process is expecting environment variables, so IMHO the code logic better reflects the intention.

version = '0.10.0a0'
sha = None

try:
cmd = ['git', 'rev-parse', 'HEAD']
sha = subprocess.check_output(cmd, cwd=str(ROOT_DIR)).decode('ascii').strip()
except Exception:
pass

if os.getenv('BUILD_VERSION'):
version = os.getenv('BUILD_VERSION')
elif sha is not None:
version += '+' + sha[:7]
sha = None

if 'BUILD_VERSION' in os.environ:
version = os.environ['BUILD_VERSION']
else:
with open(os.path.join(ROOT_DIR, 'version.txt'), 'r') as f:
version = f.readline().strip()
if sha is not None:
version += '+' + sha[:7]

if sha is None:
sha = 'Unknown'
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.10.0a0