AcademySoftwareFoundation / rez

An integrated package configuration, build and deployment system for software
https://rez.readthedocs.io
Apache License 2.0
932 stars 329 forks source link

Access to package.py path in early bind functions #1664

Closed cumulus-vfx closed 5 months ago

cumulus-vfx commented 6 months ago

Access to package.py file path in EarlyThis object

Motivation I'm attempting to create a package.py file for use in developer workflows, which would live in the git repo of the project, Its for a python library project and I would like the package.py to read in from the its requiments.txt in the root of the repo

Currently any relative paths are are anchored to my shell cwd and __file__ is not available Unless there another way to get the current package.py path, please let me know

My example using rez tools:

@early()
def requires():
    from rez.utils.pip import packaging_req_to_rez_req, normalize_requirement
    with open('requirements.txt') as f:
        lines = [str(l).rstrip() for l in f.readlines() if not l.startswith('#')]
    require = [
        packaging_req_to_rez_req(normalize_requirement(line)[0]).safe_str()
        for line in lines
    ]
    return require 

Proposed Solution I dont think this would be too much of an issue to facilitate, changing rez.serialise._load_py, it could set the attr package to have the filename var already in the function scope

So this.package will have /repo/package_name/package.py value

cumulus-vfx commented 5 months ago

Please ignore, some how I over looked the __file__ in the scope of the requires function