Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add: Jeremy's scripts activity #87
base: main
Are you sure you want to change the base?
Add: Jeremy's scripts activity #87
Changes from 1 commit
5798b60
5626235
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think actually getting to a level of comfort with this idea might take a few more examples, like 'say you have installed several python versions with pyenv, the shebang can indicate
python3.11
or etc. and like "what does that/usr/bin/env
do?" so maybe we link out to further info for this point?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? I am having trouble thinking of anything to say here that doesn't go down a long tangent about virtual environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya ya, i think this is a sort of a special case (i don't think i have ever used the shebang method except when i first started using python and didn't know how to make packages), so if it's proving troublesome i think safe to omit :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think myst is going to complain about two
#
headings in a single doc,could ToC structure be something like
or whatever order - i think that order has a nice build to it: "ok we are running single files, probably familiar, now we're running a file but it's a special file
__main__
(or__name__ == "__main__"
block), and now we're running a module anywhere in our shell" but up 2 u.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expanded on this a bit in next comment - this one on top-level topic organization, and next on organization within executing modules. I think it would be worth it to split out scripts/entrypoints into their own top-level section after
python -m module
and__main__.py
since they are sorta distinct concepts that build on each otherThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned this in a separate discussion about the executable lesson, but I originally saw this as two separate lessons, but I just drafted it as a single file. I though it was maybe too much to do all together. Also, the first section requires almost no other preliminary knowledge, while the second gains a lot by the audience at least already being familiar with packaging and package structure. It could instead be a single lesson, but I would structure it slightly differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up to you! always in favor of smaller chunks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split it all the way in my next draft.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this link work? is it a special
[][]
myst link or something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so... It was a reminder to me to come back and link to the first lesson after this was integrated into the existing lesson hierarchy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sentence and something like "that you can run from your shell anywhere, without needing to refer to the file specifically."
And then maybe a demo -
"that's how people make it possible to do things like this:
"
or something basic like that - they will have probably seen that before and maybe wondered how to do that, so i think a concrete example to let them know that "this is where we learn to do this cool thing" would be nice :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not sure what this means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scripts are not files in the repo's source. The
black
"command" is constructed and saved during install, it is part of the job of an installer to make these scripts. This is as opposed to keeping explicit scripts checked into the VCS (like abin/run_me
with a shebang) that some projects do. Some even include those scripts in the sdist/wheel; if they do, they also get installed into e.g. the venv and appear on PATH. But those are not "entrypoint scripts".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha that's what i figured you were referring to - i think this might be TMI for newbies :). it makes me think like "wait so should I not put this
.py
file in my repo? how will the tool know how to generate it for me if it's not there? when what you're referring to are the little autogenerated shim files that just call the script with shebang/etc.Might be another good one for an admonition box after explaining the concept of
[project.scripts]
kind of scripts - "try this: install your package in a virtual environment, and then open thevenv/bin/your_script
file - what the heck is that about!?!?!"i think it's important information (in the same way that i always tell anyone who wants to know what a virtual environment is to just read the
bin/activate
file (actually usually i parse it for them because there's really only two things you need to know but they're hidden in the shell script)) but might be a bit much in main text, and seems like it fits as a "if you want to know more" for the curious campers <3There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took this out for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was wondering where this was, ha :)
I think the flow might be a little clearer if we go
python file.py
python -m mypackage.myfile
initially with some loose calls at the module level, and then demonstrating why we might want to wrap those up in a function or put them in aif __name__ == "__main__":
block so they don't run when imported,__main__.py
file that takes the place of thatif __name__ == "__main__":
blockJust because I think introducing a new dunder file might take some motivating, like "why do i need this special file" and so introducing directly running a module file first gets you that motivation and also is a nice bridge from running a python script directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is actually part of what I am trying to teach here.
python -m
is not for single-file execution, it only works to execute (part of) a package. So you can't introduce-m
without__main__.py
plus a full intro to packaging (building, pyproject.toml, installing, ...). Also__main__.py
files typically don't have aif __name__ == "__main__":
because their purpose is only to be executed, not imported. (this is called out in the standard documentation).So this may need some reordering, but you seem to have dropped entrypoints in your suggetion, and merged
python file.py and
./file.py(very understandable). I do think that the
ifguard could maybe come first, as it is IME more common than
main.py`There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh ya ya this was just about the "this section" part, thinking of putting entrypoints after this.
The way i was thinking about this as far as like a train of thought in a lesson was like:
I have a python file
file.py
like this:first: i can call that function like
python file.py
Then I make a package like
second: now (if i have installed it), i can call my file like
python -m my_package.file
but wait! there is problem, what if we want to import our function and use it elsewhere? (introduce
if __name__ == "__main__"
) conceptBut wait! there's also a whole other special file for that
so third: if i move my
a_function()
call to__main__.py
, i can call my function likepython -m my_package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this a lot. I took most of this approach in my next draft.