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

[BUG] (type-safe-api) install fails on python runtime package with missing README #813

Closed
jstrunk opened this issue Jul 18, 2024 · 1 comment · Fixed by #818
Closed

[BUG] (type-safe-api) install fails on python runtime package with missing README #813

jstrunk opened this issue Jul 18, 2024 · 1 comment · Fixed by #818
Labels
bug Something isn't working needs-triage

Comments

@jstrunk
Copy link
Contributor

jstrunk commented Jul 18, 2024

Describe the bug

After cloning a project repo and installing the monorepo's dependencies with pnpm install or similar, packages that depend on an API's python runtime package fail because the generated README.md is missing and poetry install requires it. Using commitGenerated in the type safe api package or the python runtime options still includes the README.md and the module files in the runtime's .gitignore.

Expected Behavior

After cloning a project repo, I should be able to install dependencies and build all packages.

Current Behavior

After cloning the repo and running pnpm i:

│ > nx run api-detective-api-python-handlers:install
│ api-detective-api-python-handlers: Progress: resolved 1, reused 0, downloaded 0, added 0
│ api-detective-api-python-handlers: Packages: +2
│ api-detective-api-python-handlers: ++
│ api-detective-api-python-handlers: Progress: resolved 2, reused 1, downloaded 0, added 1
│ api-detective-api-python-handlers: Progress: resolved 2, reused 2, downloaded 0, added 1
│ api-detective-api-python-handlers: Progress: resolved 2, reused 2, downloaded 0, added 2
│ api-detective-api-python-handlers: Progress: resolved 2, reused 2, downloaded 0, added 2, done
│ api-detective-api-python-handlers: 👾 install | poetry env use python$PYTHON_VERSION
│ api-detective-api-python-handlers: Creating virtualenv api-detective-api-python-handlers-CBvV-DEk-py3.12 in /Users/strunkjd/Library/Caches/pypoetry/virtualenvs
│ api-detective-api-python-handlers: Using virtualenv: /Users/strunkjd/Library/Caches/pypoetry/virtualenvs/api-detective-api-python-handlers-CBvV-DEk-py3.12
│ api-detective-api-python-handlers: 👾 install | poetry update
│ api-detective-api-python-handlers: Updating dependencies
│ api-detective-api-python-handlers: Resolving dependencies...
│ api-detective-api-python-handlers: Package operations: 79 installs, 0 updates, 0 removals
│ api-detective-api-python-handlers: - Installing ...
...
│ api-detective-api-python-handlers: - Installing api-detective-api-python-runtime (0.0.0 /private/tmp/api-detective/packages/api/generated/runtime/python)
│ api-detective-api-python-handlers: ChefBuildError
│ api-detective-api-python-handlers: Backend subprocess exited when trying to invoke build_editable
│ api-detective-api-python-handlers:
│ api-detective-api-python-handlers: Traceback (most recent call last):
│ api-detective-api-python-handlers: File "/Users/strunkjd/.pyenv/versions/3.12.2/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in
│ api-detective-api-python-handlers: main()
│ api-detective-api-python-handlers: File "/Users/strunkjd/.pyenv/versions/3.12.2/lib/python3.12/site-packages/pyproject_hooks/in_process/in_process.py", line 357, in main
│ api-detective-api-python-handlers: json_out["return_val"] = hook(**hook_input["kwargs"])
│ api-detective-api-python-handlers: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ api-detective-api-python-handlers: File "/Users/strunkjd/.pyenv/versions/3.12.2/lib/python3.12/site-packages/pyproject_hooks/in_process/in_process.py", line 294, in build_editable
│ api-detective-api-python-handlers: return hook(wheel_directory, config_settings, metadata_directory)
│ api-detective-api-python-handlers: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ api-detective-api-python-handlers: File "/var/folders/4
/kvx9bwf15_j628lytjzz0mwc0000gq/T/tmp5cjmi4ri/.venv/lib/python3.12/site-packages/poetry/core/masonry/api.py", line 82, in build_e…
│ api-detective-api-python-handlers: return WheelBuilder.make_in(
│ api-detective-api-python-handlers: ^^^^^^^^^^^^^^^^^^^^^
│ api-detective-api-python-handlers: File "/var/folders/4
/kvx9bwf15_j628lytjzz0mwc0000gq/T/tmp5cjmi4ri/.venv/lib/python3.12/site-packages/poetry/core/masonry/builders/wheel.py", line 81,…
│ api-detective-api-python-handlers: wb = WheelBuilder(
│ api-detective-api-python-handlers: ^^^^^^^^^^^^^
│ api-detective-api-python-handlers: File "/var/folders/4
/kvx9bwf15_j628lytjzz0mwc0000gq/T/tmp5cjmi4ri/.venv/lib/python3.12/site-packages/poetry/core/masonry/builders/wheel.py", line 62,…
│ api-detective-api-python-handlers: super().init(poetry, executable=executable)
│ api-detective-api-python-handlers: File "/var/folders/4
/kvx9bwf15_j628lytjzz0mwc0000gq/T/tmp5cjmi4ri/.venv/lib/python3.12/site-packages/poetry/core/masonry/builders/builder.py", line 5…
│ api-detective-api-python-handlers: self._meta = Metadata.from_package(self.package)
│ api-detective-api-python-handlers: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ api-detective-api-python-handlers: File "/var/folders/4
/kvx9bwf15_j628lytjzz0mwc0000gq/T/tmp5cjmi4ri/.venv/lib/python3.12/site-packages/poetry/core/masonry/metadata.py", line 58, in fr…
│ api-detective-api-python-handlers: with readme.open(encoding="utf-8") as f:
│ api-detective-api-python-handlers: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ api-detective-api-python-handlers: File "/Users/strunkjd/.pyenv/versions/3.12.2/lib/python3.12/pathlib.py", line 1013, in open
│ api-detective-api-python-handlers: return io.open(self, mode, buffering, encoding, errors, newline)
│ api-detective-api-python-handlers: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ api-detective-api-python-handlers: FileNotFoundError: [Errno 2] No such file or directory: '/private/tmp/api-detective/packages/api/generated/runtime/python/README.md'
│ api-detective-api-python-handlers:
│ api-detective-api-python-handlers: at ~/.pyenv/versions/3.12.2/lib/python3.12/site-packages/poetry/installation/chef.py:164 in _prepare
│ api-detective-api-python-handlers: 160│
│ api-detective-api-python-handlers: 161│ error = ChefBuildError("\n\n".join(message_parts))
│ api-detective-api-python-handlers: 162│
│ api-detective-api-python-handlers: 163│ if error is not None:
│ api-detective-api-python-handlers: → 164│ raise error from None
│ api-detective-api-python-handlers: 165│
│ api-detective-api-python-handlers: 166│ return path
│ api-detective-api-python-handlers: 167│
│ api-detective-api-python-handlers: 168│ def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:
│ api-detective-api-python-handlers: Note: This error originates from the build backend, and is likely not a problem with poetry but with api-detective-api-python-runtime (0.0.0 /private/tmp/…
│ api-detective-api-python-handlers: 👾 Task "install" failed when executing "poetry update" (cwd: /private/tmp/api-detective/packages/api/handlers/python)
│ api-detective-api-python-handlers: Warning: run-commands command "pnpm dlx projen install" exited with non-zero status code

Reproduction Steps

.projenrc.ts

const pdkVersion = "0.23.40";
const projectName = "sample";

const project = new monorepo.MonorepoTsProject({
  devDeps: [`@aws/pdk@${pdkVersion}`],
  name: projectName,
  packageManager: javascript.NodePackageManager.PNPM,
  projenrcTs: true,
  gitignore: [".bashrc", ".profile", ".idea"],
  prettier: true,
});

const api = new TypeSafeApiProject({
  parent: project,
  name: `${projectName}-api`,
  outdir: "packages/api",
  model: {
    language: ModelLanguage.OPENAPI,
    options: {
      openapi: {
        title: `${projectName}-api`,
      },
    },
  },
  infrastructure: {
    language: Language.TYPESCRIPT,
  },
  handlers: {
    languages: [Language.PYTHON],
  },
  runtime: {
    languages: [Language.PYTHON],
    options: {
      python: {
          commitGenerated: true,
      },
    },
  },
  commitGenerated: true,
});

Possible Solution

First, commitGenerated: true in a Python runtime package doesn't work. .gitignore still includes the README.md and module directory:

packages/api/generated/runtime/python/.gitignore

sample_api_python_runtime
README.md

Second, commitGenerated on the type safe api project should be recursively applied to child projects.

Additional Information/Context

Mitigation:

After defining the api project in .projenrc.ts, add the following:

api.runtime.python?.gitignore.removePatterns(
  "README.md",
  api.runtime.python?.moduleName,
);

PDK version used

0.23.40

What languages are you seeing this issue on?

Typescript, Python

Environment details (OS name and version, etc.)

MacOS 14.5 intel

@jstrunk jstrunk added bug Something isn't working needs-triage labels Jul 18, 2024
@jstrunk
Copy link
Contributor Author

jstrunk commented Jul 19, 2024

While implementing this possible solution, I realized that commitGenerated is for Projen project files and defaults to true. I'm implementing a new option commitGeneratedCode with the desired behavior. It will default to false except for python projects that use poetry.

jstrunk added a commit to jstrunk/aws-pdk that referenced this issue Jul 19, 2024
…ted code

This commit introduces a new `commitGeneratedCode` option to the
TypeSafeApiProject, which allows controlling whether generated code should be
committed or ignored for all generated projects.

The main changes include:

- Add a `commitGeneratedCode` option to the TypeSafeApiProject and related
  options interfaces.
- Set the default value of `commitGeneratedCode` to `false`, except for Python
  projects where it defaults to `true` due to the Poetry package manager
  requirements.
- Conditionally add patterns to .gitignore based on the `commitGeneratedCode`
  option for all generated projects.
- Update tests to cover the new `commitGeneratedCode` option.

By default, the generated code will be ignored in the repository, except for
Python projects where it will be included to allow for easier distribution and
deployment of the generated artifacts using Poetry.

Resolves: aws#813
jstrunk added a commit to jstrunk/aws-pdk that referenced this issue Aug 1, 2024
…ted python projects

The poetry install that runs as part of post synthesis expects there to be some
code present, but code isn't generated until build time. This means that the
first install will fail when either generating the project for the first time or
checking out a fresh copy (since generated code is not checked in to version
control).

To fix this, we add a blank README.md file in addition to the __init__.py file
as the first install step to keep poetry happy until the generator overwrites
it.

Fixes aws#813
jstrunk added a commit to jstrunk/aws-pdk that referenced this issue Aug 1, 2024
…ted code

This commit introduces a new `commitGeneratedCode` option to the
TypeSafeApiProject, which allows controlling whether generated code should be
committed or ignored for all generated projects.

The main changes include:

- Add a `commitGeneratedCode` option to the TypeSafeApiProject and related
options interfaces.
- Set the default value of `commitGeneratedCode` to `false`.
- Conditionally add patterns to .gitignore based on the `commitGeneratedCode`
option for all generated projects.
- Update tests to cover the new `commitGeneratedCode` option.

By default, the generated code will be ignored in the repository, except for
Python projects where it will be included to allow for easier distribution and
deployment of the generated artifacts using Poetry.

Fixes: aws#813
agdimech pushed a commit that referenced this issue Aug 6, 2024
…ted python projects (#818)

The poetry install that runs as part of post synthesis expects there to be some
code present, but code isn't generated until build time. This means that the
first install will fail when either generating the project for the first time or
checking out a fresh copy (since generated code is not checked in to version
control).

To fix this, we add a blank README.md file in addition to the __init__.py file
as the first install step to keep poetry happy until the generator overwrites
it.

Fixes #813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant