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

ability to run r.js outside of a django project #28

Closed
sheppard opened this issue Nov 21, 2013 · 5 comments
Closed

ability to run r.js outside of a django project #28

sheppard opened this issue Nov 21, 2013 · 5 comments

Comments

@sheppard
Copy link

Just found this project, it looks pretty useful! What do you think about factoring out the Django dependency in a couple places so that one could run_optimizer() outside of a Django project? While I use Django pretty extensively, I have gotten in the habit of maintaining a strict modular separation between my client and server libraries, in part because there are a few projects where I can only use one or the other.

My build process already includes a call to execute r.js via subprocess but I'm interested in replacing it with yours (mostly so I can get some of your AutoEnvironment magic). To accomplish this without a major refactoring, I'm thinking of something like the following API:

os.environ['REQUIRE_SETTINGS'] = "app.require_settings"
from require import optimize
optimize()

Then LazySettings might get a bit lazier:

class LazySettings(object):
    @cached_property
    def config(self):
        if 'DJANGO_SETTINGS_MODULE' in os.environ:
            from django.conf import settings
            return settings
        else:
            return load_module(os.environ['REQUIRE_SETTINGS'])

    @property
    def REQUIRE_BASE_URL(self):
        return getattr(self.config, "REQUIRE_BASE_URL", "js")
# ...

TemporaryCompileEnvironment would probably need to move out of storage, and maybe have a non-temporary version that used whatever was in the build profile as directory paths. optimize() would just be a thin convenience wrapper to initialize and run a compile environment.

What do you think? I'm happy to submit a PR for this change, but I thought I'd run it by you first to see a.) if this feature would be useful to others and b.) if the above would be the right way to do it.

@etianen
Copy link
Owner

etianen commented Nov 21, 2013

To be honest, the whole point of django-require is that it's an integration
between Django's staticfiles framework, and RequireJS. Take out the Django
part, and it's just really RequireJS!

Also, the TemporaryCompileEnvironment isn't a nice way to do things. It's a
necessity to work with the Django post_process collectstatic stage, but if
you're not bound by Django's staticfiles conventions, there are vastly more
efficient ways to do it. Just compiling to your destination folder will be
faster, and how RequireJS wants to work.

That being said, if there are bits of django-require that you find useful,
please do go ahead and rip them out for your own purposes. I'm just not
sure that it's worth complicating the django-require codebase to make it
work outside of Django! :P

On 21 November 2013 05:03, S. Andrew Sheppard notifications@github.comwrote:

Just found this project, it looks pretty useful! What do you think about
factoring out the Django dependency in a couple places so that one could
run_optimizer() outside of a Django project? While I use Django pretty
extensively, I have gotten in the habit of maintaining a strict modular
separation between my client https://github.com/wq/wq.app and serverhttps://github.com/wq/wq.dblibraries, in part because there are a few projects where I can only use
one or the other.

My build processhttps://github.com/wq/wq.app/blob/master/util/compilers.pyalready includes a call to execute r.js via
subprocess but I'm interested in replacing it with yours (mostly so I can
get some of your AutoEnvironment magic). To accomplish this without a
major refactoring, I'm thinking of something like the following API:

os.environ['REQUIRE_SETTINGS'] = "app.require_settings"from require import optimizeoptimize()

Then LazySettings might get a bit lazier:

class LazySettings(object):
@cached_property
def config(self):
if 'DJANGO_SETTINGS_MODULE' in os.environ:
from django.conf import settings
return settings
else:
return load_module(os.environ['REQUIRE_SETTINGS'])

@property
def REQUIRE_BASE_URL(self):
    return getattr(self.config, "REQUIRE_BASE_URL", "js")# ...

TemporaryCompileEnvironment would probably need to move out of storage,
and maybe have a non-temporary version that used whatever was in the build
profile as directory paths. optimize() would just be a thin convenience
wrapper to initialize and run a compile environment.

What do you think? I'm happy to submit a PR for this change, but I thought
I'd run it by you first to see a.) if this feature would be useful to
others and b.) if the above would be the right way to do it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/28
.

@sheppard
Copy link
Author

Not a problem, it certainly makes sense to avoid overcomplicating django-require for this purpose. I'm glad I checked with you before getting too carried away...

I'll think a bit more about what a separate PyPI tool for executing r.js would look like and let you know what I come up with.

@etianen
Copy link
Owner

etianen commented Nov 21, 2013

I'd actually love to see it. Not all of my wbe projects use Django, but
most of them use RequireJS.

Keep me in the loop!

On 21 November 2013 15:31, S. Andrew Sheppard notifications@github.comwrote:

Not a problem, it certainly makes sense to avoid overcomplicating
django-require for this purpose. I'm glad I checked with you before getting
too carried away...

I'll think a bit more about what a separate PyPI tool for executing r.js
would look like and let you know what I come up with.


Reply to this email directly or view it on GitHubhttps://github.com//issues/28#issuecomment-28993661
.

@sheppard
Copy link
Author

Just following up on this - I've come up with a (relatively) pythonic solution for running RequireJS, based on PyMiniRacer. I just published an alpha version to PyPI.

Have a look here:
https://github.com/wq/python-requirejs

@etianen
Copy link
Owner

etianen commented Nov 15, 2017 via email

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

No branches or pull requests

2 participants