wonderful-iron-54019
08/18/2020, 4:02 PMpipenv_requirements build alias to source python requirements from pipenv using the PythonRequirements class as a model. its working like a charm. However, we've traditionally kept our Pipfile.lock file at the project root but, for ease of migration, i'd still like the build addresses for the requirements to go to 3rdparty/python:<req> is there a way i can use the _parse_context to get this to happen?wonderful-iron-54019
08/18/2020, 4:13 PMhundreds-father-404
08/18/2020, 5:34 PMHowever, we’ve traditionally kept our Pipfile.lock file at the project root but, for ease of migration, i’d still like the build addresses for the requirements to go to 3rdparty/python:<req> is there a way i can use theI would recommend that you perhaps ignore theto get this to happen?_parse_context
rel_path from the parse context and that you always look at the build root for the file. You would call your new macro in 3rdparty/python/BUILD, which would result in the new python_requirement_library targets that get generated from your macro being created there, in 3rdparty/python.
Rather than os.path.join(self._parse_context.rel_path, requirements_relpath), use get_buildroot() from pants.base.environment, so something like os.path.join(get_buildroot(), "Pipfile.lock")
You could also then make it more generic by having your macro take some parameter like path_from_buildroot.
relatedly, im not sure i understand the purpose the target defined here:Indeed, that target is being used so that invalidation works properly. Without adding a dependency on all the generated
python_requirement_library targets, Pants would not know that they’re invalidated upon changes to the Pipfile.
Previously, this dependency was expressed by creating a files() target. But, that resulted in the requirements.txt file showing up more than we wanted to, as it was included wherever else files() targets would be pulled in. So, Benjy created _python_requirement_library to better model the situation. Afaict, you can reuse that same target type, no need to add a new _pipfile_requirement_library or anything.wonderful-iron-54019
08/18/2020, 5:37 PMpipenv_requirements in 3rdparty/python and setting the rel to ../../Pipfile.lock with no issues.
Where the problem comes in is in defining the _python_requirement_library target since the sources fielld being passed is ['../../Pipfile.lock'] and PEX is not happy with thatwonderful-iron-54019
08/18/2020, 5:38 PMhundreds-father-404
08/18/2020, 5:39 PMos.path.join(get_buildroot(), "Pipfile.lock"), I think you’d had have an absolute path and Pex would be finewonderful-iron-54019
08/18/2020, 5:39 PMwonderful-iron-54019
08/18/2020, 5:41 PMwonderful-iron-54019
08/18/2020, 5:43 PMhundreds-father-404
08/18/2020, 5:43 PMso i think that may be a path forwardWhich part? The
get_buildroot() suggestion?wonderful-iron-54019
08/18/2020, 5:44 PMresolve_from_buildroot option on the build_alias be acceptable to toggle this behavior on and off?wonderful-iron-54019
08/18/2020, 5:44 PMhundreds-father-404
08/18/2020, 5:48 PMpython_requirements that the Pipfile.lock is a sibling file to where your BUILD file is.
For any new users, if they have a top-level Pipfile.lock, we would encourage them to use a top-level BUILD and specify reqs via //:my-req, rather than 3rdparty/python:req.
From there, though, the macro could have options like resolve_from_buildroot and/or requirements_relpath to do what you’re describing.wonderful-iron-54019
08/18/2020, 5:48 PMwonderful-iron-54019
08/18/2020, 5:49 PMwonderful-iron-54019
08/18/2020, 5:57 PMwonderful-iron-54019
08/18/2020, 7:39 PMresolve_from_buildroot and properly invalidatewonderful-iron-54019
08/18/2020, 7:40 PMUnmatched glob from 3rdparty/python:Pipfile.lock's sources field: "3rdparty/python/Pipfile.lock"hundreds-father-404
08/18/2020, 7:42 PM_python_requirements_file defined in the build root from a CAFO that gets called in 3rdparty/python/BUILD. He wants all the generated python_requirement_library targets to still be in 3rdparty/python, though.witty-crayon-22786
08/18/2020, 7:43 PMwitty-crayon-22786
08/18/2020, 7:44 PMwonderful-iron-54019
08/18/2020, 7:44 PMpython_requirement_library?witty-crayon-22786
08/18/2020, 7:44 PMhundreds-father-404
08/18/2020, 7:44 PM_python_requirements_file target in your top level BUILD for Pipfile.lock. Check that in. Then, in your macro, have it declare an explicit dependency on //:pipfile for every generated python_requirement_library.wonderful-iron-54019
08/18/2020, 7:44 PMhundreds-father-404
08/18/2020, 7:44 PMwonderful-iron-54019
08/18/2020, 7:45 PMwonderful-iron-54019
08/18/2020, 7:45 PMwonderful-iron-54019
08/18/2020, 7:46 PM3rdparty construction but Pipfile's just 'make sense' in the root especially if you plan to run things off pantswonderful-iron-54019
08/18/2020, 7:46 PMhundreds-father-404
08/18/2020, 7:46 PMpipfile_target: Optional[str]. If unset, then generate the _python_requirement_library in the same directory as the macro. Otherwise, use the provided explicit dep.
This does leak far more than the original design, but is somewhat general.wonderful-iron-54019
08/18/2020, 7:46 PMwonderful-iron-54019
08/19/2020, 2:52 PM