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

Add management command to download htmx #428

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

kytta
Copy link

@kytta kytta commented Mar 25, 2024

@kytta
Copy link
Author

kytta commented Mar 25, 2024

I feel like I've over-engineered some bits (like URL building), so feel free to strip out stuff you don't find useful :)

Copy link
Owner

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

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

Thanks for getting this started. I have some suggestions below.

Needs changelog note, tests, documentation, and a short section on using this within the example project in its README

@@ -0,0 +1,77 @@
from __future__ import annotations
Copy link
Owner

Choose a reason for hiding this comment

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

How about we call the management command htmx and have a subparser for the download subcommand, allowing the possibility of more in the future?

Copy link
Author

Choose a reason for hiding this comment

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

I have never considered Django management subcommands as I thought it's not idiomatic, but it doesn't sound like a bad idea at all!

Copy link
Author

Choose a reason for hiding this comment

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

Done in 5df5cba

Comment on lines 16 to 17
if TYPE_CHECKING:
from argparse import ArgumentParser
Copy link
Owner

Choose a reason for hiding this comment

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

Only use if TYPE_CHECKING to avoid circular imports or other issues, no need for plain imports

Suggested change
if TYPE_CHECKING:
from argparse import ArgumentParser
from argparse import ArgumentParser

Copy link
Author

Choose a reason for hiding this comment

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

Done in a91221b


class Command(BaseCommand):
help = "Download the given htmx version and the extensions."
requires_system_checks = [Tags.staticfiles]
Copy link
Owner

Choose a reason for hiding this comment

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

Why did you do this? Were you trying to speed up the checks ?

Suggested change
requires_system_checks = [Tags.staticfiles]

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking that since we use the STATICFILES_DIRS, it makes sense to at least check if the finders are configured correctly. But I agree with the other comment of yours about not having this default, so it's not needed after all

Copy link
Author

Choose a reason for hiding this comment

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

Done in 8a2a20e

"-d",
type=Path,
default=None,
help="where to download HTMX to. default: the first STATICFILES_DIR",
Copy link
Owner

Choose a reason for hiding this comment

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

I’d rather we didn’t have a default, every project has a different static layout.

Copy link
Author

Choose a reason for hiding this comment

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

Should the script just accept a target directory, then?

package_spec += f"@{options['version']}"

actual_version = options["version"]
for file in ["htmx.js", "ext/debug.js", "ext/event-header.js"]:
Copy link
Owner

Choose a reason for hiding this comment

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

Extensions should be selected by the user on the command line, not hardcoded. The previous script hardcoded these extensions as they’re used in the example app. Add a --ext option.

Copy link
Author

Choose a reason for hiding this comment

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

done in bd4cd29

with urlopen(url) as response:
if not actual_version:
actual_version = (
urlparse(response.geturl()).path.split("/")[1].split("@")[-1]
Copy link
Owner

Choose a reason for hiding this comment

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

too much on one line, split up and name the intermediate parts in variables

@adamchainz
Copy link
Owner

I found the original issue requesting the feature, #87, and edited your message to feature it.

def handle(self, *args: str, **options: Any) -> None:
dest_dir = options["dest"]
if dest_dir is None:
if len(settings.STATICFILES_DIRS) == 0:
Copy link
Owner

Choose a reason for hiding this comment

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

this setting isn’t guaranteed to exist, so we need to use getattr

@kytta
Copy link
Author

kytta commented Mar 25, 2024

Thanks for the initial review! I'll try to address this stuff tomorrow :)

@kryskool
Copy link

kryskool commented Apr 14, 2024

move to comment on the issue #87

actual_version = options["version"]
files = ["htmx.js"]
if options["ext"] is not None:
files += [f"ext/{extension}" for extension in options["ext"]]
Copy link
Author

Choose a reason for hiding this comment

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

I just noticed that htmx v2 does not include extensions in the NPM package. I need to investigate where to source them from

Copy link
Author

Choose a reason for hiding this comment

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

todo for me: think about how to define the new extensions to download, as just a name won't suffice...

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.

Management command for downloading HTMX
3 participants