Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit94e645d

Browse files
authored
Merge pull requestadafruit#499 from dhalbert/2.x_frozen_module_version_info
Add git version info to frozen modules.
2 parentse44fbca +31be207 commit94e645d

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

‎.gitmodules‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@
2929
[submodule "frozen/Adafruit_CircuitPython_BusDevice"]
3030
path=frozen/Adafruit_CircuitPython_BusDevice
3131
url=https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git
32+
[submodule "tools/python-semver"]
33+
path=tools/python-semver
34+
url=https://github.com/k-bx/python-semver.git

‎py/mkenv.mk‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ endif
7070
MAKE_FROZEN =$(TOP)/tools/make-frozen.py
7171
MPY_CROSS =$(TOP)/mpy-cross/mpy-cross
7272
MPY_TOOL =$(TOP)/tools/mpy-tool.py
73+
PREPROCESS_FROZEN_MODULES = PYTHONPATH=$(TOP)/tools/python-semver$(TOP)/tools/preprocess_frozen_modules.py
7374

7475
all:
7576
.PHONY: all

‎py/mkrules.mk‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,13 @@ $(MPY_CROSS): $(TOP)/py/*.[ch] $(TOP)/mpy-cross/*.[ch] $(TOP)/windows/fmode.c
114114
$(Q)$(MAKE) -C$(TOP)/mpy-cross
115115

116116
# Copy all the modules and single python files to freeze to a common area, omitting top-level dirs (the repo names).
117-
#Remove anyconf.py (sphinx config) and setup.py (module install info) files, which are not meant to be frozen.
118-
#Also remove thelibraryexamples directory, so it won't be included.
117+
#Do anypreprocessing necessary: currently, this adds version information, removes examples, and
118+
#non-library.py files in the modules (setup.py and conf.py)
119119
# Then compile .mpy files from all the .py files, placing them in the same directories as the .py files.
120120
$(BUILD)/frozen_mpy:$(FROZEN_MPY_DIRS)
121121
$(ECHO) FREEZE$(FROZEN_MPY_DIRS)
122122
$(Q)$(MKDIR) -p$@
123-
$(Q)$(RSYNC) -rL --include="*/" --include='*.py' --exclude="*"$(addsuffix /*,$(FROZEN_MPY_DIRS))$@
124-
$(Q)$(RM) -rf$@/conf.py$@/setup.py$@/examples
123+
$(Q)$(PREPROCESS_FROZEN_MODULES) -o$@$(FROZEN_MPY_DIRS)
125124
$(Q)$(CD)$@&&\
126125
$(FIND) -L . -type f -name '*.py' | sed 's=^\./==' | \
127126
xargs -n1 $(abspath $(MPY_CROSS)) $(MPY_CROSS_FLAGS)

‎tools/preprocess_frozen_modules.py‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
importargparse
3+
importos
4+
importos.path
5+
frompathlibimportPath
6+
importsemver
7+
importsubprocess
8+
9+
# Compatible with Python 3.4 due to travis using trusty as default.
10+
11+
defversion_string(path=None,*,valid_semver=False):
12+
version=None
13+
try:
14+
tag=subprocess.check_output('git describe --tags --exact-match',shell=True,cwd=path)
15+
version=tag.strip().decode("utf-8","strict")
16+
exceptsubprocess.CalledProcessError:
17+
describe=subprocess.check_output("git describe --tags",shell=True,cwd=path)
18+
tag,additional_commits,commitish=describe.strip().decode("utf-8","strict").rsplit("-",maxsplit=2)
19+
commitish=commitish[1:]
20+
ifvalid_semver:
21+
version_info=semver.parse_version_info(tag)
22+
ifnotversion_info.prerelease:
23+
version=semver.bump_patch(tag)+"-alpha.0.plus."+additional_commits+"+"+commitish
24+
else:
25+
version=tag+".plus."+additional_commits+"+"+commitish
26+
else:
27+
version=commitish
28+
returnversion
29+
30+
# Visit all the .py files in topdir. Replace any __version__ = "0.0.0-auto.0" type of info
31+
# with actual version info derived from git.
32+
defcopy_and_process(in_dir,out_dir):
33+
forroot,subdirs,filesinos.walk(in_dir):
34+
35+
# Skip library examples directories.
36+
ifPath(root).name=='examples':
37+
continue
38+
39+
forfileinfiles:
40+
# Skip top-level setup.py (module install info) and conf.py (sphinx config),
41+
# which are not part of the library
42+
if (root==in_dir)andfilein ('conf.py','setup.py'):
43+
continue
44+
45+
input_file_path=Path(root,file)
46+
output_file_path=Path(out_dir,input_file_path.relative_to(in_dir))
47+
48+
iffile.endswith(".py"):
49+
ifnotoutput_file_path.parent.exists():
50+
output_file_path.parent.mkdir(parents=True)
51+
withinput_file_path.open("r")asinput,output_file_path.open("w")asoutput:
52+
forlineininput:
53+
ifline.startswith("__version__"):
54+
module_version=version_string(root,valid_semver=True)
55+
line=line.replace("0.0.0-auto.0",module_version)
56+
output.write(line)
57+
58+
if__name__=='__main__':
59+
argparser=argparse.ArgumentParser(description="""\
60+
Copy and pre-process .py files into output directory, before freezing.
61+
1. Remove top-level repo directory.
62+
2. Update __version__ info.
63+
3. Remove examples.
64+
4. Remove non-library setup.py and conf.py""")
65+
argparser.add_argument("in_dirs",metavar="input-dir",nargs="+",
66+
help="top-level code dirs (may be git repo dirs)")
67+
argparser.add_argument("-o","--out_dir",help="output directory")
68+
args=argparser.parse_args()
69+
70+
forin_dirinargs.in_dirs:
71+
copy_and_process(in_dir,args.out_dir)

‎tools/python-semver‎

Submodulepython-semver added at2001c62

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp