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

TypeError: Can't intern string #2798

Closed
3 tasks done
darkvariantdivine opened this issue Aug 11, 2020 · 7 comments · Fixed by python-poetry/poetry-core#62
Closed
3 tasks done

TypeError: Can't intern string #2798

darkvariantdivine opened this issue Aug 11, 2020 · 7 comments · Fixed by python-poetry/poetry-core#62
Labels
area/core Related to the poetry-core library kind/bug Something isn't working as expected status/waiting-on-core Requires changes to poetry-core first
Milestone

Comments

@darkvariantdivine
Copy link

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Fedora 31
  • Poetry version: 1.0.5
  • Link of a Gist with the contents of your pyproject.toml file:

Issue

I'm facing this issue when building my poetry project using the new poetry-core. When looking a little deeper, it seems like the fix in commit was not applied to poetry-core.

I would love to help out with a PR, but will need some direction :)

@darkvariantdivine darkvariantdivine added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Aug 11, 2020
@abn
Copy link
Member

abn commented Aug 11, 2020

@darkvariantdivine can you try the latest pre-release please?

@darkvariantdivine
Copy link
Author

darkvariantdivine commented Aug 12, 2020

Thanks for the prompt response @abn.

Here is a snippet of my pyproject.toml that specifies my build-system:

[build-system]
requires = ["poetry-core>=1.0.0a5"]
build-backend = "poetry.core.masonry.api"

I'm using pip to install the project with the following configuration:
pip install -U -vvv myproject --target='./packages' --install-option='--install-scripts=./bin'

Just to confirm, this is poetry-core 1.0.0a9? I will try and update the results.

@finswimmer
Copy link
Member

Hello @darkvariantdivine,

the latest pre-release version is 1.1.0b2.

Could you please provide enough enough information to reproduce your issue?

fin swimmer

@darkvariantdivine
Copy link
Author

@finswimmer, thanks for replying. This is more of a poetry-core issue but when I attempted to create an issue on poetry-core, it directed me to the poetry issue board.

I'm trying to install my project (that I'm using poetry to manage builds) to a specific folder with a specific structure using the following command:

pip install -U genisys --target='.packages' -- install-option='--install-scripts=./bin'

My project's pyproject.toml is below, I'm using poetry-core build system rather than poetry due to #760 :

[tool.poetry]
name = "genisys"
version = "0.1.2"
description = "A framework for building intelligent microservices"
license = "MIT"
authors = ["David Lee <[email protected]>"]
packages = [
    { include = "genisys" },
]
exclude = [
    "devops",
    "genisys/*/tests"
]

[tool.poetry.dependencies]
python = ">=3.6"
cookiecutter = "^1.7.2"
click = "^7.1.2"
colorama = "^0.4.3"
toml = "^0.10.1"

[tool.poetry.dev-dependencies]
# For documentation
mkdocs = "^1.1.2"

# For testing
tox = "^3.16.1"
tox-pyenv = "^1.1.0"
docker = "^4.2.2"

[tool.poetry.scripts]
genisys = "genisys.console:genisys_cli"

[tool.poetry.plugins."genisys.cli"]
init = "genisys.console.init:init_cli"
create = "genisys.console.create:create_cli"

[tool.tox]
legacy_tox_ini = """
[tox]
isolated_build = True
envlist = py36,py37,py38

[testenv]
commands = python -m unittest discover -v -s ./genisys -t .
"""

[build-system]
requires = ["poetry-core>=1.0.0a5"]
build-backend = "poetry.core.masonry.api"

