Skip to content

Commit

Permalink
feat: Allow loading from multiple repos (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
janw authored Jan 30, 2024
1 parent 969e971 commit 05e37e6
Show file tree
Hide file tree
Showing 12 changed files with 446 additions and 13 deletions.
13 changes: 13 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
engines:
bandit:
enabled: true
checks:
assert_used:
enabled: false

checks:
argument-count:
enabled: false
method-complexity:
config:
threshold: 8
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: poetry install --no-root --with=tests --sync
run: poetry install --with=tests --sync

- name: Install poetry version under test
run: |
Expand Down
204 changes: 203 additions & 1 deletion poetry.lock

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

21 changes: 11 additions & 10 deletions poetry_homebrew_formula/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def handle(self) -> int:

self.line_error("<info>Generating formula</info>")
template = self.load_template()
self.repo = self.poetry.pool.repository("pypi")
package = self.project_with_activated_groups_only()
package_info = self.get_root_package_info(package)
resources = [self.get_package_info(dependency) for dependency in self.resolve_dependencies(package).packages]
Expand Down Expand Up @@ -101,16 +100,17 @@ def render_formula(
+ "\n"
)

if not (output := self.option("output")):
output = Path.cwd() / f"{package.name}.rb"
elif output == "-":
if (output := self.option("output")) == "-":
self.line("Writing template to stdout", verbosity=Verbosity.VERBOSE)
sys.stdout.write(formula)
return
if not output:
output = f"{package.name}.rb"

self.line(f"Writing template to {output}", verbosity=Verbosity.VERBOSE)
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text(formula)
output_path = Path(output)
self.line(f"Writing template to {output_path}", verbosity=Verbosity.VERBOSE)
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_text(formula)

def _render_resources(self, resources: list[PackageInfo]) -> str:
template = get_template(RESOURCES_TEMPLATE)
Expand Down Expand Up @@ -154,9 +154,10 @@ def get_root_package_info(self, package: Package) -> RootPackageInfo:
)

def pick_link(self, package: Package) -> Link:
for link in self.repo.find_links_for_package(package):
if link.is_sdist:
return link
for repo in self.poetry.pool.repositories:
for link in repo.find_links_for_package(package):
if link.is_sdist:
return link
raise RuntimeError(f"No valid link found for {package.name}. ")


Expand Down
1 change: 1 addition & 0 deletions poetry_homebrew_formula/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def list_templates(self) -> list[str]:
]
),
trim_blocks=True,
autoescape=False,
)


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mypy = "^1.8.0"
rich-codex = "^1.2.7"
commitizen = "^3.13.0"
pre-commit = "^3.6.0"
ipdb = "^0.13.13"

[tool.poetry.group.tests.dependencies]
pytest = "^7.4.4"
Expand Down
Loading

0 comments on commit 05e37e6

Please sign in to comment.