Skip to content

Commit

Permalink
refactor: deprecrate and use site package
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 11, 2024
1 parent d0a8cdf commit c846153
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions docs/userguides/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies:

When using the `pypi:` key, dependencies are downloaded and extracted from PyPI using an HTTP requests library.

You can also specify the `python:` key for already-installed dependencies:
You can also specify the `site_package:` key for already-installed dependencies:

```yaml
dependencies:
Expand All @@ -82,13 +82,13 @@ dependencies:
contracts_folder: .
```

Using `python:` requires the package to be installed in your `sys.path` (site-packages) folder, generally via `pip` or some other tool.
Using `site_package:` requires the package to be installed in your `sys.path` (site-packages) folder, generally via `pip` or some other tool.
The `contracts_folder` override, in this case, is often needed because the site-package does not have the root source-folder included.
Additionally, `python:` specified dependencies may also be lacking project-configuration files, such as the `ape-config.yaml`.
Additionally, `site_package:` specified dependencies may also be lacking project-configuration files, such as the `ape-config.yaml`.
Compilers such as `vyper` encourage users to use `pip` to publish and install smart-contract dependencies (other vyper files), but some features in Ape may be limited if the dependency is not also specified in your config somewhere.

If wanting to use a dependency from `PyPI`, we recommend using the `pypi:` key instead of the `python:` key.
However, the `python:` key works great if you already used `pip` to install the dependency, especially if the dependency is not available on `PyPI`.
If wanting to use a dependency from `PyPI`, we recommend using the `pypi:` key instead of the `site_package:` key.
However, the `site_package:` key works great if you already used `pip` to install the dependency, especially if the dependency is not available on `PyPI`.

### Local

Expand Down
13 changes: 9 additions & 4 deletions src/ape_pm/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def path(self) -> Optional[Path]:
# Is pypi: specified; has no special path.
return None

elif python := self.python:
elif python := self.site_package:
try:
return get_package_path(python)
except ValueError as err:
Expand All @@ -467,11 +467,16 @@ def path(self) -> Optional[Path]:

@property
def package_id(self) -> str:
if pkg_id := (self.pypi or self.python):
if pkg_id := (self.pypi or self.site_package):
return pkg_id

raise ProjectError("Must provide either 'pypi:' or 'python:' for python-base dependencies.")

@property
def python(self) -> str:
logger.warning("'.python' is deprecated. Please use 'site_package'.")
return self.site_package

@property
def version_id(self) -> str:
if self.pypi:
Expand All @@ -480,7 +485,7 @@ def version_id(self) -> str:
# I doubt this is a possible condition, but just in case.
raise ProjectError(f"Missing version from PyPI for package '{self.package_id}'.")

elif self.python:
elif self.site_package:
try:
vers = f"{metadata.version(self.package_id)}"
except metadata.PackageNotFoundError as err:
Expand All @@ -505,7 +510,7 @@ def uri(self) -> str:
if self.pypi:
return self.download_archive_url

elif self.python and (path := self.path):
elif self.site_package and (path := self.path):
# Local site-package path.
return path.as_uri()

Expand Down

0 comments on commit c846153

Please sign in to comment.