This is the error I'm getting:

  Building wheel for genisys (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/david/.pyenv/versions/3.8.2/envs/genisys3.8.2/bin/python3.8 /home/david/.pyenv/versions/3.8.2/envs/genisys3.8.2/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmp554sy3gq
       cwd: /tmp/pip-install-s6osfz5z/genisys
  Complete output (26 lines):
  Traceback (most recent call last):
    File "/home/david/.pyenv/versions/3.8.2/envs/genisys3.8.2/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
      main()
    File "/home/david/.pyenv/versions/3.8.2/envs/genisys3.8.2/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/home/david/.pyenv/versions/3.8.2/envs/genisys3.8.2/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 204, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
    File "/tmp/pip-build-env-wp34m118/overlay/lib/python3.8/site-packages/poetry/core/masonry/api.py", line 57, in build_wheel
      return unicode(WheelBuilder.make_in(poetry, Path(wheel_directory)))
    File "/tmp/pip-build-env-wp34m118/overlay/lib/python3.8/site-packages/poetry/core/masonry/builders/wheel.py", line 55, in make_in
      wb.build()
    File "/tmp/pip-build-env-wp34m118/overlay/lib/python3.8/site-packages/poetry/core/masonry/builders/wheel.py", line 84, in build
      self._copy_module(zip_file)
    File "/tmp/pip-build-env-wp34m118/overlay/lib/python3.8/site-packages/poetry/core/masonry/builders/wheel.py", line 154, in _copy_module
      to_add = self.find_files_to_add()
    File "/tmp/pip-build-env-wp34m118/overlay/lib/python3.8/site-packages/poetry/core/masonry/builders/builder.py", line 170, in find_files_to_add
      if self.is_excluded(
    File "/tmp/pip-build-env-wp34m118/overlay/lib/python3.8/site-packages/poetry/core/masonry/builders/builder.py", line 120, in is_excluded
      if exclude_path.as_posix() in self.find_excluded_files():
    File "/tmp/pip-build-env-wp34m118/overlay/lib/python3.8/site-packages/poetry/core/masonry/builders/builder.py", line 99, in find_excluded_files
      for excluded in self._path.glob(excluded_glob):
    File "/home/david/.pyenv/versions/3.8.2/lib/python3.8/pathlib.py", line 1127, in glob
      drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
    File "/home/david/.pyenv/versions/3.8.2/lib/python3.8/pathlib.py", line 81, in parse_parts
      parsed.append(sys.intern(rel))
  TypeError: can't intern String
  ----------------------------------------
  ERROR: Failed building wheel for genisys

When I looked deeper into the code base, the error seems similar to #634 and the fix in commit 417d01d does not seem to be applied in poetry-core

poetry-core (poetry/core/masonry/builders/builder.py line 99):

                for excluded in self._path.glob(excluded_glob):

poetry (poetry/masonry/builders/builder.py line 56):

                for excluded in self._path.glob(str(excluded_glob)): 

@abn
Copy link
Member

abn commented Aug 13, 2020

@darkvariantdivine definitely give you this, this is an interesting issue.

For anyone who is interested in the root case, when tomlkit reads in the toml file, the values of tool.poetry.exclude are of tyle <class 'tomlkit.items.String'>. This in most parts works seamlessly everwhere a string is required. However, it seems that in this particular case, since one of the values ("devops") is an absolute path, ie. no relative path or glob, pathlib decides to use a code path that ends up triggerring the a call to sys.intern(exclude[0]) and this is what fails.

An immediate workaround would be to use devops/** instead of devops.

@abn abn added area/core Related to the poetry-core library and removed status/triage This issue needs to be triaged labels Aug 13, 2020
@abn abn added this to the 1.1 milestone Aug 13, 2020
abn added a commit to abn/poetry-core that referenced this issue Aug 15, 2020
When excluded path is not a glob pattern, pathlib implementation relies
on `sys.intern`, which expects a string. However, the value passed in
is of `tomlkit.items.String`. This change ensures poetry does not
crash in this scenario.

Resolves: python-poetry/poetry#2798

Co-authored-by: David Lee <[email protected]>
@abn abn added the status/waiting-on-core Requires changes to poetry-core first label Aug 15, 2020
finswimmer pushed a commit to python-poetry/poetry-core that referenced this issue Aug 15, 2020
When excluded path is not a glob pattern, pathlib implementation relies
on `sys.intern`, which expects a string. However, the value passed in
is of `tomlkit.items.String`. This change ensures poetry does not
crash in this scenario.

Resolves: python-poetry/poetry#2798

Co-authored-by: David Lee <[email protected]>
@darkvariantdivine
Copy link
Author

Thanks @finswimmer and @abn for this. Poetry is a great tool, I hope it continues to grow!

Copy link

github-actions bot commented Mar 3, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/core Related to the poetry-core library kind/bug Something isn't working as expected status/waiting-on-core Requires changes to poetry-core first
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants