Files
fm-orchestrator/make-dist-tarball.py
Owen W. Taylor ad4927fd01 Add a script to check the dist tarball, and use it to fix the dist tarball
* Add a script make-dist-tarball.py that runs 'setup.py sdist' and compares
  what gets distributed with git and with a set of patterns of extra files
  added during distribution, and with git files that we don't want to
  distribute.

* Extend MANIFEST.in or add __init__.py files to distribute:

   run-unittests.sh
   tox.in
   conf/client_secrets.json
   tests/test_builder
   tests/integration

* Don't include all of module_build_service - this is too prone to backup
  files and development trash files; instead add just the files we need
  that aren't *.py

* Move global-excludes to the end - they modify the existing list of files;
  and add *.db - for some reason, .mbs_local_build.db files were
  getting disted.
2023-04-04 16:07:10 +00:00

105 lines
2.6 KiB
Python
Executable File

#!/usr/bin/python
from pathlib import Path
import re
import subprocess
import sys
if sys.stderr.isatty:
def info(*args):
print("\033[1m", file=sys.stderr, end="")
print(*args, file=sys.stderr, end="")
print("\033[0m", file=sys.stderr)
else:
def info(*args):
print(*args, file=sys.stderr)
def ignore_re(patterns):
return re.compile('^('
+ '|'.join(patterns.strip().split())
+ ')$')
# These are files that are generated as part of the distribution process
DIST_IGNORE_RE = ignore_re(r"""
module_build_service.egg-info/.*
setup.cfg
PKG-INFO
""")
# These files are in git, but we don't actually want to distribute them
GIT_IGNORE_RE = ignore_re(r"""
\.cico-pr.pipeline
\.dockerignore
\.gitignore
docker/.*
openshift/.*
make-dist-tarball.py
Vagrantfile
""")
# Find the version in setup.py, this determines the generated tarball name
version = None
with open("setup.py") as f:
for line in f:
m = re.match(r'\s*version\s*=\s*"([^"]+)', line)
if m:
version = m.group(1)
assert version, "Version not found in setup.py"
# Make the tarball
subprocess.check_call(['python3', 'setup.py', 'sdist'])
info("Checking distributed files")
# Read what files were included in the generated tarball, ignoring files
# based on DIST_IGNORE_RE
tarball = Path('dist') / f"module-build-service-{version}.tar.gz"
disted_files = set()
with subprocess.Popen(["tar", "tfz", tarball],
stdout=subprocess.PIPE, encoding="UTF-8") as p:
for line in p.stdout:
filename = re.sub(r'^module-build-service-[\d.]+/', '', line.strip())
if filename and not filename.endswith("/") and not DIST_IGNORE_RE.match(filename):
disted_files.add(filename)
# And what files are checked into git, ignoring files
# based on GIT_IGNORE_RE
git_files = set()
with subprocess.Popen(["git", "ls-tree", "-r", "--name-only", "HEAD"],
stdout=subprocess.PIPE, encoding="UTF-8") as p:
for line in p.stdout:
filename = line.strip()
if not GIT_IGNORE_RE.match(filename):
git_files.add(filename)
# Compare and tell the user about differences
disted_extra = disted_files - git_files
git_extra = git_files - disted_files
if not disted_extra and not git_extra:
info(tarball, "- OK")
else:
if disted_extra:
info("Extra distributed files")
for f in sorted(disted_extra):
print(' ', f, file=sys.stderr)
if git_extra:
info("Extra files in git, not distributed")
for f in sorted(git_extra):
print(' ', f, file=sys.stderr)
sys.exit(1)