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

[WIP] Support add/remove dependency to the given project #318

Closed
wants to merge 4 commits into from

Conversation

ischaojie
Copy link
Contributor

@ischaojie ischaojie commented Jun 14, 2023

[WIP]

➜  o git:(main) ✗ rye show
project: o
path: /Users/zhezhezhu/projects/test/o
venv: /Users/zhezhezhu/projects/test/o/.venv
target python: 3.8
venv python: [email protected]
workspace: /Users/zhezhezhu/projects/test/o
  members:
    o (./)
    o1 (./o1)
    o2 (./o2)
➜  o git:(main) ✗ rye add black --project o1
Added black~=23.3.0 as regular dependency
➜  o git:(main) ✗ cat o1/pyproject.toml
[project]
name = "o1"
version = "0.1.0"
description = "Add a short description here"
authors = [
    { name = "Chaojie", email = "[email protected]" }
]
dependencies = [
    "black~=23.3.0",
]
......

if cmd.project.is_some() && pyproject_toml.is_workspace_root() {
let workspace = pyproject_toml.workspace().unwrap();
pyproject_toml = workspace.get_project(&cmd.project.unwrap())?.unwrap();
}
let py_ver = match pyproject_toml.target_python_version() {
Some(ver) => ver.format_simple(),
None => "".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I looked at it before for the --pyproject arg work:

Inside the requirement code in this same file, apply_to_requirement there is some logic about relative paths for path dependencies. That code uses the current working directory path as starting point. We might need to think about how that one should work together with this feature.

Copy link
Contributor Author

@ischaojie ischaojie Jun 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current messy way of adding local dependency is rooted in the limited support of pip-tools. I am looking for a proper way to make relative paths work properly. The main issue is that after adding dependencies for a specific project, lock and sync will fail due to the inability to find the path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw this PR #321, 👍

let mut pyproject_toml = PyProject::discover()?;
if cmd.project.is_some() && pyproject_toml.is_workspace_root() {
let workspace = pyproject_toml.workspace().unwrap();
pyproject_toml = workspace.get_project(&cmd.project.unwrap())?.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to write this using if let or match to avoid all or most of the unwraps. if let Some(project) = cmd.project etc avoids one, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@ischaojie ischaojie changed the title Support add dependency to the given project Support add/remove dependency to the given project Jun 17, 2023
@ischaojie ischaojie changed the title Support add/remove dependency to the given project [WIP] Support add/remove dependency to the given project Jun 17, 2023
@ischaojie
Copy link
Contributor Author

Since there are still many problems with adding local dependencies, I'll close this PR for now.

@ischaojie ischaojie closed this Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants