Compare commits

...

17 Commits

Author SHA1 Message Date
Anthony Scemama beac615343 Merge branch 'master' of gitlab.com:scemama/irpf90 2024-04-22 11:02:59 +02:00
Anthony Scemama 01899b41b2 Fixed type 2024-04-22 11:02:00 +02:00
Anthony Scemama 451c93a52c Fixed type 2024-04-22 10:58:25 +02:00
Anthony Scemama 76946321d6 Updated regexp for type 2024-04-22 10:44:50 +02:00
Anthony Scemama ba1a2837aa Fix for sphinx functions 2024-03-20 16:05:42 +01:00
Anthony Scemama 4ab1b175fc Updated python -> python3 2023-10-19 17:50:35 +02:00
Anthony Scemama 0007f72f67 Merge branch 'set_parameters' into 'master'
I need to setup my params differently. This is one idea but it requires extra import

See merge request scemama/irpf90!25
2022-11-28 08:07:00 +00:00
Otto Kohulak a885761ea2 Merge branch 'master' into set_parameters 2022-10-21 08:18:44 +02:00
Otto Kohulak 152c69c754 Draft: I need to setup my params differently. This is one idea but it requires extra import 2022-10-20 15:53:38 +02:00
Anthony Scemama 34ca9a7852 Merge branch 'fix_indent_preprocesor_macros' into 'master'
Fix irpf90_indent now does not produce white space lines

See merge request scemama/irpf90!24
2022-10-18 13:12:16 +00:00
Otto Kohulak d1e475dc22 Fix irpf90_indent now does not produce white space lines
Fix C preprocessor macros are now never indented
Fix !$omp directive are now never indeted
2022-10-18 14:06:45 +02:00
Anthony Scemama 088c6fdc04 Merge branch 'fix_indent' into 'master'
Fix indent if line starts with &

See merge request scemama/irpf90!23
2022-10-18 09:47:34 +00:00
Ot(t)o Kohulák c938931e5e Fix indent if line starts with & 2022-10-17 07:21:29 +02:00
Anthony Scemama ab88cc01a6 Fixed regexp for strings with double quotes 2022-01-11 22:44:18 +01:00
Anthony Scemama 33ca5e1018 Shorten lines in ninja file 2021-05-19 18:36:43 +02:00
Anthony Scemama 132a4a1661 increase version 2020-12-06 20:58:38 +01:00
Anthony Scemama 2027274583 Replace AR by ARCHIVE 2020-12-06 20:48:35 +01:00
12 changed files with 103 additions and 51 deletions

View File

@ -3,7 +3,7 @@ RST2MAN=rst2man -d -t
default: man1/irpman.1.gz man1/irpf90.1.gz
options.rst: ../src/command_line.py
python ../src/command_line.py > options.rst
python3 ../src/command_line.py > options.rst
man1/irpf90.1.gz: irpf90.rst options.rst
rm -f $@ ; $(RST2MAN) --title="IRP Fortran 90" irpf90.rst man1/irpf90.1 ; gzip man1/irpf90.1

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
# the Implicit Reference to Parameters (IRP) method.
# Copyright (C) 2009 Anthony SCEMAMA

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
# the Implicit Reference to Parameters (IRP) method.
# Copyright (C) 2009 Anthony SCEMAMA

View File

