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

Clarify error about taken port in serve; allow to open a browser #3498

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

oprypin
Copy link
Contributor

@oprypin oprypin commented Dec 2, 2023

  • Add a flag to override the serve port
  • Add diagnostics when mkdocs serve fails to bind a port

@oprypin

This comment was marked as outdated.

@oprypin
Copy link
Contributor Author

oprypin commented Dec 2, 2023

I dropped port randomization and trying multiple ports, compared to #3497. I think it can actually be too confusing.

@@ -248,7 +252,9 @@ def cli():


@cli.command(name="serve")
@click.option('-a', '--dev-addr', help=dev_addr_help, metavar='<IP:PORT>')
@click.option('-a', '--dev-addr', help=dev_addr_help, metavar='IP:PORT')
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

So, please don't get me wrong, but IMHO, this is not a very consistent design. You can specify a port via --dev-addr, but also via --port? That's two ways of achieving the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK what do you suggest?

Copy link
Sponsor Contributor

@squidfunk squidfunk Dec 3, 2023

Choose a reason for hiding this comment

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

Either remove --port or deprecate and split up --dev-addr into --host and --port. I'm not sure what you're aiming here for however, because --dev-addr is working perfectly fine.

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Also note that all of this might incentivize people to use the development server as a production server, because now you can only set the --port. --dev-addr carries dev in it, which I think was put there deliberately to keep people from using it in production. Still happens more often than one might think, as judging from issues I answered in the past.

Copy link
Sponsor Contributor

@pawamoy pawamoy Dec 4, 2023

Choose a reason for hiding this comment

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

I would find a -p option really convenient. I literally never change the default host, and if I had to, it would probably be in a container setup where I would set it to 0.0.0.0 and never change it again. Whereas in (rare) cases where I serve multiple sites, I need to change the port, and having to re-specify the default localhost is a bit annoying.

So I wouldn't mind if --dev-addr was deprecated in favor of two --host and --port options. However I'm not the only MkDocs user and I fear it would be quite disruptive to deprecate --dev-addr for, again, rarely happening situations. Maybe they could both (dev-addr and host+port) live together, forever, as mutually exclusive options? Or maybe --dev-addr could be modified so that we can pass either HOST:PORT, or just HOST, or just PORT? It looks like it's easy to distinguish the three cases?

`dev_addr` flag already covers this but is too inconvenient to use
Suggest the user to pick some other port - the suggested number seems random but is actually derived from the current site's name.
@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Dec 4, 2023

What happens if I permanently set the port to 8010 with serve_port: 8010 in the config file, and this port is already in use when I run mkdocs serve? Will I be able to override it with -p 8020 or -a 127.0.0.1:8020?

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Dec 4, 2023

I wonder if this really brings value. Choosing a different ports among different projects will be cumbersome, and will not play well with project templates. Also it caters to a (I'd say) small fraction of users who run multiple live-reload servers concurrently. And IMO is only useful when you also use -o to automatically open the tab in the browser. So many users will likely keep using 8000 by default. Besides, even if you permanently sets ports 8007, 8020, 8055 and 8080 on your projects, nothing guarantees that other projects you contribute to won't use the same ports. In that case you'll again fall back to overriding with -p. The first few ports (and the multiples of 10) will probably be over-used across all projects.

I feel like anything more than a default port plus a way to override it doesn't bring any real guarantee or benefit, and only increases cognitive overhead and/or maintenance work. I do note that this is an opt-in feature, so I won't push against it.

@oprypin
Copy link
Contributor Author

oprypin commented Dec 4, 2023

Yea the feature kinda falls apart easily. A compromise where nobody will bother trying to benefit from it

@squidfunk
Copy link
Sponsor Contributor

I wonder if this really brings value.

I feel that we're wasting our time discussing something that provides so little value as opposed to other open issues that would need more attention. This won't add any new functionality besides what's already achievable.

@oprypin
Copy link
Contributor Author

oprypin commented Dec 4, 2023

For you perhaps time is money. And for me, not spending time on one interesting issue doesn't mean I'll be more likely to spend time on another issue (actually often quite the opposite)

@fralau
Copy link

fralau commented Feb 25, 2024

For you perhaps time is money. And for me, not spending time on one interesting issue doesn't mean I'll be more likely to spend time on another issue (actually often quite the opposite)

That's a key point 🙂, for occasional or volunteer contributors. Both viewpoints exist and complement each other.

Of course, I am beating the drum for my own subjects of interest; though I can see and appreciate the other person's viewpoint.

I any case ifmkdocs could assume that the default host was localhost (mkdocs serve -a 8001), I would consider myself completely vindicated.

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.

With mkdocs serve switch to another port if the current port is busy
4 participants