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

Support local wheel files in pip_install requirements.txt #366

Closed
aaliddell opened this issue Oct 2, 2020 · 2 comments · Fixed by #433
Closed

Support local wheel files in pip_install requirements.txt #366

aaliddell opened this issue Oct 2, 2020 · 2 comments · Fixed by #433
Assignees

Comments

@aaliddell
Copy link
Contributor

🚀 feature request

Relevant Rules

pip_install

Description

If you have a local .whl file in the workspace, you can add it to the requirements.txt file like so:

./path/to/wheel.whl
file:path/to/wheel.whl

Presently, this results in an error when attempting fetch the wheels, since pip is not running in the workspace root:

Traceback (most recent call last):                                                                                                                                                                                                                                             
  File "<snip>/external/pypi__pip/pip/_internal/cli/base_command.py", line 153, in _main                                                                                                         
    status = self.run(options, args)                                                                                                                                                                                                                                           
  File "<snip>/external/pypi__pip/pip/_internal/commands/wheel.py", line 158, in run                                                                                                             
    resolver.resolve(requirement_set)                                                                                                                                                                                                                                          
  File "<snip>/external/pypi__pip/pip/_internal/legacy_resolve.py", line 201, in resolve                                                                                                         
    self._resolve_one(requirement_set, req)                                                                                                                                                                                                                                    
  File "<snip>/external/pypi__pip/pip/_internal/legacy_resolve.py", line 365, in _resolve_one                                                                                                    
    abstract_dist = self._get_abstract_dist_for(req_to_install)                                                                                                                                                                                                                
  File "<snip>/external/pypi__pip/pip/_internal/legacy_resolve.py", line 313, in _get_abstract_dist_for                                                                                          
    req, self.session, self.finder, self.require_hashes                                                                                                                                                                                                                        
  File "<snip>/external/pypi__pip/pip/_internal/operations/prepare.py", line 194, in prepare_linked_requirement                                                                                  
    progress_bar=self.progress_bar                                                                                                                                                                                                                                             
  File "<snip>/external/pypi__pip/pip/_internal/download.py", line 452, in unpack_url                                                                                                            
    unpack_file_url(link, location, download_dir, hashes=hashes)                                                                                                                                                                                                               
  File "<snip>/external/pypi__pip/pip/_internal/download.py", line 398, in unpack_file_url                                                                                                       
    hashes.check_against_path(link_path)                                                                                                                                                                                                                                       
  File "<snip>/external/pypi__pip/pip/_internal/utils/hashes.py", line 104, in check_against_path                                                                                                
    with open(path, 'rb') as file:                                                                                                                                                                                                                                             
FileNotFoundError: [Errno 2] No such file or directory: '<snip>/<snip>-py3-none-any.whl'                                                                                                                                                                       
Traceback (most recent call last):                                                                                                                                                                                                                                             
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main                                                                                                                                                                                                   
    "__main__", mod_spec)                                                                                                                                                                                                                                                      
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code                                                                                                                                                                                                              
    exec(code, run_globals)                                                                                                                                                                                                                                                    
  File "<snip>/external/rules_python/python/pip_install/extract_wheels/__main__.py", line 5, in <module>                                                                                         
    main()                                                                                                                                                                                                                                                                     
  File "<snip>/external/rules_python/python/pip_install/extract_wheels/__init__.py", line 87, in main                                                                                            
    subprocess.run(pip_args, check=True)                                                                                                                                                                                                                                       
  File "/usr/local/lib/python3.7/subprocess.py", line 512, in run                                                                                                                                                                                                              
    output=stdout, stderr=stderr)                                                                                                                                                                                                                                              
subprocess.CalledProcessError: Command '['/usr/bin/python3.7', '-m', 'pip', 'wheel', '-r', '<snip>/requirements.txt']' returned non-zero exit status 2. 

Describe the solution you'd like

The extract_wheels script could convert relative wheel paths to absolute wheel paths prior to running pip wheel. It already has the full path to the requirements.txt file, so would just snip off the end and replace with relative path provided in requirements.txt.

Describe alternatives you've considered

  • Using whl_library, but this is not recommended and does not load dependencies of the local wheel.
  • Using absolute path in requirements.txt. This appears to work, but the path is not portable across different environments.
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

@github-actions github-actions bot added the Can Close? Will close in 30 days if there is no new activity label Apr 14, 2021
@aaliddell
Copy link
Contributor Author

Not stale, pending PR

@github-actions github-actions bot removed the Can Close? Will close in 30 days if there is no new activity label Apr 15, 2021
@thundergolfer thundergolfer self-assigned this May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants