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

Add option for ~/.local directory #885

Closed
DUOLabs333 opened this issue Feb 4, 2022 · 16 comments · Fixed by #987
Closed

Add option for ~/.local directory #885

DUOLabs333 opened this issue Feb 4, 2022 · 16 comments · Fixed by #987
Labels
⭐ enhancement Improvements for existing features

Comments

@DUOLabs333
Copy link
Contributor

DUOLabs333 commented Feb 4, 2022

Is your feature request related to a problem? Please describe.

pdm has a -g option, to edit the "global" Python environment, eg. the one in /usr. However, there's no option for the local python environment, the one in ~/.local

Describe the solution you'd like

Maybe an option like --local or --user to act on that directory?

@DUOLabs333 DUOLabs333 added the ⭐ enhancement Improvements for existing features label Feb 4, 2022
@DUOLabs333
Copy link
Contributor Author

How does -g even work? ~/.pdm/global-project doesn't have anything that would point to /usr.

@frostming
Copy link
Collaborator

How does -g even work? ~/.pdm/global-project doesn't have anything that would point to /usr.

~/.pdm/global-project/.pdm.toml also stores the Python path, and the packages will be installed into the site-packages of the selected Python interpreter

@DUOLabs333
Copy link
Contributor Author

DUOLabs333 commented Mar 19, 2022

Is global-project special? I.e, can I make my own folder that will point to another site-packages?

@frostming
Copy link
Collaborator

frostming commented Mar 19, 2022

No you can point to another project dir by -gp <project_path>, where global-project is the default location when -p isn't given.

@DUOLabs333
Copy link
Contributor Author

How would I remove/add packages? Since they're not in the pyproject.toml it fails with does not exist in default dependencies.

@frostming
Copy link
Collaborator

How would I remove/add packages? Since they're not in the pyproject.toml it fails with does not exist in default dependencies.

If you agree the env should be kept in sync with pyproject.toml, then pdm sync -g --clean will remove all packages not needed.

@DUOLabs333
Copy link
Contributor Author

But that would remove all the packages already installed in site-packages.

@frostming
Copy link
Collaborator

That is the meaning of the existence of the global project: track all, not some packages installed in site-packages.
If there are any packages needed but not listed in pdm.lock, add them.

@DUOLabs333
Copy link
Contributor Author

So you are saying that pdm sync will just add all the packages in site-packages to global-project/pyproject.toml?

@DUOLabs333
Copy link
Contributor Author

Doing pdm sync -g gives me Lock file does not exist, nothing to install.

@frostming
Copy link
Collaborator

frostming commented Mar 22, 2022

So you are saying that pdm sync will just add all the packages in site-packages to global-project/pyproject.toml?

Sync is from pyproject.toml to site-packages and not reverse.

Doing pdm sync -g gives me Lock file does not exist, nothing to install.

Did you generate a lock file in the first place? Use pdm install -g to generate.

You seems to be taking -g as some kind of black magic, but it is just like a normal project, except that the packages are installed into the global site-packages, instead of the project level __pypackages__. All packages must be listed in pdm.lock, which is generated from pyproject.toml. Adding and removing packages must be via PDM. In this way the global site-packages are fully tracked and can be easily rebuilt from scratch, with a pair of pyproject.toml and pdm.lock files.

@DUOLabs333
Copy link
Contributor Author

Ok, so you are saying the point of --global is to add new packages to site-packages, not to manage old packages already there.

@frostming
Copy link
Collaborator

Yeah, you need to add them to pyproject.toml yourself if you want to manage the old packages

@DUOLabs333
Copy link
Contributor Author

Is there any way to import them in or do I really have to add them one by one? Maybe offer a pyproject.toml format?

@frostming
Copy link
Collaborator

frostming commented Mar 22, 2022

You only need to add top-level dependencies, run pdm list -g --graph to show the dependency tree, and add root nodes to pyproject.toml's dependencies array, each item is a PEP 508 requirement string. Take the example of pdm/pyproject.toml.

Answering such questions unpaid kills a lot of time and there are even no THANK words. You should consider to Sponsor this project, or just READ THE MANUAL please.

@DUOLabs333
Copy link
Contributor Author

DUOLabs333 commented Mar 22, 2022

I found a way to import the exact versions already installed -- make a new folder names test. pdm list -g --freeze > test/requirements.txt. cd test; pdm init. Then, copy the lock file into global-project. Maybe there should be a script for onboarding (I'm not sure how it would be completed) -g?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants