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

replace git command use with dulwich #5428

Merged
merged 4 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
- name: Run pytest
run: poetry run python -m pytest -p no:sugar -q tests/

- name: Run pytest (integration suite)
run: poetry run python -m pytest -p no:sugar -q --integration tests/integration

- name: Get Plugin Version (poetry-plugin-export)
id: poetry-plugin-export-version
run: |
Expand Down
18 changes: 18 additions & 0 deletions docs/dependency-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ To use an SSH connection, for example in the case of private repositories, use t
requests = { git = "git@github.com:requests/requests.git" }
```

{{% note %}}
With Poetry 1.2 releases, the default git client used is [Dulwich](https://www.dulwich.io/). We
fall back to legacy system git client implementation in cases where [gitcredentials](https://git-scm.com/docs/gitcredentials)
are used. This fallback will be removed in a future release where username/password authentication
can be better supported natively.

In cases where you encounter issues with the default implementation that used to work prior to
Poetry 1.2, you may wish to explicitly configure the use of the system git client via a shell
subprocess call.

```bash
poetry config experimental.system-git-client true
```

Keep in mind however, that doing so will surface bugs that existed in versions prior to 1.2 which
were caused due to the use of the system git client.
{{% /note %}}

## `path` dependencies

To depend on a library located in a local directory or file,
Expand Down
49 changes: 45 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ tomlkit = ">=0.7.0,<1.0.0"
# exclude 20.4.5 - 20.4.6 due to /~https://github.com/pypa/pip/issues/9953
virtualenv = "(>=20.4.3,<20.4.5 || >=20.4.7)"
urllib3 = "^1.26.0"
dulwich = "^0.20.35"

[tool.poetry.dev-dependencies]
tox = "^3.18"
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Config:
"options": {"always-copy": False, "system-site-packages": False},
"prefer-active-python": False,
},
"experimental": {"new-installer": True},
"experimental": {"new-installer": True, "system-git-client": False},
"installer": {"parallel": True, "max-workers": None},
}

Expand Down Expand Up @@ -141,6 +141,7 @@ def _get_normalizer(name: str) -> Callable:
"virtualenvs.options.system-site-packages",
"virtualenvs.options.prefer-active-python",
"experimental.new-installer",
"experimental.system-git-client",
"installer.parallel",
}:
return boolean_normalizer
Expand Down
7 changes: 6 additions & 1 deletion src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,13 @@ def _parse_requirements(self, requirements: list[str]) -> list[dict[str, Any]]:
if extras:
pair["extras"] = extras

source_root = (
self.env.path.joinpath("src")
if isinstance(self, EnvCommand) and self.env
else None
)
package = Provider.get_package_from_vcs(
"git", url.url, rev=pair.get("rev")
"git", url=url.url, rev=pair.get("rev"), source_root=source_root
)
pair["name"] = package.name
result.append(pair)
Expand Down
23 changes: 7 additions & 16 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def _install_directory(self, operation: Install | Update) -> int:
return self.pip_install(req, upgrade=True)

def _install_git(self, operation: Install | Update) -> int:
from poetry.core.vcs import Git
from poetry.vcs.git import Git

package = operation.package
operation_message = self.get_operation_message(operation)
Expand All @@ -586,24 +586,15 @@ def _install_git(self, operation: Install | Update) -> int:
)
self._write(operation, message)

src_dir = self._env.path / "src" / package.name
if src_dir.exists():
remove_directory(src_dir, force=True)

src_dir.parent.mkdir(exist_ok=True)

git = Git()
git.clone(package.source_url, src_dir)

reference = package.source_resolved_reference
if not reference:
reference = package.source_reference

git.checkout(reference, src_dir)
source = Git.clone(
url=package.source_url,
source_root=self._env.path / "src",
revision=package.source_resolved_reference or package.source_reference,
)

# Now we just need to install from the source directory
original_url = package.source_url
package._source_url = str(src_dir)
package._source_url = str(source.path)

status_code = self._install_directory(operation)

Expand Down
10 changes: 8 additions & 2 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ def _do_refresh(self) -> int:
self._io,
)

ops = solver.solve(use_latest=[]).calculate_operations()
with solver.provider.use_source_root(
source_root=self._env.path.joinpath("src")
):
ops = solver.solve(use_latest=[]).calculate_operations()

local_repo = Repository()
self._populate_local_repo(local_repo, ops)
Expand Down Expand Up @@ -236,7 +239,10 @@ def _do_install(self, local_repo: Repository) -> int:
self._io,
)

ops = solver.solve(use_latest=self._whitelist).calculate_operations()
with solver.provider.use_source_root(
source_root=self._env.path.joinpath("src")
):
ops = solver.solve(use_latest=self._whitelist).calculate_operations()
else:
self._io.write_line("<info>Installing dependencies from lock file</>")

Expand Down
22 changes: 7 additions & 15 deletions src/poetry/installation/pip_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,27 +248,19 @@ def install_directory(self, package: Package) -> str | int:

def install_git(self, package: Package) -> None:
from poetry.core.packages.package import Package
from poetry.core.vcs.git import Git

src_dir = self._env.path / "src" / package.name
if src_dir.exists():
remove_directory(src_dir, force=True)
from poetry.vcs.git import Git

src_dir.parent.mkdir(exist_ok=True)

git = Git()
git.clone(package.source_url, src_dir)

reference = package.source_resolved_reference
if not reference:
reference = package.source_reference

git.checkout(reference, src_dir)
source = Git.clone(
url=package.source_url,
source_root=self._env.path / "src",
revision=package.source_resolved_reference or package.source_reference,
)

# Now we just need to install from the source directory
pkg = Package(package.name, package.version)
pkg._source_type = "directory"
pkg._source_url = str(src_dir)
pkg._source_url = str(source.path)
pkg.develop = package.develop

self.install_directory(pkg)
Loading