klayout icon indicating copy to clipboard operation
klayout copied to clipboard

Python, os.path.realpath returns extra '/

Open lukasc-ubc opened this issue 3 years ago • 11 comments

Hi Matthias,

On klayout-HW-klayout-0.27-macOS-BigSur-1-qt5Brew-RsysPhb38, in the Macro window in Python the following code returns something different than on the 0.26 versions, namely extra prepended characters:

> import os
> os.path.realpath(__file__)
/'/Users/lukasc/Documents/GitHub/SiEPIC-Tools/klayout_dot_config/tech/GSiP/pymacros

in HW-klayout-0.26.12-macOS-BigSur-1-qt5Brew-RsysPhb38.dmg, the same returns:

/Users/lukasc/Documents/GitHub/SiEPIC-Tools/klayout_dot_config/tech/GSiP/pymacros

It seems that print(file) returns extra quotations around the file, which is not what python3 and 0.26 return.

lukasc-ubc avatar May 26 '21 06:05 lukasc-ubc

Furthermore, breakpoints don't seem to work:

image

lukasc-ubc avatar May 26 '21 06:05 lukasc-ubc

also,

for Library.register, the documentation states that it replaces the library. https://www.klayout.de/doc-qt5/code/class_Library.html#method24

self.register(library)

However, if I run the library multiple times, it shows up repeated:

image

In 0.26.12, it replaced correctly. Furthermore, documentation says that this and other features were introduced in 0.27, but they were already in 0.26.

lukasc-ubc avatar May 26 '21 07:05 lukasc-ubc

@klayoutmatthias

  • the path problem seems to be fixed in 0.27.1 (HW version on OSX)
  • the breakpoint problem seems to be fixed in 0.27.1 (HW version on OSX)

but:

  • the Library.register function doesn't do the replacement

regards, Lukas

lukasc-ubc avatar Jun 12 '21 07:06 lukasc-ubc

@klayoutmatthias The os.path problem is back in 0.27.2

I get the issue:

/'/Users/lukasc/Documents/GitHub/SiEPIC-Tools/klayout_dot_config/tech/GSiP/pymacros

lukasc-ubc avatar Jul 02 '21 23:07 lukasc-ubc

Hi Lukas,

I tried first to reproduce the "library.register" problem, but I can't confirm that (Linux).

This is what works for me:

lib_a = RBA::Library::new
lib_a.layout.add_cell("LIB_A")
lib_a.register("ISSUE_810_LIB")

lib_b = RBA::Library::new
lib_b.layout.add_cell("LIB_B")
lib_b.add_technology("si4all")
lib_b.register("ISSUE_810_LIB")

# register another library for tech "si4all" which replaces lib_b
lib_c = RBA::Library::new
lib_c.layout.add_cell("LIB_C")
lib_c.add_technology("si4all")
lib_c.register("ISSUE_810_LIB")

# register another library for "no tech" which replaces lib_a
lib_x = RBA::Library::new
lib_x.layout.add_cell("LIB_X")
lib_x.register("ISSUE_810_LIB")

This will correctly register two libraries "ISSUE_810_LIB", one for "si4all" technology, the other unspecific. The first two "register" calls are replaced.

klayoutmatthias avatar Jul 06 '21 19:07 klayoutmatthias

I do have only Catalina, so I tried to reproduce the problem with os.path.

I used HW-klayout-0.27.2-macOS-Catalina-1-qt5Brew-RsysPhb38.dmg without success:

image

So maybe it's a problem with BigSur?

klayoutmatthias avatar Jul 06 '21 20:07 klayoutmatthias

@Kazzz-S could you please check these two issues, if they they show up on your OSX installations?

thanks

lukasc-ubc avatar Jul 06 '21 21:07 lukasc-ubc

Hi,

In my environment...

Catalina

  • HW-klayout-0.27.2-macOS-Catalina-1-qt5Brew-RsysPhb38.dmg Catalina1 Catalina2

Big Sur

  • HW-klayout-0.27.2-macOS-BigSur-1-qt5Brew-RsysPhb38.dmg BigSur1 BigSur2

Kazzz-S

Kazzz-S avatar Jul 06 '21 22:07 Kazzz-S

Could you please try with a folder that has a space in the name? This could be causing an issue. Thank you.

Lukas Chrostowski Professor, Electrical and Computer Engineering University of British Columbia Quantum Matter Institute Member, College of the Royal Society of Canada http://www.mina.ubc.ca/lukasc http://siepic.ubc.ca https://qmi.ubc.ca/about/directory/lukas-chrostowski

On Jul 6, 2021, at 3:44 PM, Kazunari Sekigawa @.***> wrote:

 Hi,

In my environment...

Catalina

HW-klayout-0.27.2-macOS-Catalina-1-qt5Brew-RsysPhb38.dmg

Big Sur

HW-klayout-0.27.2-macOS-BigSur-1-qt5Brew-RsysPhb38.dmg

Kazzz-S

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

lukasc-ubc avatar Jul 07 '21 01:07 lukasc-ubc

Is this a useful test?

#--------------------------
# Issue-810
#
# File: Issue810-2.py
#--------------------------
import os
import platform

# The directory structure is as shown below.
#   (base) BigSur2{kazzz-s} GitHub810 (1)% pwd
#   /Users/kazzz-s/Gitwork/ForumKLayout/GitHub810
#   (base) BigSur2{kazzz-s} GitHub810 (2)% ll
#   total 0
#   drwxr-xr-x  4 kazzz-s staff 128 Jul  7 18:14  .
#   drwxr-xr-x 18 kazzz-s staff 576 Jul  7 18:03  ..
#   drwxr-xr-x  4 kazzz-s staff 128 Jul  7 18:03 'Folder With Space'
#   lrwxr-xr-x  1 kazzz-s staff  17 Jul  7 18:14  symlink -> 'Folder With Space'

myFileReal = os.environ['HOME'] + "/GitWork/ForumKLayout/GitHub810/Folder With Space/Issue810-2.py"
myFileSymL = os.environ['HOME'] + "/GitWork/ForumKLayout/GitHub810/symlink/Issue810-2.py"

print( "### My Platform ###" )
(System, Node, Release, Version, Machine, Processor) = platform.uname()
print( "System    = %s" % System )
print( "Node      = %s" % Node )
print( "Release   = %s" % Release )
print( "Version   = %s" % Version )
print( "Machine   = %s" % Machine )
print( "Processor = %s" % Processor )

print( "" )
print( "### Real Path with Spaces ###" )
path1=os.path.realpath(myFileReal)
print(path1)

path2=os.path.dirname(os.path.realpath(myFileReal))
print(path2)

print( "" )
print( "### Symbolic Link Path  ###" )
path3=os.path.realpath(myFileSymL)
print(path3)

path4=os.path.dirname(os.path.realpath(myFileSymL))
print(path4)

# End of file

Catalina3

BigSur3

Kazzz-S

Kazzz-S avatar Jul 07 '21 10:07 Kazzz-S

This seems to be happening on Windows as well but uses path to KLayout installation. Running Windows 11 with KLayout 0.27.5.

EDIT: 64-bit Windows 11

image

seanlam97 avatar Jan 07 '22 02:01 seanlam97