Is there a good way with python code in pants v2 t...
# general
l
Is there a good way with python code in pants v2 to get a path to the location of a dependency on disk? In our pre-pants code we have some stuff like
Copy code
STATICFILES_DIRS += (  # pylint: disable=undefined-variable
    os.path.join(
        os.environ['VIRTUAL_ENV'],
        'lib/python3.6/site-packages/django/contrib/admin/static',
    ),
that I need to port to pants
where VIRTUAL_ENV is set to the location where we create our virtualenv
h
Pants 2.9 adds an
export
goal that will write a virtualenv
Copy code
❯ ./pants export
17:37:06.81 [INFO] Completed: Building requirements.pex
17:37:07.04 [INFO] Completed: Create virtualenv
Wrote virtualenv for CPython==3.9.* to dist/export/python/virtualenv
Are you looking for something like that?
l
I would like to avoid that if possible.
i think the virtual_env might be a red herring here
i just want to be able to find the path to the location on-disk of a dependency
h
I believe that would look something like this:
Copy code
❯ ~/.cache/pants/named_caches/pex_root/installed_wheels/ff59bd9da4c781186fecb96e9717c458a98db032/types_PyYAML-5.4.3-py2.py3-none-any.whl/yaml-stubs/
METADATA.toml    cyaml.pyi        events.pyi       reader.pyi       serializer.pyi
__init__.pyi     dumper.pyi       loader.pyi       representer.pyi  tokens.pyi
composer.pyi     emitter.pyi      nodes.pyi        resolver.pyi
constructor.pyi  error.pyi        parser.pyi       scanner.pyi
l
this is to support collectstatic in django btw
👀 1
h
can you share more about how you're using collectstatic please?
l
so basically we have python dependencies which come bundled with static assets (js + css) which need to get collected and bundled with the rest of our static assets
in your django settings you can add a list of paths to
STATICFILES_DIRS
which will be searched by the
collectstatic
command
right now, with our virtualenv set up, the paths are predictable
maybe the inpsect module is what I want - https://docs.python.org/3/library/inspect.html
a
Copy code
import django
Path(django.__file__).parent/“contrib/admin/static”
?
🚀 1
But doesn’t Django do the STATICFILES_DIRS automatically when you add
django.contrib.admin
to your INSTALLED_APPS ?
h
cc @clean-city-64472 who knows more about Pants+Django than anyone
l
good question @ambitious-actor-36781
h
Echoing @ambitious-actor-36781, I'm surprised that you need the
STATICFILES_DIRS
hack pre-Pants.
In the Pants world, how would you want to run collectstatic. For example,
./pants run path/to/manage.py -- collectstatic
?
Is that what you had in mind? Or...
I think that should work for your first-party code's static files, since the CWD for
./pants run
is the repo root. And for 3rdparty stuff, I think Django does some magic based on relative paths from the app's code? I'd need to refresh my memory.
Yeah, memory refreshed. I'm not sure why you have that STATICFILES_DIRS hack. I would have expected all the standard built-in Django apps, including
django.contrib.admin
to have their static files under the
static
directory in the app
Which is collected by default
l
yeah maybe I can just remove this, could be really old code
found answer to why we need to do this in a comment:
Copy code
# We don't include AppDirectoriesFinder because we rely on gulp to collect all files.
h
I don't know what gulp is... brb doing some reading
l
something js related
I'm not sure I fully understand the process, but I just noting that we have a reason to updated STATICFILES_DIRS
h
Hmm the snippet you posted relates specifically to the staticfiles for the standard Django admin app, and I wouldn't have thought gulp was relevant to that?
c
I think gulp.js was used 5-10 years ago to basically just bundle a whole bunch of js and css in a single file.
1
l
yup
(and still used in some places....)
🙂 1