@ -1,13 +1,16 @@
import sys
import setuptools
import version
with open("README.md", "r") as fh:
long_description = fh.read()
v = version.version
setuptools.setup(
name = 'irpf90',
version = '2.0.4',
version = v,
scripts = ["irpf90", "irpman", "irpf90_indent"],
author = 'Anthony Scemama',
author_email = 'scemama@irsamc.ups-tlse.fr',
@ -15,7 +18,7 @@ setuptools.setup(
long_description=long_description,
long_description_content_type="text/markdown",
url="https://irpf90.ups-tlse.fr",
download_url = 'https://gitlab.com/scemama/irpf90/-/archive/v2.0.4/irpf90-v2.0.4.tar.gz',
download_url = f'https://gitlab.com/scemama/irpf90/-/archive/v{v}/irpf90-v{v}.tar.gz',
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",

1
pip/version.py Symbolic link
View File

@ -0,0 +1 @@
../src/version.py

View File

@ -222,7 +222,7 @@ def do_print_subroutines_rst(sub):
filename = sub.line.filename
name = sub.name
file = open("%s%s.rst"%(mandir,sub.name), "w")
print(".. c:function:: %s:\n"%(sub.name.lower()), file=file)
print(".. c:macro:: %s:\n"%(sub.name.lower()), file=file)
print("", file=file)
print(" File : :file:`"+filename+"`", file=file)
print("", file=file)

View File

@ -26,10 +26,21 @@
import sys
import os
import re
LENMAX = 70
tabn = 2
#copy of locals without "import copy"
locals_ = {x: y for x, y in locals().items()}
for key, value in locals_.items():
try:
val = os.environ["IRPF90_INDENT_"+key.upper()]
locals()[key] = type(locals_[key])(val)
except:
pass
tab = " "*tabn
class Grep(object):
@ -106,6 +117,14 @@ class Grep(object):
def declaration(self,string):
return re.match(self.re_declaration,string) is not None
re_preprocessor = re.compile(r"^\s*#.*$")
def preprocessor(self,string):
return re.match(self.re_preprocessor,string) is not None
re_omppragma = re.compile(r"^\s*!\$omp\s.*$")
def omppragma(self,string):
return re.match(self.re_omppragma,string) is not None
grep = Grep()
class indent(object):
@ -119,10 +138,12 @@ class indent(object):
return l.strip().ljust(n) + ' :: '+ r.strip()
def format_continuation(self,string,n):
buffer = string.split('&')
buffer = string.split('&', 1)
if len(buffer) == 1:
l = buffer[0]
return l
elif buffer[0].strip() == "":
return self.format_continuation(buffer[1], n)
else:
l, r = buffer
return l.strip().ljust(69-len(n)) + '&'+ r.strip()
@ -165,6 +186,19 @@ class indent(object):
for i in range(len(self.text)):
prevline = line
line = self.text[i].strip()
if line == "":
print("")
continue
if grep.preprocessor(line):
print(line.lstrip())
continue
if grep.omppragma(line):
print(line.lstrip())
continue
if grep.continuation(line):
line = self.format_continuation(line,k)

View File

@ -36,9 +36,9 @@ FILENAME_GITIGNORE = ".gitignore"
IRPF90_MAKE = "irpf90.make"
if sys.platform in ["linux", "linux2"]:
AR = "ar crs"
ARCHIVE = "ar crs"
elif sys.platform == "darwin":
AR = "libtool -static -o"
ARCHIVE = "libtool -static -o"
else:
print("Unknown platform. Only Linux and Darwin are supported.")
sys.exit(-1)
@ -58,7 +58,7 @@ def create():
FC = gfortran
FCFLAGS= -O2 -ffree-line-length-none -I .
NINJA = ninja
AR = %s
ARCHIVE= %s
RANLIB = ranlib
SRC=
@ -70,7 +70,7 @@ export
%s: $(filter-out %s%%, $(wildcard */*.irp.f)) $(wildcard *.irp.f) $(wildcard *.inc.f) Makefile
\t$(IRPF90)
"""%(AR,IRPF90_MAKE,IRPF90_MAKE,irpdir)
"""%(ARCHIVE,IRPF90_MAKE,IRPF90_MAKE,irpdir)
file.write(t)
file.close()
create_gitignore()
@ -197,7 +197,7 @@ def run_make():
print(dir+"%.o: %.F\n\t$(FC) $(FCFLAGS) -c $*.F -o "+dir+"$*.o", file=file)
print(dir+"%.irp.F90: "+IRPF90_MAKE+"\n", file=file)
print("move:\n\t@mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING=\n", file=file)
print("IRPF90_temp/irpf90.a: $(OBJ) $(OBJ1)\n\t$(AR) IRPF90_temp/irpf90.a $(OBJ1)\n", file=file)
print("IRPF90_temp/irpf90.a: $(OBJ) $(OBJ1)\n\t$(ARCHIVE) IRPF90_temp/irpf90.a $(OBJ1)\n", file=file)
print("clean:\n\trm -rf $(EXE) $(OBJ1) IRPF90_temp/irpf90.a $(ALL_OBJ1) $(ALL)\n", file=file)
print("veryclean:\n\t- $(MAKE) clean\n", file=file)
print("\t- rm -rf "+irpdir+" "+mandir+" "+IRPF90_MAKE+" irpf90_entities dist tags\n", file=file)

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
# the Implicit Reference to Parameters (IRP) method.
# Copyright (C) 2009 Anthony SCEMAMA
# Copyright (C) 2009 Anthony SCEMAMA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -20,8 +20,8 @@
# Anthony Scemama
# LCPQ - IRSAMC - CNRS
# Universite Paul Sabatier
# 118, route de Narbonne
# 31062 Toulouse Cedex 4
# 118, route de Narbonne
# 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr
@ -39,6 +39,14 @@ cwd = os.getcwd()
PRINT_WIDTH=50
if sys.platform in ["linux", "linux2"]:
AR = "ar crs"
elif sys.platform == "darwin":
AR = "libtool -static -o"
else:
print("Unknown platform. Only Linux and Darwin are supported.")
sys.exit(-1)
def dress(f,in_root=False):
"""
Transfoms the filename f into $PWD/IRPF90_temp/f
@ -47,7 +55,8 @@ def dress(f,in_root=False):
result = os.path.join(cwd,f)
else:
result = os.path.join(cwd,irpdir,f)
return os.path.normpath(result)
result = os.path.normpath(result)
return result
def create_build_touches(list_of_other_o):
@ -68,7 +77,7 @@ def create_build_touches(list_of_other_o):
list_of_modules = ' '.join(list_of_modules)
result = '\n'.join(
[
[
"build {target_o}: compile_touches_{id} {target_F90} | {list_of_modules}",
" short_in = {short_target_F90}",
" short_out = {short_target_o}",
@ -86,7 +95,7 @@ def create_build_touches(list_of_other_o):
short_target_F90 = os.path.split(target_F90)[1] ,
short_target_o = os.path.split(target_o)[1] ,
target_F90 = target_F90 ,
target_o = target_o
target_o = target_o
)
return result
@ -110,7 +119,7 @@ def create_build_target(t,list_of_other_o):
needed_modules = [ "%s.irp.module.o"%(modules[x].filename) for x in modules \
if modules[x].name in t.needed_modules ] + [ target_module_o ]
list_of_o = [ target_o, target_module_o, irp_lib ]
list_of_o = [ target_o, target_module_o, irp_lib ]
list_of_o = ' '.join(list_of_o)
list_of_modules = list(map(dress, needed_modules)) + list_of_other_o
@ -119,7 +128,7 @@ def create_build_target(t,list_of_other_o):
list_of_includes = ' '.join([dress(x,in_root=True) for x in t.includes])
result = '\n'.join(
[ "build {target}: link_{id} {list_of_o}",
[ "build {target}: link_{id} {list_of_o}",
" short_out = {short_target}",
"",
"build {target_o}: compile_fortran_{id} {target_F90} | {list_of_modules} {list_of_includes}",
@ -146,7 +155,7 @@ def create_build_target(t,list_of_other_o):
target_module_F90 = target_module_F90 ,
target_module_o = target_module_o ,
target_o = target_o ,
target = target
target = target
)
return result
@ -176,7 +185,7 @@ def create_build_non_target(t,list_of_other_o):
list_of_includes = ' '.join([dress(x,in_root=True) for x in t.includes])
result = '\n'.join(
[
[
"build {target_o}: compile_fortran_{id} {target_F90} | {list_of_modules} {list_of_externals}",
" short_in = {short_target_F90}",
" short_out = {short_target}",
@ -198,7 +207,7 @@ def create_build_non_target(t,list_of_other_o):
target_F90 = target_F90 ,
target_module_F90 = target_module_F90 ,
target_module_o = target_module_o ,
target_o = target_o
target_o = target_o
)
return result
@ -222,7 +231,7 @@ def create_build_remaining(f):
elif extension.lower() in [ 'cxx', 'cpp' ]:
result = [ "build {target_o}: compile_cxx_{id} {target_i}" ]
result += [ " short_in = {short_target_i}",
result += [ " short_in = {short_target_i}",
" short_out = {short_target_o}", "" ]
result = '\n'.join(result).format(
target_o = target_o,
@ -246,7 +255,7 @@ TARGETS={1}
all:
$(NINJA)
$(TARGETS):
$(TARGETS):
$(NINJA) $(PWD)/$@
clean:
@ -271,8 +280,8 @@ def run():
try: FC = os.environ["FC"]
except KeyError: FC="gfortran -ffree-line-length-none"
try: AR = os.environ["AR"]
except KeyError: AR="ar crs"
try: ARCHIVE = os.environ["ARCHIVE"]
except KeyError: ARCHIVE=AR
try: CC = os.environ["CC"]
except KeyError: CC="gcc"
@ -285,7 +294,7 @@ def run():
FC += " "+' '.join(includes)
CC += " "+' '.join(includes)
CXX += " "+' '.join(includes)
try: SRC = os.environ["SRC"].split()
except KeyError: SRC=[]
@ -311,32 +320,32 @@ def run():
# Rules
t = [ "rule compile_fortran_{id}",
" command = {FC} {FCFLAGS} -c $in -o $out",
" description = F : $short_in -> $short_out",
t = [ "rule compile_fortran_{id}",
" command = {FC} {FCFLAGS} -c $in -o $out",
" description = F : $short_in -> $short_out",
"",
"rule compile_touches_{id}",
"rule compile_touches_{id}",
" command = {FC} -c $in -o $out",
" description = F : $short_in -> $short_out",
" description = F : $short_in -> $short_out",
"",
"",
"rule compile_c_{id}" ,
" command = {CC} {CFLAGS} -c $in -o $out",
" description = C : $short_in -> $short_out",
" command = {CC} {CFLAGS} -c $in -o $out",
" description = C : $short_in -> $short_out",
"",
"rule compile_cxx_{id}",
" command = {CXX} {CXXFLAGS} -c $in -o $out",
" description = C++ : $short_in -> $short_out",
"rule compile_cxx_{id}",
" command = {CXX} {CXXFLAGS} -c $in -o $out",
" description = C++ : $short_in -> $short_out",
"",
"rule link_lib_{id}",
" command = {AR} $out $in" ,
" description = Link: $short_out",
"rule link_lib_{id}",
" command = {ARCHIVE} $out $in" ,
" description = Link: $short_out",
"",
"rule link_{id}",
"rule link_{id}",
" command = {FC} $in {LIB} -o $out" ,
" description = Link: $short_out"]
output += [ '\n'.join(t).format(id=irp_id, FC=FC, FCFLAGS=FCFLAGS, LIB=LIB, CXX=CXX, CXXFLAGS=CXXFLAGS, CC=CC, CFLAGS=CFLAGS, AR=AR) ]
" description = Link: $short_out"]
output += [ '\n'.join(t).format(id=irp_id, FC=FC, FCFLAGS=FCFLAGS, LIB=LIB, CXX=CXX, CXXFLAGS=CXXFLAGS, CC=CC, CFLAGS=CFLAGS, ARCHIVE=ARCHIVE) ]
# All modules : list of Fmodule objects
@ -396,9 +405,13 @@ def run():
for i in l_common_s:
output.append(create_build_remaining(i))
text = '\n\n'.join(output)
text = text.replace(cwd+"/IRPF90_temp","$T")
text = text.replace(cwd,"$X")
with open(FILENAME,'w') as f:
f.write('\n\n'.join(output))
f.write("X="+cwd+"\nT="+cwd+"/IRPF90_temp\n")
f.write(text)
f.write('\n')
create_irpf90_make([ x.filename for x in l_targets ] + [ os.path.join(irpdir,'irpf90.a') ] )

View File

@ -323,7 +323,7 @@ def execute_templates(text):
file.close()
# Execute shell
import os
pipe = os.popen("python < %s"%(scriptname),'r')
pipe = os.popen("python3 < %s"%(scriptname),'r')
lines = pipe.readlines()
pipe.close()
result += get_text(lines,scriptname)

View File

@ -46,12 +46,13 @@ re_decl = re.compile( "".join( [ r"^\ *",
r"|intrinsic *(::)?",
r"|external *(::)?",
r"|equivalence *(::)?",
r"|type",
r"|type *\(",
r"|type +",
r"|end ?type",
r")[^=(]"
] ) )
re_test = re.compile(r"\( *(.*)(\.[a-zA-Z]*\.|[<>]=?|[=/]=)([^=]*)\)")
re_string = re.compile(r"'.*?'")
re_string = re.compile(r"'.*?'|\".*?\"")

View File

@ -1 +1 @@
version = "2.0.4"
version="2.0.5"