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

Generate.py quality of life improvements #1259

Open
2 tasks done
jaspervzwi opened this issue Sep 20, 2024 · 0 comments
Open
2 tasks done

Generate.py quality of life improvements #1259

jaspervzwi opened this issue Sep 20, 2024 · 0 comments
Labels

Comments

@jaspervzwi
Copy link
Contributor

Pre-filing checks

  • I have searched for open issues that report the same problem
  • I have checked that the bug affects the latest version of the library

The results you expect to see

When building a new scraper, the generate.py script showed two things that were not expected behavior:

  • The 'from.. import..' statement for the new scraper gets put all the way at the top of the recipe_scrapers.init.py file, rather than putting this between the other statements in alphabetical order
  • When generating a class, the script does not take into account if one already exists. If a user is to run the script twice for the same website (e.g. when creating a test template for a page without ingredients_groups and one with) it creates a duplicate class

The results (including any Python error messages) that you are seeing

  • Put the new scraper's 'from... import...'statement in alphabetical position in the init.py file
  • Check if class already exists before generating new class

...

@jaspervzwi jaspervzwi added the bug label Sep 20, 2024
hhursev pushed a commit that referenced this issue Dec 29, 2024
* Currently, generate.py tries to insert new `from ... import ...` statements after the first line (See #1259 and #1427 (comment)).
* It looks like the `node.level > 0` condition was added to skip the first item (`from __future__ import annotations`, which the generator considers to be a valid scraper class), but unfortunately `self.last_node = node` is still reached. The second time `__import()` is called, the first line is `self.last_node` and the new import is added beneath it.
* This PR moves the `node.level > 0` condition up into the parent `if` statement to avoid `self.last_node = node` from being called. Luckily, this doesn't impact the `elif` beneath it.
* I manually validated that we can insert a new scraper class named "AAA" and "ZZZ"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant