Skip to content

Add docs on the main function, argv and return codes#470

Open
JeffersGlass wants to merge 1 commit intospylang:mainfrom
JeffersGlass:main-function
Open

Add docs on the main function, argv and return codes#470
JeffersGlass wants to merge 1 commit intospylang:mainfrom
JeffersGlass:main-function

Conversation

@JeffersGlass
Copy link
Copy Markdown
Contributor

Adds a documentation page for current info on the main function, and optionally providing command line arguments and return codes. Based on the work in #353 and elsewhere.

@kanin-kearpimy
Copy link
Copy Markdown
Contributor

Hello @JeffersGlass,

Thank you so much for this doc. Overall content is comprehensive. However, main() argument now supports both compiler and interpreter. So, we can compile code with main function arguments regarding #449.

```


## Passed Arguments (Interpretter Only)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
## Passed Arguments (Interpretter Only)
## Passed Arguments (Interpreter Only)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as @kanin-kearpimy already pointed out, the arguments works also on compiled mode now 🎉.

Maybe instead of "passed arguments" we can call this section "Accessing command line arguments"?


## Passed Arguments (Interpretter Only)

If the `main` function accepts a list of strings as an argument, the SPy program will accept arguments from the command line, both when running in interpretted
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
If the `main` function accepts a list of strings as an argument, the SPy program will accept arguments from the command line, both when running in interpretted
If the `main` function accepts a list of strings as an argument, the SPy program will accept arguments from the command line, both when running in interpreted

Seems the sentence is not finished?

Copy link
Copy Markdown
Member

@antocuni antocuni left a comment

Choose a reason for hiding this comment

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

Thank you @JeffersGlass!
I left some minor comments but overall looks good 💪

print("Hello world")
```

Not every `.spy` module needs a main function, but the module invoked by, e.g. `spy execute foo.spy` must contain a main function.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Not every `.spy` module needs a main function, but the module invoked by, e.g. `spy execute foo.spy` must contain a main function.
Not every `.spy` module needs a main function, but the module entry point invoked by, e.g. `spy foo.spy` or `spy build foo.spy` must contain a main function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a big more correct, but it become more nuanced, because e.g. spy build --target lib and spy build --target py-cffi do not require a main.

Maybe we can reword the section by starting this way:

The execution of a SPy program starts from a main function; you need a main if you try to run the interpreter (spy foo.spy) or to build an executable (spy build foo.spy). You don't need a main if you build a library (e.g. spy build --target lib foo.spy).

However, I don't fully like the wording. What do you think?

```


## Passed Arguments (Interpretter Only)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as @kanin-kearpimy already pointed out, the arguments works also on compiled mode now 🎉.

Maybe instead of "passed arguments" we can call this section "Accessing command line arguments"?

999
```

As with CPython, args[0] is the name of the string passed to the uv runtime:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably we should say that this is the equivalent of CPython's sys.argv


```py
#args.spy
def main(args: list[str]) -> None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should use argv as the canonical name, for consistency to CPython

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants