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

Support scripts with inline script metadata as input files #2107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chrysle
Copy link
Contributor

@chrysle chrysle commented Jun 26, 2024

Closes #2027.

Contributor checklist
  • Included tests for the changes.
  • PR title is short, clear, and ready to be included in the user-facing changelog.
Maintainer checklist
  • Verified one of these labels is present: backwards incompatible, feature, enhancement, deprecation, bug, dependency, docs or skip-changelog as they determine changelog listing.
  • Assign the PR to an existing or new milestone for the target version (following Semantic Versioning).

@chrysle chrysle added the feature Request for a new feature label Jun 26, 2024
@chrysle chrysle added this to the 7.4.2 milestone Jun 26, 2024
@chrysle chrysle force-pushed the inline-script-metadata branch from 2f914a1 to 71d54de Compare June 26, 2024 19:08
@chrysle chrysle requested a review from webknjaz June 27, 2024 12:50
@chrysle
Copy link
Contributor Author

chrysle commented Jun 30, 2024

@webknjaz please review; there isn't any other active maintainer left, as it seems..

@WhyNotHugo
Copy link
Member

WhyNotHugo commented Jul 1, 2024

What's the use-case for this?

@chrysle
Copy link
Contributor Author

chrysle commented Jul 1, 2024

Hmm, suppose you have a Python script that has dependencies, is probably often in use and not part of a package with corresponding metadata; then setting up an environment fastly would be possible through this functionality.

@chrysle
Copy link
Contributor Author

chrysle commented Jul 3, 2024

@WhyNotHugo would you like to review this? We're really short on help ATM.

dedent(
"""
# /// script
# dependencies = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also have tests for extras?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there's no explicit extras in the spec. But how about requires-python?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how that would influence the build process?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should reject incompatible runtimes, for example.

@@ -43,6 +49,10 @@
DEFAULT_REQUIREMENTS_OUTPUT_FILE = "requirements.txt"
METADATA_FILENAMES = frozenset({"setup.py", "setup.cfg", "pyproject.toml"})

INLINE_SCRIPT_METADATA_REGEX = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using (?x) to be able to make this multiline with comments.

# piping from stdin, we need to briefly save the input from stdin
# to a temporary file and have pip read that. also used for
if src_file == "-" or (
os.path.basename(src_file).endswith(".py") and not is_setup_file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pathlib is usually nicer

Suggested change
os.path.basename(src_file).endswith(".py") and not is_setup_file
Path(src_file).suffix == ".py" and not is_setup_file

# reading requirements from install_requires in setup.py.
if os.path.basename(src_file).endswith(".py"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if os.path.basename(src_file).endswith(".py"):
if Path(src_file).suffix == ".py":

@webknjaz
Copy link
Member

webknjaz commented Jul 3, 2024

@chrysle sorry, I didn't have time lately. I'll try to come back for another review round during/after EuroPython.

@webknjaz webknjaz requested a review from WhyNotHugo December 16, 2024 04:17
@webknjaz webknjaz force-pushed the inline-script-metadata branch from 71d54de to 792e034 Compare December 16, 2024 04:19
@webknjaz
Copy link
Member

@chrysle I clicked “rebase” and it looks like there's some actionable feedback in the earlier comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement support for PEP 723 "Inline script metadata"
3 participants