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

Fix a few breaking changes in scripts #384

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
scripts/__pycache__/
tests/__pycache__/
debhelper-build-stamp
*.debhelper.log
Expand Down
13 changes: 10 additions & 3 deletions scripts/build-sync-wheels
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import subprocess
import tempfile
import shutil
import argparse
from pathlib import Path

import utils


if os.geteuid() == 0:
Expand Down Expand Up @@ -36,13 +39,12 @@ def main():
if "PKG_DIR" in os.environ and \
not any(arg.startswith("--pkg-dir") for arg in sys.argv):
sys.argv.extend(["--pkg-dir", os.environ["PKG_DIR"]])
sys.argv.extend(["--project", os.path.basename(os.environ["PKG_DIR"])])

parser = argparse.ArgumentParser(
description="Builds and stores sources and wheels"
)
parser.add_argument("--pkg-dir", help="Package directory", required=True)
parser.add_argument("--project", help="Project name to update", required=True)
parser.add_argument("--project", help="Project name to update")
parser.add_argument(
"--clobber", action="store_true", default=False,
help="Whether to overwrite wheels and source tarballs",
Expand All @@ -60,13 +62,18 @@ def main():
subprocess.check_call(cmd)
args.pkg_dir = git_clone_directory
else:
args.pkg_dir = os.path.expanduser(args.pkg_dir)
git_clone_directory = ""
if not os.path.exists(args.pkg_dir):
print(f"Project directory missing {args.pkg_dir}.")
sys.exit(1)

req_path = os.path.join(args.pkg_dir, args.requirements, "requirements.txt")
local_wheels = os.path.join(args.project, "wheels")
if args.project is not None:
project_name = args.project
else:
project_name = utils.project_name(Path(args.pkg_dir))
gonzalo-bulnes marked this conversation as resolved.
Show resolved Hide resolved
local_wheels = os.path.join(project_name, "wheels")

if not os.path.exists(req_path):
print("requirements.txt missing at {0}.".format(req_path))
Expand Down
13 changes: 9 additions & 4 deletions scripts/update-requirements
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,31 @@ import subprocess
from pathlib import Path
from typing import List

import utils


def parse_args():
# For backwards-compat
if "PKG_DIR" in os.environ and \
not any(arg.startswith("--pkg-dir") for arg in sys.argv):
sys.argv.extend(["--pkg-dir", os.environ["PKG_DIR"]])
sys.argv.extend(["--project", os.path.basename(os.environ["PKG_DIR"])])
parser = argparse.ArgumentParser(description="Update requirements files with sha256sums from our wheels")
parser.add_argument("--pkg-dir", help="Package directory", required=True)
parser.add_argument("--project", help="Project to update", required=True)
parser.add_argument("--project", help="Project to update")
parser.add_argument("--requirements", help="Directory that contains requirements.txt inside the package directory",
default="requirements")
return parser.parse_args()


def main():
args = parse_args()
pkg_dir = Path(args.pkg_dir)
pkg_dir = Path(args.pkg_dir).expanduser()
if args.project is not None:
project_name = args.project
else:
project_name = utils.project_name(pkg_dir)
requirements_file = pkg_dir / args.requirements / "requirements.txt"
project = Path(__file__).parent.parent / args.project
project = Path(__file__).parent.parent / project_name

# First remove index line and any PyQt or sip dependency
cleaned_lines = cleanup(requirements_file)
Expand Down
20 changes: 20 additions & 0 deletions scripts/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Shared functions between various scripts
"""
import re
from pathlib import Path

RE_NAME = re.compile(r'name="(.*?)"')


def project_name(path: Path) -> str:
"""Extract the project name from setup.py"""
setup_py = path / "setup.py"
if not setup_py.exists():
raise RuntimeError(f"No setup.py in {path}."
"If this isn't a Python project, use --project?")
search = RE_NAME.search(setup_py.read_text())
if not search:
raise RuntimeError(f"Unable to parse name out of {setup_py}. "
"If this isn't a Python project, use --project?")
return search.group(1)
2 changes: 2 additions & 0 deletions tests/test_update_requirements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import imp
import os
import sys
import pytest
from pathlib import Path

Expand All @@ -9,6 +10,7 @@
path_to_script = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "../scripts/update-requirements"
)
sys.path.append(os.path.dirname(path_to_script))
update_requirements = imp.load_source("update-requirements", path_to_script)

TEST_SOURCE_HASH = "8eb170f8d0d61825e09a95b38be068299ddeda82f35e96c3301a8a5e7604cb83"
Expand Down