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 stew build with local dependencies #54

Merged
merged 1 commit into from
Jul 16, 2024
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
29 changes: 24 additions & 5 deletions coveo_stew/offline_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from pathlib import Path
from tempfile import mkstemp
from typing import List, Optional, Pattern, Set
from typing import List, Optional, Set

from coveo_styles.styles import ExitWithFailure
from coveo_systools.platforms import WINDOWS
Expand All @@ -25,12 +25,13 @@
# looks like:
# - `coveo-stew @ file://home/jonapich/code/stew/coveo-stew; python ...` on linux
# - `coveo-stew @ file:///C:/Users/jonapich/code/stew/coveo-stew; python ...` on windows :shrug:
# - `-e file://path/to/coveo-stew; python ...` after an upstream breaking change (will be reformatted into the above)
if WINDOWS:
LOCAL_REQUIREMENT_PATTERN: Pattern = re.compile(
r"^(?P<library_name>.+) @ file:///(?P<path>.+);"
)
FILE_IDENTIFIER = "file:///"
else:
LOCAL_REQUIREMENT_PATTERN = re.compile(r"^(?P<library_name>.+) @ file://(?P<path>.+);")
FILE_IDENTIFIER = "file://"

LOCAL_REQUIREMENT_PATTERN = re.compile(rf"^(?P<library_name>.+) @ {FILE_IDENTIFIER}(?P<path>.+);")


def offline_publish(
Expand Down Expand Up @@ -112,6 +113,24 @@ def _store_dependencies_in_wheelhouse(self, project: Optional[PythonProject] = N

lines: List[str] = []
for requirement in project.export().splitlines():
if requirement.startswith("-e "):
# everything was going fine on poetry 1.8.3 then something started to break.
# `poetry export` changed the format of the local dependencies.
# e.g.:
# before: 'mock-pyproject-dependency @ file:///C:/path/to/mock-pyproject-dependency ; ...'
# now: '-e file:///C:/path/to/mock-pyproject-dependency ; ...'
requirements_part, _remainder_part = requirement.split(";", maxsplit=1)
# remove the `-e file:///` part
requirements_part = requirements_part[3 + len(FILE_IDENTIFIER) :].strip()
requirement_path = Path(requirements_part)
if not requirement_path.exists():
raise ExitWithFailure(
failures=f"Cannot find the local dependency {requirement_path}"
)
# reformat the line to what we used to expect before the breaking change
# let's hope the folder name == the package name 😅
requirement = f"{requirement_path.name} @ {FILE_IDENTIFIER}{requirement_path} ; {_remainder_part}"

if match := LOCAL_REQUIREMENT_PATTERN.match(requirement):
dependency_name, dependency_location = (
match["library_name"].strip(),
Expand Down
Loading