Skip to content

Conversation

@sohang3112
Copy link
Contributor

@sohang3112 sohang3112 commented Apr 20, 2025

Closes #7302 - make linguist recognize uv script as a python file.

Description

Add uv as a python interpreter in its yaml, and also a sample script for testing.
Now the sample uv script is successfully recognized as Python:

$ bundle exec github-linguist samples/Python/uv
samples/Python/uv: 2 lines (2 sloc)
  type:      Text
  mime type: text/plain
  language:  Python
(Additional) how I setup locally

Opened my fork in Github Codespaces and ran:

$ script/bootstrap
$ bundle install    # not sure if it's required
$ bundle exec github-linguist --breakdown    # NOTE: CONTRIBUTING.md said to run "bundle/github-linguist" but that one errored, this works instead

Checklist:

NOTE: I wasn't sure which one is applicable for this change. I have checked the one that seemed appropriate, but also left 2 other sections that may be appropriate - please help regarding this:

  • I am fixing a misclassified language

    • I have included a new sample for the misclassified language:
      • Sample source(s): added file and made it executable: chmod +x samples/Python/uv. Its contents are:
      #!/usr/bin/env -S uv run --script
      print("Hello World!")
    • I have included a change to the heuristics to distinguish my language from others using the same extension. - NOT APPLICABLE
  • I am changing the source of a syntax highlighting grammar

    • Old: [URL to grammar repo]
    • New: [URL to grammar repo]
  • I am adding new or changing current functionality

    • I have added or updated the tests for the new or changed functionality.

@sohang3112 sohang3112 requested a review from a team as a code owner April 20, 2025 14:48
@sohang3112
Copy link
Contributor Author

Didn't add any tests because there don't seem to be any existing tests for supported languages in tests/test_samples.rb.

@sohang3112
Copy link
Contributor Author

sohang3112 commented Apr 20, 2025

@lildude Added uv to python interpreters in languages.yaml based on your comment in the issue: #7302 (comment) . Please merge & approve this PR. Also the required Github test workflows are blocked as maintainer approval is required - please approve them so they can run.

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

We explicitly request real world samples and state ""Hello world" examples will not be accepted." in the CONTRIBUTING.md file. Please replace this sample with a real example and update the template accordingly.

@sohang3112
Copy link
Contributor Author

sohang3112 commented Apr 21, 2025

We explicitly request real world samples and state ""Hello world" examples will not be accepted."

@lildude If that's really the case, then why are there existing hello world type Python sample scripts?
For example, this is the contents of the file samples/Python/python:

#!/usr/bin/env python2.4
print "Python"

Anyway, I replaced the uv hello world sample script with this Countries of the World script that downloads countries' names, codes etc. from a Wikipedia table. The new script is at samples/Python/uv-download-countries-of-the-world - this is the result of running it:

$ ./uv-countries-of-the-world 
Reading inline script metadata from `./uv-countries-of-the-world`
Downloading table from wikipedia...
Countries of the World:
    Alpha-3 code     Description                     Other name(s) or older name(s)
0           NaN        Abkhazia  Republic of Abkhazia (official, English), Aphs...
1           AFG     Afghanistan  Islamic Emirate of Afghanistan (de facto offic...
2           ALB         Albania  Republic of Albania (official, English), Repub...
3           DZA         Algeria  People's Democratic Republic of Algeria (offic...
4           AND         Andorra  Principality of Andorra (official, English), P...
..          ...             ...                                                ...
3           VNM         Vietnam  Socialist Republic of Vietnam (official, Engli...
0           ESH  Western Sahara  Sahrawi Arab Democratic Republic (official, En...
0           YEM           Yemen  Republic of Yemen (official, English), ٱلْجُمْ...
0           ZMB          Zambia  Republic of Zambia (official, English), Northe...
1           ZWE        Zimbabwe  Republic of Zimbabwe (official, English), Rhod...

[201 rows x 3 columns]
Saved downloaded data to wikipedia_countries.csv

Please review & merge now - let me know if any further changes are required.

@sohang3112 sohang3112 requested a review from lildude April 21, 2025 07:16
Copy link
Contributor Author

@sohang3112 sohang3112 left a comment

Choose a reason for hiding this comment

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

As reviewer requested for more complex script than hello world, I have now replaced the uv hello world script with a script that downloads countries info from wikipedia table using pandas.

@lildude
Copy link
Member

lildude commented Apr 21, 2025

@lildude If that's really the case, then why are there existing hello world type Python sample scripts?

Because they pre-date the introduction of this requirement.

Copy link
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

Important

The changes in this PR will not appear on GitHub until the next release has been made and deployed. See here for more details.

@lildude lildude added this pull request to the merge queue Apr 21, 2025
Merged via the queue into github-linguist:main with commit 2351d9d Apr 21, 2025
5 checks passed
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Aug 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env uv shebang files not detected as python

2 participants