Skip to content

Commit

Permalink
Change default_pin_latest to default_alias_single_version
Browse files Browse the repository at this point in the history
  • Loading branch information
jvolkman committed May 2, 2022
1 parent 77f7dad commit 7131b4c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
24 changes: 22 additions & 2 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Public API re-exports

<pre>
pycross_lock_file(<a href="#pycross_lock_file-name">name</a>, <a href="#pycross_lock_file-always_build_packages">always_build_packages</a>, <a href="#pycross_lock_file-build_prefix">build_prefix</a>, <a href="#pycross_lock_file-build_target_overrides">build_target_overrides</a>,
<a href="#pycross_lock_file-default_pin_latest">default_pin_latest</a>, <a href="#pycross_lock_file-environment_prefix">environment_prefix</a>, <a href="#pycross_lock_file-file_url_overrides">file_url_overrides</a>, <a href="#pycross_lock_file-local_wheels">local_wheels</a>,
<a href="#pycross_lock_file-default_alias_single_version">default_alias_single_version</a>, <a href="#pycross_lock_file-environment_prefix">environment_prefix</a>, <a href="#pycross_lock_file-file_url_overrides">file_url_overrides</a>, <a href="#pycross_lock_file-local_wheels">local_wheels</a>,
<a href="#pycross_lock_file-lock_model_file">lock_model_file</a>, <a href="#pycross_lock_file-out">out</a>, <a href="#pycross_lock_file-package_prefix">package_prefix</a>, <a href="#pycross_lock_file-remote_wheels">remote_wheels</a>, <a href="#pycross_lock_file-repo_prefix">repo_prefix</a>,
<a href="#pycross_lock_file-target_environments">target_environments</a>)
</pre>
Expand All @@ -24,7 +24,7 @@ pycross_lock_file(<a href="#pycross_lock_file-name">name</a>, <a href="#pycross_
| <a id="pycross_lock_file-always_build_packages"></a>always_build_packages | A list of package keys (name-version) to always build from source. | List of strings | optional | [] |
| <a id="pycross_lock_file-build_prefix"></a>build_prefix | An optional prefix to apply to package build targets. Defaults to _build | String | optional | "_build" |
| <a id="pycross_lock_file-build_target_overrides"></a>build_target_overrides | A mapping of package keys (name-version) to existing pycross_wheel_build build targets. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="pycross_lock_file-default_pin_latest"></a>default_pin_latest | Generate aliases for the latest versions of packages not covered by the lock model's pins. | Boolean | optional | False |
| <a id="pycross_lock_file-default_alias_single_version"></a>default_alias_single_version | Generate aliases for all packages that have a single version in the lock file. | Boolean | optional | False |
| <a id="pycross_lock_file-environment_prefix"></a>environment_prefix | An optional prefix to apply to environment targets. Defaults to _env | String | optional | "_env" |
| <a id="pycross_lock_file-file_url_overrides"></a>file_url_overrides | An optional mapping of wheel or sdist filenames to their URLs. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="pycross_lock_file-local_wheels"></a>local_wheels | A list of wheel files. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
Expand All @@ -36,6 +36,26 @@ pycross_lock_file(<a href="#pycross_lock_file-name">name</a>, <a href="#pycross_
| <a id="pycross_lock_file-target_environments"></a>target_environments | A list of pycross_target_environment labels. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |


<a id="#pycross_lock_repo"></a>

## pycross_lock_repo

<pre>
pycross_lock_repo(<a href="#pycross_lock_repo-name">name</a>, <a href="#pycross_lock_repo-lock_file">lock_file</a>, <a href="#pycross_lock_repo-repo_mapping">repo_mapping</a>)
</pre>



**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="pycross_lock_repo-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="pycross_lock_repo-lock_file"></a>lock_file | The generated bzl lock file. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="pycross_lock_repo-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | required | |


<a id="#pycross_poetry_lock_model"></a>

## pycross_poetry_lock_model
Expand Down
2 changes: 1 addition & 1 deletion example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pycross_lock_file(
local_wheels = [
"//wheels",
],
default_pin_latest = True,
default_alias_single_version = True,
build_target_overrides = {
"future-0.18.2": "@//deps:overridden_future_0.18.2",
},
Expand Down
2 changes: 0 additions & 2 deletions example/example_lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ PINS = {
"charset-normalizer": "charset_normalizer_2.0.12",
"click": "click_8.1.3",
"cognitojwt": "cognitojwt_1.4.1",
"colorama": "colorama_0.4.4",
"cryptography": "cryptography_37.0.1",
"decorator": "decorator_5.1.1",
"docker": "docker_5.0.3",
Expand Down Expand Up @@ -60,7 +59,6 @@ PINS = {
"python-dateutil": "python_dateutil_2.8.2",
"python-jose": "python_jose_3.1.0",
"pytz": "pytz_2022.1",
"pywin32": "pywin32_227",
"pyyaml": "pyyaml_6.0",
"requests": "requests_2.27.1",
"responses": "responses_0.20.0",
Expand Down
8 changes: 4 additions & 4 deletions pycross/private/lock_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def _pycross_lock_file_impl(ctx):
ctx.attr.environment_prefix,
])

if ctx.attr.default_pin_latest:
args.append("--default-pin-latest")
if ctx.attr.default_alias_single_version:
args.append("--default-alias-single-version")

for k, t in ctx.attr.build_target_overrides.items():
args.extend([
Expand Down Expand Up @@ -143,8 +143,8 @@ pycross_lock_file = rule(
doc = "An optional prefix to apply to environment targets. Defaults to _env",
default = "_env",
),
"default_pin_latest": attr.bool(
doc = "Generate aliases for the latest versions of packages not covered by the lock model's pins.",
"default_alias_single_version": attr.bool(
doc = "Generate aliases for all packages that have a single version in the lock file.",
),
"build_target_overrides": attr.string_dict(
doc = "A mapping of package keys (name-version) to existing pycross_wheel_build build targets."
Expand Down
11 changes: 6 additions & 5 deletions pycross/private/tools/bzl_lock_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,16 +614,17 @@ def main():
repos.sort(key=lambda ft: ft.name)

pins = dict(lock_model.pins)
if args.default_pin_latest:
if args.default_alias_single_version:
packages_by_name = defaultdict(list)
for package_target in package_targets:
packages_by_name[package_target.package.name].append(package_target.package)

for package_name, packages in packages_by_name.items():
if package_name in pins:
continue
latest = max(packages, key=lambda p: p.version)
pins[package_name] = latest.key
if len(packages) > 1:
continue
pins[package_name] = packages[0].key

with open(output, "w") as f:

Expand Down Expand Up @@ -760,9 +761,9 @@ def make_parser() -> argparse.ArgumentParser:
)

parser.add_argument(
"--default-pin-latest",
"--default-alias-single-version",
action="store_true",
help="Generate aliases for the latest versions of packages not covered by the lock model's pins.",
help="Generate aliases for all packages with single versions.",
)

parser.add_argument(
Expand Down
20 changes: 15 additions & 5 deletions pycross/private/tools/poetry_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,27 @@ def to_lock_package(self) -> Package:


def get_files_for_package(
files: List[PackageFile], package_name: NormalizedName, package_version: PoetryVersion
files: List[PackageFile],
package_name: NormalizedName,
package_version: PoetryVersion,
) -> List[PackageFile]:
result = []
for file in files:
try:
file_package_name, file_package_version, _, _ = parse_wheel_filename(file.name)
file_package_name, file_package_version, _, _ = parse_wheel_filename(
file.name
)
except InvalidWheelFilename:
try:
file_package_name, file_package_version = parse_sdist_filename(file.name)
file_package_name, file_package_version = parse_sdist_filename(
file.name
)
except InvalidSdistFilename:
continue

if file_package_name == package_name and str(file_package_version) == str(package_version):
if file_package_name == package_name and str(file_package_version) == str(
package_version
):
result.append(file)

return result
Expand Down Expand Up @@ -165,7 +173,9 @@ def parse_file_info(file_info) -> PackageFile:
python_versions=package_python_versions,
dependencies=dependencies,
files=get_files_for_package(
files_by_package_name[package_listed_name], package_name, package_version
files_by_package_name[package_listed_name],
package_name,
package_version,
),
resolved_dependencies=[],
)
Expand Down

0 comments on commit 7131b4c

Please sign in to comment.