Skip to content

Commit 6f83bdd

Browse files
committed
Add ability to update automatically version of generated wheels
Generate a patch number based on the date during generation Part of it/package-registry#2
1 parent 0c523e9 commit 6f83bdd

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/e3/python/pypiscript.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pkg_resources import Requirement
66
from e3.main import Main
77
from e3.fs import mkdir, cp
8+
from datetime import date
89
import argparse
910
import os
1011
import re
@@ -21,21 +22,29 @@
2122
wheels:
2223
name1: url1#branch1
2324
name2: url2
25+
update_wheel_version_file: true
2426
requirements:
2527
- "req1"
2628
- "req2"
2729
- "req3"
2830
discard_from_closure: "regexp"
2931
frozen_requirement_file: "requirements.txt"
32+
3033
platforms:
3134
- x86_64-linux
3235
- x86_64-windows
3336
- aarch64-linux
3437
35-
wheels contains the list of wheel that should be locally built
38+
wheels contains the optional list of wheel that should be locally built
3639
from source located at a git repository url (branch is specified after
3740
a #, if no branch is specified master is assumed
3841
42+
update_wheel_verison_file is an optional parameter to force version
43+
update during generation of the wheels based on sources. The update
44+
works only if the version is stored in a file called VERSION and the
45+
version in this file has MAJOR.MINOR format. In that case during
46+
generation the version is updated to MAJOR.MINOR.YYYYMMDD
47+
3948
requirements are additional python requirements as string
4049
4150
discard_from_closure are packages that should not be copied into the
@@ -87,6 +96,9 @@ def main() -> None:
8796
# First build the local wheels
8897
local_wheels = []
8998

99+
# Should we attempt to update VERSION files for wheels
100+
update_version_file = config.get("update_wheel_version_file", False)
101+
90102
for name, url in config.get("wheels", {}).items():
91103
logging.info(f"Fetch {name} sources")
92104
if "#" in url:
@@ -107,6 +119,24 @@ def main() -> None:
107119
if not m.args.skip_repo_updates:
108120
checkout_manager.update(vcs="git", url=url, revision=rev)
109121

122+
if update_version_file:
123+
# Try to update the version file for the given repository. Update
124+
# is one only if there is file called VERSION and that the version
125+
# has the format MAJOR.MINOR
126+
version_file = os.path.join(checkout_manager.working_dir, "VERSION")
127+
if os.path.isfile(version_file):
128+
with open(version_file) as fd:
129+
version = fd.read().strip()
130+
logging.info(f"Wheel {name} has version {version}")
131+
split_version = version.split(".")
132+
if len(split_version) == 2:
133+
# We have a major and minor but no patch so add it automatically
134+
version = f"{version}.{date.today().strftime('%Y%m%d')}"
135+
with open(version_file, "w") as fd:
136+
fd.write(version)
137+
138+
logging.info(f"Wheel {name} version updated to {version}")
139+
110140
local_wheels.append(
111141
Wheel.build(
112142
source_dir=checkout_manager.working_dir, dest_dir=wheel_cache_dir

0 commit comments

Comments
 (0)