-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
feat: added option to generate basic ape-config.yaml
file if [tool.ape.plugins]
property is specified inside pyproject.toml file [APE-1312]
#1618
Closed
Aviksaikat
wants to merge
16
commits into
ApeWorX:main
from
Aviksaikat:feat/pyproject.toml-based-ape-configuration
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d361b1b
feat: added option to generate basic ape-config.yaml file if [tool.ap…
Aviksaikat d6beda0
Merge branch 'main' into feat/pyproject.toml-based-ape-configuration
Aviksaikat e48fece
fix: issues causing dev messages from working on vyper 0.3.9 [APE-132…
antazoey c656b30
Merge branch 'ApeWorX:main' into feat/pyproject.toml-based-ape-config…
Aviksaikat ceeb7e1
feat: show plugin name in log messages [APE-1327] (#1628)
antazoey bd6cf06
Update networks.md (#1629)
0xJchen 66703f0
fix: attempt fixing geth install [APE-1333] (#1634)
antazoey 0e584b3
fix: pluggy (#1633)
antazoey 6c58d7e
fix: weird type error (#1631)
antazoey e70f92a
Merge branch 'ApeWorX:main' into feat/pyproject.toml-based-ape-config…
Aviksaikat b7f22e4
removed vanilla file read to tomli to read toml files & updated as pe…
Aviksaikat 137a912
Merge branch 'main' into feat/pyproject.toml-based-ape-configuration
antazoey 6a027e4
import fixed & mypy erros fixed
Aviksaikat 45630ba
black formatted
Aviksaikat dccabf4
Update setup.py
Aviksaikat 1073fef
setup.py dependency fixed
Aviksaikat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,47 @@ | ||
import shutil | ||
from pathlib import Path | ||
from typing import List | ||
|
||
import click | ||
|
||
from ape.cli import ape_cli_context | ||
from ape.utils import github_client | ||
|
||
try: | ||
import tomllib # type: ignore[import] | ||
# backwards compatibility | ||
except ModuleNotFoundError: | ||
import tomli as tomllib | ||
|
||
|
||
def read_dependencies_from_toml(file_path, cli_ctx) -> List[str]: | ||
|
||
with open("./pyproject.toml", "rb") as file: | ||
try: | ||
data = tomllib.load(file) | ||
except FileNotFoundError: | ||
cli_ctx.logger.warning( | ||
f"Unable to populate contnets from pyproject.toml file. {file_path} doesn't exists." | ||
) | ||
|
||
except tomllib.TOMLDecodeError: | ||
cli_ctx.logger.warning(f"Error reading {file_path} file.") | ||
|
||
# Extract the 'tool.poetry.dependencies' section | ||
dependencies = data.get("tool", {}).get("poetry", {}).get("dependencies", {}) | ||
|
||
# Check each dependency to see if it starts with 'ape-', because we know these are the ape plugins | ||
ape_plugins = [dep[4:] for dep in dependencies if dep.startswith("ape-")] | ||
|
||
return ape_plugins | ||
|
||
|
||
def write_ape_config_yml(dependencies: List[str], file_to_write: Path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of writing an ape file, the ConfigManager should read the values from the pyproject.toml and treat it the same as if the config file had existed. There is not reason to configure twice, even if one is auto-generated. |
||
dependency_text = "plugins:\n" + "\n".join( | ||
[f" - name: {dependency}" for dependency in dependencies] | ||
) | ||
file_to_write.write_text(dependency_text) | ||
|
||
|
||
@click.command(short_help="Initalize an ape project") | ||
@ape_cli_context() | ||
|
@@ -53,9 +89,17 @@ def cli(cli_ctx, github): | |
git_ignore_path.write_text(body.lstrip()) | ||
|
||
ape_config = project_folder / "ape-config.yaml" | ||
if ape_config.exists(): | ||
if ape_config.is_file(): | ||
cli_ctx.logger.warning(f"'{ape_config}' exists") | ||
else: | ||
project_name = click.prompt("Please enter project name") | ||
ape_config.write_text(f"name: {project_name}\n") | ||
cli_ctx.logger.success(f"{project_name} is written in ape-config.yaml") | ||
|
||
pyproject_toml = project_folder / "pyproject.toml" | ||
if pyproject_toml.is_file(): | ||
dependencies = read_dependencies_from_toml(pyproject_toml, cli_ctx) | ||
write_ape_config_yml(dependencies, ape_config) | ||
cli_ctx.logger.success( | ||
f"Generated {ape_config} based on the currect pyproject.toml file" | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should all happen in the config manage, not in ape-init plugin.
And then you can use the project_manager.path as the base here instead of cwd